1 include(LLVMProcessSources)
4 macro(add_llvm_library name)
5 llvm_process_sources( ALL_FILES ${ARGN} )
6 add_library( ${name} ${ALL_FILES} )
7 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
8 if( LLVM_COMMON_DEPENDS )
9 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
10 endif( LLVM_COMMON_DEPENDS )
12 if( BUILD_SHARED_LIBS )
13 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
16 # Ensure that the system libraries always comes last on the
17 # list. Without this, linking the unit tests on MinGW fails.
18 link_system_libs( ${name} )
20 if( EXCLUDE_FROM_ALL )
21 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
23 install(TARGETS ${name}
24 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
25 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
27 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
28 endmacro(add_llvm_library name)
30 macro(add_llvm_library_dependencies name)
31 # Save the dependencies of the LLVM library in a variable so that we can
32 # query it when resolve llvm-config-style component -> library mappings.
33 set_property(GLOBAL PROPERTY LLVM_LIB_DEPS_${name} ${ARGN})
35 # Then add the actual dependencies to the library target.
36 target_link_libraries(${name} ${ARGN})
37 endmacro(add_llvm_library_dependencies name)
39 macro(add_llvm_loadable_module name)
40 if( NOT LLVM_ON_UNIX OR CYGWIN )
41 message(STATUS "Loadable modules not supported on this platform.
43 # Add empty "phony" target
44 add_custom_target(${name})
46 llvm_process_sources( ALL_FILES ${ARGN} )
53 add_library( ${name} ${libkind} ${ALL_FILES} )
54 set_target_properties( ${name} PROPERTIES PREFIX "" )
56 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
57 link_system_libs( ${name} )
60 # Darwin-specific linker flags for loadable modules.
61 set_target_properties(${name} PROPERTIES
62 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
65 if( EXCLUDE_FROM_ALL )
66 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
68 install(TARGETS ${name}
69 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
70 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
74 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
75 endmacro(add_llvm_loadable_module name)
78 macro(add_llvm_executable name)
79 llvm_process_sources( ALL_FILES ${ARGN} )
80 if( EXCLUDE_FROM_ALL )
81 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
83 add_executable(${name} ${ALL_FILES})
85 set(EXCLUDE_FROM_ALL OFF)
86 target_link_libraries( ${name} ${LLVM_USED_LIBS} )
87 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
88 if( LLVM_COMMON_DEPENDS )
89 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
90 endif( LLVM_COMMON_DEPENDS )
91 link_system_libs( ${name} )
92 endmacro(add_llvm_executable name)
95 macro(add_llvm_tool name)
96 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
97 if( NOT LLVM_BUILD_TOOLS )
98 set(EXCLUDE_FROM_ALL ON)
100 add_llvm_executable(${name} ${ARGN})
101 if( LLVM_BUILD_TOOLS )
102 install(TARGETS ${name} RUNTIME DESTINATION bin)
104 set_target_properties(${name} PROPERTIES FOLDER "Tools")
105 endmacro(add_llvm_tool name)
108 macro(add_llvm_example name)
109 # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
110 if( NOT LLVM_BUILD_EXAMPLES )
111 set(EXCLUDE_FROM_ALL ON)
113 add_llvm_executable(${name} ${ARGN})
114 if( LLVM_BUILD_EXAMPLES )
115 install(TARGETS ${name} RUNTIME DESTINATION examples)
117 set_target_properties(${name} PROPERTIES FOLDER "Examples")
118 endmacro(add_llvm_example name)
121 macro(add_llvm_utility name)
122 add_llvm_executable(${name} ${ARGN})
123 set_target_properties(${name} PROPERTIES FOLDER "Utils")
124 endmacro(add_llvm_utility name)
127 macro(add_llvm_target target_name)
128 include_directories(BEFORE
129 ${CMAKE_CURRENT_BINARY_DIR}
130 ${CMAKE_CURRENT_SOURCE_DIR})
131 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
132 set( CURRENT_LLVM_TARGET LLVM${target_name} )
133 endmacro(add_llvm_target)