blob: bfe5127a4b418067c7b7f698b3f293c87d222176 [file] [log] [blame]
Oscar Fuentes1bbdd462008-11-14 22:06:14 +00001include(LLVMProcessSources)
Oscar Fuentese7510c22011-04-05 17:02:48 +00002include(LLVM-Config)
Oscar Fuentes3d01fc72008-09-22 01:08:49 +00003
4macro(add_llvm_library name)
Oscar Fuentes50925fb2008-11-15 02:08:08 +00005 llvm_process_sources( ALL_FILES ${ARGN} )
6 add_library( ${name} ${ALL_FILES} )
Oscar Fuentes6d857ca2011-02-18 22:06:14 +00007 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
Oscar Fuentes1d8e4cf2008-09-22 18:21:51 +00008 if( LLVM_COMMON_DEPENDS )
9 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
10 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentes00a96182010-10-14 15:54:41 +000011
12 if( BUILD_SHARED_LIBS )
Oscar Fuentes879d3a92011-03-12 16:48:54 +000013 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes00a96182010-10-14 15:54:41 +000014 endif()
15
Oscar Fuentes23f0bfe2011-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 Lewyckybcffb1f2011-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 Fuentes0b85d072011-02-20 22:06:10 +000027 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
Daniel Dunbar288bc5c2011-11-29 01:31:52 +000028
29 # Add the explicit dependency information for this library.
30 #
31 # It would be nice to verify that we have the dependencies for this library
32 # name, but using get_property(... SET) doesn't suffice to determine if a
33 # property has been set to an empty value.
34 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
35 target_link_libraries(${name} ${lib_deps})
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000036endmacro(add_llvm_library name)
37
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000038macro(add_llvm_loadable_module name)
Oscar Fuentes01a575e2010-10-22 19:03:24 +000039 if( NOT LLVM_ON_UNIX OR CYGWIN )
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000040 message(STATUS "Loadable modules not supported on this platform.
41${name} ignored.")
NAKAMURA Takumi51c06bf2010-12-10 02:15:36 +000042 # Add empty "phony" target
43 add_custom_target(${name})
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000044 else()
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000045 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes71104282010-12-22 08:30:17 +000046 if (MODULE)
47 set(libkind MODULE)
48 else()
49 set(libkind SHARED)
50 endif()
51
52 add_library( ${name} ${libkind} ${ALL_FILES} )
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000053 set_target_properties( ${name} PROPERTIES PREFIX "" )
Douglas Gregor87814162009-11-10 15:30:33 +000054
Oscar Fuentes879d3a92011-03-12 16:48:54 +000055 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes23f0bfe2011-03-29 20:51:08 +000056 link_system_libs( ${name} )
Oscar Fuentes879d3a92011-03-12 16:48:54 +000057
Douglas Gregor87814162009-11-10 15:30:33 +000058 if (APPLE)
59 # Darwin-specific linker flags for loadable modules.
60 set_target_properties(${name} PROPERTIES
61 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
62 endif()
63
Oscar Fuentesab92d1e2011-04-26 14:55:27 +000064 if( EXCLUDE_FROM_ALL )
Nick Lewyckybcffb1f2011-04-29 02:12:06 +000065 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
Oscar Fuentesab92d1e2011-04-26 14:55:27 +000066 else()
67 install(TARGETS ${name}
68 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
69 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
70 endif()
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000071 endif()
Oscar Fuentes0b85d072011-02-20 22:06:10 +000072
73 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
Oscar Fuentesc5e1ae12009-11-10 02:45:37 +000074endmacro(add_llvm_loadable_module name)
75
76
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000077macro(add_llvm_executable name)
Oscar Fuentes50925fb2008-11-15 02:08:08 +000078 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentesb8352de2009-11-23 00:21:43 +000079 if( EXCLUDE_FROM_ALL )
80 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
81 else()
82 add_executable(${name} ${ALL_FILES})
83 endif()
84 set(EXCLUDE_FROM_ALL OFF)
Oscar Fuentes23f0bfe2011-03-29 20:51:08 +000085 target_link_libraries( ${name} ${LLVM_USED_LIBS} )
86 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentesd8b1b9a2009-08-14 04:38:57 +000087 if( LLVM_COMMON_DEPENDS )
88 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
89 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentes23f0bfe2011-03-29 20:51:08 +000090 link_system_libs( ${name} )
Oscar Fuentes3d01fc72008-09-22 01:08:49 +000091endmacro(add_llvm_executable name)
92
93
94macro(add_llvm_tool name)
95 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
Oscar Fuentes7be498e2009-11-23 00:32:42 +000096 if( NOT LLVM_BUILD_TOOLS )
Oscar Fuentesb8352de2009-11-23 00:21:43 +000097 set(EXCLUDE_FROM_ALL ON)
98 endif()
Oscar Fuentes066de852010-09-25 20:25:25 +000099 add_llvm_executable(${name} ${ARGN})
Oscar Fuentes7be498e2009-11-23 00:32:42 +0000100 if( LLVM_BUILD_TOOLS )
101 install(TARGETS ${name} RUNTIME DESTINATION bin)
102 endif()
Oscar Fuentes0b85d072011-02-20 22:06:10 +0000103 set_target_properties(${name} PROPERTIES FOLDER "Tools")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000104endmacro(add_llvm_tool name)
105
106
107macro(add_llvm_example name)
108# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
Oscar Fuentes7be498e2009-11-23 00:32:42 +0000109 if( NOT LLVM_BUILD_EXAMPLES )
Oscar Fuentesb8352de2009-11-23 00:21:43 +0000110 set(EXCLUDE_FROM_ALL ON)
111 endif()
Oscar Fuentes066de852010-09-25 20:25:25 +0000112 add_llvm_executable(${name} ${ARGN})
Oscar Fuentes7be498e2009-11-23 00:32:42 +0000113 if( LLVM_BUILD_EXAMPLES )
114 install(TARGETS ${name} RUNTIME DESTINATION examples)
115 endif()
Oscar Fuentes0b85d072011-02-20 22:06:10 +0000116 set_target_properties(${name} PROPERTIES FOLDER "Examples")
Oscar Fuentes3d01fc72008-09-22 01:08:49 +0000117endmacro(add_llvm_example name)
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000118
119
Oscar Fuentes0b85d072011-02-20 22:06:10 +0000120macro(add_llvm_utility name)
121 add_llvm_executable(${name} ${ARGN})
122 set_target_properties(${name} PROPERTIES FOLDER "Utils")
123endmacro(add_llvm_utility name)
124
125
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000126macro(add_llvm_target target_name)
Oscar Fuentesd7808d22011-07-25 20:17:01 +0000127 include_directories(BEFORE
128 ${CMAKE_CURRENT_BINARY_DIR}
129 ${CMAKE_CURRENT_SOURCE_DIR})
Douglas Gregor7e9e36a2009-06-23 17:57:35 +0000130 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
Oscar Fuentes00d78f12011-02-20 02:55:27 +0000131 set( CURRENT_LLVM_TARGET LLVM${target_name} )
Oscar Fuentese1ad0872008-09-26 04:40:32 +0000132endmacro(add_llvm_target)
Michael J. Spencer3c00db72012-04-26 19:43:35 +0000133
134# Add external project that may want to be built as part of llvm such as Clang,
135# lld, and Polly. This adds two options. One for the source directory of the
136# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
137# enable or disable building it with everthing else.
138macro(add_llvm_external_project name)
139 string(TOUPPER ${name} nameUPPER)
140 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
141 CACHE PATH "Path to ${name} source directory")
142 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
143 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
144 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
145 "Whether to build ${name} as part of LLVM" ON)
146 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
147 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${name})
148 endif()
149 endif()
150endmacro(add_llvm_external_project)