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 # The LLVM Target library shall be built before its sublibraries
28 # (asmprinter, etc) because those may use tablegenned files which
29 # generation is triggered by the main LLVM target library. Necessary
30 # for parallel builds:
31 if( CURRENT_LLVM_TARGET )
32 add_dependencies(${name} ${CURRENT_LLVM_TARGET})
34 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
35 endmacro(add_llvm_library name)
38 macro(add_llvm_loadable_module name)
39 if( NOT LLVM_ON_UNIX OR CYGWIN )
40 message(STATUS "Loadable modules not supported on this platform.
42 # Add empty "phony" target
43 add_custom_target(${name})
45 llvm_process_sources( ALL_FILES ${ARGN} )
52 add_library( ${name} ${libkind} ${ALL_FILES} )
53 set_target_properties( ${name} PROPERTIES PREFIX "" )
55 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
56 link_system_libs( ${name} )
59 # Darwin-specific linker flags for loadable modules.
60 set_target_properties(${name} PROPERTIES
61 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
64 if( EXCLUDE_FROM_ALL )
65 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
67 install(TARGETS ${name}
68 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
69 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
73 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
74 endmacro(add_llvm_loadable_module name)
77 macro(add_llvm_executable name)
78 llvm_process_sources( ALL_FILES ${ARGN} )
79 if( EXCLUDE_FROM_ALL )
80 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
82 add_executable(${name} ${ALL_FILES})
84 set(EXCLUDE_FROM_ALL OFF)
85 target_link_libraries( ${name} ${LLVM_USED_LIBS} )
86 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
87 if( LLVM_COMMON_DEPENDS )
88 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
89 endif( LLVM_COMMON_DEPENDS )
90 link_system_libs( ${name} )
91 endmacro(add_llvm_executable name)
94 macro(add_llvm_tool name)
95 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
96 if( NOT LLVM_BUILD_TOOLS )
97 set(EXCLUDE_FROM_ALL ON)
99 add_llvm_executable(${name} ${ARGN})
100 if( LLVM_BUILD_TOOLS )
101 install(TARGETS ${name} RUNTIME DESTINATION bin)
103 set_target_properties(${name} PROPERTIES FOLDER "Tools")
104 endmacro(add_llvm_tool name)
107 macro(add_llvm_example name)
108 # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
109 if( NOT LLVM_BUILD_EXAMPLES )
110 set(EXCLUDE_FROM_ALL ON)
112 add_llvm_executable(${name} ${ARGN})
113 if( LLVM_BUILD_EXAMPLES )
114 install(TARGETS ${name} RUNTIME DESTINATION examples)
116 set_target_properties(${name} PROPERTIES FOLDER "Examples")
117 endmacro(add_llvm_example name)
120 macro(add_llvm_utility name)
121 add_llvm_executable(${name} ${ARGN})
122 set_target_properties(${name} PROPERTIES FOLDER "Utils")
123 endmacro(add_llvm_utility name)
126 macro(add_llvm_target target_name)
127 if( TABLEGEN_OUTPUT )
128 add_custom_target(${target_name}Table_gen
129 DEPENDS ${TABLEGEN_OUTPUT})
130 add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS})
131 endif( TABLEGEN_OUTPUT )
132 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
133 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
134 if ( TABLEGEN_OUTPUT )
135 add_dependencies(LLVM${target_name} ${target_name}Table_gen)
136 set_target_properties(${target_name}Table_gen PROPERTIES FOLDER "Tablegenning")
137 endif (TABLEGEN_OUTPUT)
138 set( CURRENT_LLVM_TARGET LLVM${target_name} )
139 endmacro(add_llvm_target)