blob: cf9ea72107d5c9beaad4b3f57ff61dcad84c174a [file] [log] [blame]
Oscar Fuentes751ea9d2008-11-14 22:06:14 +00001include(LLVMProcessSources)
Oscar Fuentesd8a6dd62011-04-05 17:02:48 +00002include(LLVM-Config)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +00003
4macro(add_llvm_library name)
Oscar Fuentes2c10b222008-11-15 02:08:08 +00005 llvm_process_sources( ALL_FILES ${ARGN} )
6 add_library( ${name} ${ALL_FILES} )
Oscar Fuentes5ed96262011-02-18 22:06:14 +00007 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
Oscar Fuentes8807bdd2008-09-22 18:21:51 +00008 if( LLVM_COMMON_DEPENDS )
9 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
10 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentesffe32e12010-10-14 15:54:41 +000011
12 if( BUILD_SHARED_LIBS )
Oscar Fuentescc48b9a2011-03-12 16:48:54 +000013 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentesffe32e12010-10-14 15:54:41 +000014 endif()
15
Oscar Fuentes978e5282011-03-29 20:51:08 +000016 # 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} )
19
Nick Lewycky61aed872011-04-29 02:12:06 +000020 if( EXCLUDE_FROM_ALL )
21 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
22 else()
23 install(TARGETS ${name}
24 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
25 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
26 endif()
Oscar Fuentes8160d282009-08-16 05:16:43 +000027 # 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 )
Benjamin Kramer171a7d62009-08-16 09:44:27 +000032 add_dependencies(${name} ${CURRENT_LLVM_TARGET})
Oscar Fuentes8160d282009-08-16 05:16:43 +000033 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +000034 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000035endmacro(add_llvm_library name)
36
Chandler Carruth9d7feab2011-07-29 00:14:25 +000037macro(add_llvm_library_dependencies name)
38 # Save the dependencies of the LLVM library in a variable so that we can
39 # query it when resolve llvm-config-style component -> library mappings.
40 set(LLVM_LIB_DEPS_${name} ${ARGN})
41
42 # Then add the actual dependencies to the library target.
43 target_link_libraries(${name} ${ARGN})
44endmacro(add_llvm_library_dependencies name)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000045
Oscar Fuentesbbc10672009-11-10 02:45:37 +000046macro(add_llvm_loadable_module name)
Oscar Fuentesff11a232010-10-22 19:03:24 +000047 if( NOT LLVM_ON_UNIX OR CYGWIN )
Oscar Fuentesbbc10672009-11-10 02:45:37 +000048 message(STATUS "Loadable modules not supported on this platform.
49${name} ignored.")
NAKAMURA Takumia8c1c3f2010-12-10 02:15:36 +000050 # Add empty "phony" target
51 add_custom_target(${name})
Oscar Fuentesbbc10672009-11-10 02:45:37 +000052 else()
Oscar Fuentesbbc10672009-11-10 02:45:37 +000053 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes9f2b3842010-12-22 08:30:17 +000054 if (MODULE)
55 set(libkind MODULE)
56 else()
57 set(libkind SHARED)
58 endif()
59
60 add_library( ${name} ${libkind} ${ALL_FILES} )
Oscar Fuentesbbc10672009-11-10 02:45:37 +000061 set_target_properties( ${name} PROPERTIES PREFIX "" )
Douglas Gregor66df54f2009-11-10 15:30:33 +000062
Oscar Fuentescc48b9a2011-03-12 16:48:54 +000063 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes978e5282011-03-29 20:51:08 +000064 link_system_libs( ${name} )
Oscar Fuentescc48b9a2011-03-12 16:48:54 +000065
Douglas Gregor66df54f2009-11-10 15:30:33 +000066 if (APPLE)
67 # Darwin-specific linker flags for loadable modules.
68 set_target_properties(${name} PROPERTIES
69 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
70 endif()
71
Oscar Fuentes638aaec2011-04-26 14:55:27 +000072 if( EXCLUDE_FROM_ALL )
Nick Lewycky61aed872011-04-29 02:12:06 +000073 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
Oscar Fuentes638aaec2011-04-26 14:55:27 +000074 else()
75 install(TARGETS ${name}
76 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
77 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
78 endif()
Oscar Fuentesbbc10672009-11-10 02:45:37 +000079 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +000080
81 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
Oscar Fuentesbbc10672009-11-10 02:45:37 +000082endmacro(add_llvm_loadable_module name)
83
84
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000085macro(add_llvm_executable name)
Oscar Fuentes2c10b222008-11-15 02:08:08 +000086 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +000087 if( EXCLUDE_FROM_ALL )
88 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
89 else()
90 add_executable(${name} ${ALL_FILES})
91 endif()
92 set(EXCLUDE_FROM_ALL OFF)
Oscar Fuentes978e5282011-03-29 20:51:08 +000093 target_link_libraries( ${name} ${LLVM_USED_LIBS} )
94 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes3fca0e82009-08-14 04:38:57 +000095 if( LLVM_COMMON_DEPENDS )
96 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
97 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentes978e5282011-03-29 20:51:08 +000098 link_system_libs( ${name} )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000099endmacro(add_llvm_executable name)
100
101
102macro(add_llvm_tool name)
103 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000104 if( NOT LLVM_BUILD_TOOLS )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000105 set(EXCLUDE_FROM_ALL ON)
106 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000107 add_llvm_executable(${name} ${ARGN})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000108 if( LLVM_BUILD_TOOLS )
109 install(TARGETS ${name} RUNTIME DESTINATION bin)
110 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000111 set_target_properties(${name} PROPERTIES FOLDER "Tools")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000112endmacro(add_llvm_tool name)
113
114
115macro(add_llvm_example name)
116# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000117 if( NOT LLVM_BUILD_EXAMPLES )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000118 set(EXCLUDE_FROM_ALL ON)
119 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000120 add_llvm_executable(${name} ${ARGN})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000121 if( LLVM_BUILD_EXAMPLES )
122 install(TARGETS ${name} RUNTIME DESTINATION examples)
123 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000124 set_target_properties(${name} PROPERTIES FOLDER "Examples")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000125endmacro(add_llvm_example name)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000126
127
Oscar Fuentes3145e922011-02-20 22:06:10 +0000128macro(add_llvm_utility name)
129 add_llvm_executable(${name} ${ARGN})
130 set_target_properties(${name} PROPERTIES FOLDER "Utils")
131endmacro(add_llvm_utility name)
132
133
Oscar Fuentescdc95492008-09-26 04:40:32 +0000134macro(add_llvm_target target_name)
Oscar Fuentes4f0f3352011-07-25 20:17:01 +0000135 include_directories(BEFORE
136 ${CMAKE_CURRENT_BINARY_DIR}
137 ${CMAKE_CURRENT_SOURCE_DIR})
Douglas Gregor85fedbe2009-06-23 17:57:35 +0000138 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
Oscar Fuentesba1186c2011-02-20 02:55:27 +0000139 set( CURRENT_LLVM_TARGET LLVM${target_name} )
Oscar Fuentescdc95492008-09-26 04:40:32 +0000140endmacro(add_llvm_target)