blob: 0933a02a015b3272eea2c25d97e3a824b4116683 [file] [log] [blame]
Chandler Carruth69ce6652012-06-30 10:14:14 +00001include(LLVMParseArguments)
Oscar Fuentes751ea9d2008-11-14 22:06:14 +00002include(LLVMProcessSources)
Oscar Fuentesd8a6dd62011-04-05 17:02:48 +00003include(LLVM-Config)
Oscar Fuentesa229b3c2008-09-22 01:08:49 +00004
Nico Weberc27118d2013-12-28 23:31:44 +00005function(add_llvm_symbol_exports target_name export_file)
6 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
7 set(native_export_file "symbol.exports")
8 add_custom_command(OUTPUT symbol.exports
9 COMMAND sed -e "s/^/_/" < ${export_file} > symbol.exports
10 DEPENDS ${export_file}
11 VERBATIM
12 COMMENT "Creating export file for ${target_name}")
13 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
14 LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports")
15 elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
16 # Gold and BFD ld require a version script rather than a plain list.
17 set(native_export_file "symbol.exports")
18 # FIXME: Don't write the "local:" line on OpenBSD.
19 add_custom_command(OUTPUT symbol.exports
20 COMMAND echo "{" > symbol.exports
21 COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> symbol.exports || :
Nico Webera69d1a82013-12-28 23:39:49 +000022 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> symbol.exports
Nico Weberc27118d2013-12-28 23:31:44 +000023 COMMAND echo " local: *;" >> symbol.exports
24 COMMAND echo "};" >> symbol.exports
25 DEPENDS ${export_file}
26 VERBATIM
27 COMMENT "Creating export file for ${target_name}")
28 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
29 LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports")
30 else()
31 set(native_export_file "symbol.def")
32
33 set(CAT "type")
34 if(CYGWIN)
35 set(CAT "cat")
36 endif()
37
Nico Weber5c8a4a32013-12-29 04:05:23 +000038 # Using ${export_file} in add_custom_command directly confuses cmd.exe.
39 file(TO_NATIVE_PATH ${export_file} export_file_backslashes)
40
Nico Weberc27118d2013-12-28 23:31:44 +000041 add_custom_command(OUTPUT symbol.def
Nico Weberb42359d2013-12-29 00:11:20 +000042 COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > symbol.def
Nico Weber5c8a4a32013-12-29 04:05:23 +000043 COMMAND ${CAT} ${export_file_backslashes} >> symbol.def
Nico Weberc27118d2013-12-28 23:31:44 +000044 DEPENDS ${export_file}
45 VERBATIM
46 COMMENT "Creating export file for ${target_name}")
Nico Weber49da7582013-12-29 06:56:28 +000047 if(CYGWIN)
48 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
49 LINK_FLAGS "${CMAKE_CURRENT_BINARY_DIR}/symbol.def")
50 else()
51 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
52 LINK_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}/symbol.def")
53 endif()
Nico Weberc27118d2013-12-28 23:31:44 +000054 endif()
55
56 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
57
58 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
59 foreach(src ${srcs})
60 get_filename_component(extension ${src} EXT)
61 if(extension STREQUAL ".cpp")
62 set(first_source_file ${src})
63 break()
64 endif()
65 endforeach()
66
67 # Force re-linking when the exports file changes. Actually, it
68 # forces recompilation of the source file. The LINK_DEPENDS target
69 # property only works for makefile-based generators.
70 set_property(SOURCE ${first_source_file} APPEND PROPERTY
71 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
72
73 set_property(DIRECTORY APPEND
74 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
75
76 add_dependencies(${target_name} ${target_name}_exports)
77endfunction(add_llvm_symbol_exports)
78
Oscar Fuentesa229b3c2008-09-22 01:08:49 +000079macro(add_llvm_library name)
Oscar Fuentes2c10b222008-11-15 02:08:08 +000080 llvm_process_sources( ALL_FILES ${ARGN} )
81 add_library( ${name} ${ALL_FILES} )
Oscar Fuentes5ed96262011-02-18 22:06:14 +000082 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
Oscar Fuentes8807bdd2008-09-22 18:21:51 +000083 if( LLVM_COMMON_DEPENDS )
84 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
85 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentesffe32e12010-10-14 15:54:41 +000086
87 if( BUILD_SHARED_LIBS )
Oscar Fuentescc48b9a2011-03-12 16:48:54 +000088 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
NAKAMURA Takumicb065a62013-08-14 03:34:49 +000089 if (MSVC)
90 set_target_properties(${name}
91 PROPERTIES
92 IMPORT_SUFFIX ".imp")
93 endif ()
Oscar Fuentesffe32e12010-10-14 15:54:41 +000094
Nico Weber06473f82013-12-29 05:39:01 +000095 if (LLVM_EXPORTED_SYMBOL_FILE)
96 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
97 endif()
Nico Weberc27118d2013-12-28 23:31:44 +000098 endif()
99
Oscar Fuentes978e5282011-03-29 20:51:08 +0000100 # Ensure that the system libraries always comes last on the
101 # list. Without this, linking the unit tests on MinGW fails.
102 link_system_libs( ${name} )
103
Nick Lewycky61aed872011-04-29 02:12:06 +0000104 if( EXCLUDE_FROM_ALL )
105 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
106 else()
Hans Wennborg16546272013-08-24 00:20:36 +0000107 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
108 install(TARGETS ${name}
109 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
110 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
111 endif()
Nick Lewycky61aed872011-04-29 02:12:06 +0000112 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000113 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
Daniel Dunbarfaaa76d2011-11-29 01:31:52 +0000114
115 # Add the explicit dependency information for this library.
116 #
117 # It would be nice to verify that we have the dependencies for this library
118 # name, but using get_property(... SET) doesn't suffice to determine if a
119 # property has been set to an empty value.
120 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
121 target_link_libraries(${name} ${lib_deps})
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000122endmacro(add_llvm_library name)
123
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000124macro(add_llvm_loadable_module name)
Oscar Fuentesff11a232010-10-22 19:03:24 +0000125 if( NOT LLVM_ON_UNIX OR CYGWIN )
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000126 message(STATUS "Loadable modules not supported on this platform.
127${name} ignored.")
NAKAMURA Takumia8c1c3f2010-12-10 02:15:36 +0000128 # Add empty "phony" target
129 add_custom_target(${name})
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000130 else()
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000131 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes9f2b3842010-12-22 08:30:17 +0000132 if (MODULE)
133 set(libkind MODULE)
134 else()
135 set(libkind SHARED)
136 endif()
137
Nico Weberc27118d2013-12-28 23:31:44 +0000138 if (LLVM_EXPORTED_SYMBOL_FILE)
139 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
140 endif(LLVM_EXPORTED_SYMBOL_FILE)
141
Oscar Fuentes9f2b3842010-12-22 08:30:17 +0000142 add_library( ${name} ${libkind} ${ALL_FILES} )
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000143 set_target_properties( ${name} PROPERTIES PREFIX "" )
Douglas Gregor66df54f2009-11-10 15:30:33 +0000144
Oscar Fuentescc48b9a2011-03-12 16:48:54 +0000145 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes978e5282011-03-29 20:51:08 +0000146 link_system_libs( ${name} )
Oscar Fuentescc48b9a2011-03-12 16:48:54 +0000147
Douglas Gregor66df54f2009-11-10 15:30:33 +0000148 if (APPLE)
149 # Darwin-specific linker flags for loadable modules.
150 set_target_properties(${name} PROPERTIES
151 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
152 endif()
153
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000154 if( EXCLUDE_FROM_ALL )
Nick Lewycky61aed872011-04-29 02:12:06 +0000155 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000156 else()
Hans Wennborg16546272013-08-24 00:20:36 +0000157 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
158 install(TARGETS ${name}
159 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
160 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
161 endif()
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000162 endif()
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000163 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000164
165 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000166endmacro(add_llvm_loadable_module name)
167
168
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000169macro(add_llvm_executable name)
Oscar Fuentes2c10b222008-11-15 02:08:08 +0000170 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000171 if( EXCLUDE_FROM_ALL )
172 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
173 else()
174 add_executable(${name} ${ALL_FILES})
175 endif()
Nico Weberc27118d2013-12-28 23:31:44 +0000176
177 if (LLVM_EXPORTED_SYMBOL_FILE)
178 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
179 endif(LLVM_EXPORTED_SYMBOL_FILE)
180
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000181 set(EXCLUDE_FROM_ALL OFF)
Oscar Fuentes978e5282011-03-29 20:51:08 +0000182 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes3fca0e82009-08-14 04:38:57 +0000183 if( LLVM_COMMON_DEPENDS )
184 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
185 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentes978e5282011-03-29 20:51:08 +0000186 link_system_libs( ${name} )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000187endmacro(add_llvm_executable name)
188
189
Hans Wennborg16546272013-08-24 00:20:36 +0000190set (LLVM_TOOLCHAIN_TOOLS
191 llvm-ar
192 llvm-objdump
193 )
194
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000195macro(add_llvm_tool name)
196 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000197 if( NOT LLVM_BUILD_TOOLS )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000198 set(EXCLUDE_FROM_ALL ON)
199 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000200 add_llvm_executable(${name} ${ARGN})
Hans Wennborg16546272013-08-24 00:20:36 +0000201
202 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
203 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
204 if( LLVM_BUILD_TOOLS )
205 install(TARGETS ${name} RUNTIME DESTINATION bin)
206 endif()
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000207 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000208 set_target_properties(${name} PROPERTIES FOLDER "Tools")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000209endmacro(add_llvm_tool name)
210
211
212macro(add_llvm_example name)
213# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000214 if( NOT LLVM_BUILD_EXAMPLES )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000215 set(EXCLUDE_FROM_ALL ON)
216 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000217 add_llvm_executable(${name} ${ARGN})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000218 if( LLVM_BUILD_EXAMPLES )
219 install(TARGETS ${name} RUNTIME DESTINATION examples)
220 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000221 set_target_properties(${name} PROPERTIES FOLDER "Examples")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000222endmacro(add_llvm_example name)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000223
224
Oscar Fuentes3145e922011-02-20 22:06:10 +0000225macro(add_llvm_utility name)
226 add_llvm_executable(${name} ${ARGN})
227 set_target_properties(${name} PROPERTIES FOLDER "Utils")
228endmacro(add_llvm_utility name)
229
230
Oscar Fuentescdc95492008-09-26 04:40:32 +0000231macro(add_llvm_target target_name)
Oscar Fuentes4f0f3352011-07-25 20:17:01 +0000232 include_directories(BEFORE
233 ${CMAKE_CURRENT_BINARY_DIR}
234 ${CMAKE_CURRENT_SOURCE_DIR})
Douglas Gregor85fedbe2009-06-23 17:57:35 +0000235 add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
Oscar Fuentesba1186c2011-02-20 02:55:27 +0000236 set( CURRENT_LLVM_TARGET LLVM${target_name} )
Oscar Fuentescdc95492008-09-26 04:40:32 +0000237endmacro(add_llvm_target)
Michael J. Spencere734f542012-04-26 19:43:35 +0000238
239# Add external project that may want to be built as part of llvm such as Clang,
240# lld, and Polly. This adds two options. One for the source directory of the
241# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
Alp Toker171b0c32013-12-20 00:33:39 +0000242# enable or disable building it with everything else.
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000243# Additional parameter can be specified as the name of directory.
Michael J. Spencere734f542012-04-26 19:43:35 +0000244macro(add_llvm_external_project name)
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000245 set(add_llvm_external_dir "${ARGN}")
246 if("${add_llvm_external_dir}" STREQUAL "")
247 set(add_llvm_external_dir ${name})
248 endif()
Argyrios Kyrtzidis7eec9d02013-08-21 19:13:44 +0000249 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000250 string(REPLACE "-" "_" nameUNDERSCORE ${name})
251 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
252 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
Michael J. Spencere734f542012-04-26 19:43:35 +0000253 CACHE PATH "Path to ${name} source directory")
254 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
255 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
256 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
257 "Whether to build ${name} as part of LLVM" ON)
258 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000259 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
Michael J. Spencere734f542012-04-26 19:43:35 +0000260 endif()
261 endif()
262endmacro(add_llvm_external_project)
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000263
Argyrios Kyrtzidis7eec9d02013-08-21 19:13:44 +0000264macro(add_llvm_tool_subdirectory name)
265 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
266 add_subdirectory(${name})
267endmacro(add_llvm_tool_subdirectory)
268
269macro(ignore_llvm_tool_subdirectory name)
270 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
271endmacro(ignore_llvm_tool_subdirectory)
272
273function(add_llvm_implicit_external_projects)
274 set(list_of_implicit_subdirs "")
275 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
276 foreach(dir ${sub-dirs})
277 if(IS_DIRECTORY "${dir}")
278 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
279 if( tool_subdir_ignore EQUAL -1
280 AND EXISTS "${dir}/CMakeLists.txt")
281 get_filename_component(fn "${dir}" NAME)
282 list(APPEND list_of_implicit_subdirs "${fn}")
283 endif()
284 endif()
285 endforeach()
286
287 foreach(external_proj ${list_of_implicit_subdirs})
288 add_llvm_external_project("${external_proj}")
289 endforeach()
290endfunction(add_llvm_implicit_external_projects)
291
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000292# Generic support for adding a unittest.
Chandler Carruth94d02512012-06-21 09:51:26 +0000293function(add_unittest test_suite test_name)
NAKAMURA Takumic42bdfc2013-01-27 12:46:53 +0000294 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000295 if( NOT LLVM_BUILD_TESTS )
296 set(EXCLUDE_FROM_ALL ON)
297 endif()
298
299 add_llvm_executable(${test_name} ${ARGN})
300 target_link_libraries(${test_name}
301 gtest
302 gtest_main
303 LLVMSupport # gtest needs it for raw_ostream.
304 )
305
306 add_dependencies(${test_suite} ${test_name})
307 get_target_property(test_suite_folder ${test_suite} FOLDER)
308 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
309 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
310 endif ()
311
312 # Visual Studio 2012 only supports up to 8 template parameters in
313 # std::tr1::tuple by default, but gtest requires 10
314 if (MSVC AND MSVC_VERSION EQUAL 1700)
315 set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS _VARIADIC_MAX=10)
316 endif ()
317
318 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
319 set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000320 if (NOT LLVM_ENABLE_THREADS)
321 set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
322 endif ()
323
Chandler Carruth582e8a52012-06-21 18:44:24 +0000324 get_property(target_compile_flags TARGET ${test_name} PROPERTY COMPILE_FLAGS)
325 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
326 set(target_compile_flags "${target_compile_flags} -fno-rtti")
327 elseif (MSVC)
Aaron Ballmanbde2cd12013-08-06 23:34:04 +0000328 llvm_replace_compiler_option(target_compile_flags "/GR" "/GR-")
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000329 endif ()
Chandler Carruth582e8a52012-06-21 18:44:24 +0000330
331 if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
332 set(target_compile_flags "${target_compile_flags} -Wno-variadic-macros")
333 endif ()
334 set_property(TARGET ${test_name} PROPERTY COMPILE_FLAGS "${target_compile_flags}")
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000335endfunction()
Chandler Carruth3511dd32012-06-28 06:36:24 +0000336
337# This function provides an automatic way to 'configure'-like generate a file
Alp Toker171b0c32013-12-20 00:33:39 +0000338# based on a set of common and custom variables, specifically targeting the
Chandler Carruth3511dd32012-06-28 06:36:24 +0000339# variables needed for the 'lit.site.cfg' files. This function bundles the
340# common variables that any Lit instance is likely to need, and custom
341# variables can be passed in.
342function(configure_lit_site_cfg input output)
343 foreach(c ${LLVM_TARGETS_TO_BUILD})
344 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
345 endforeach(c)
346 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
347
348 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
NAKAMURA Takumie73df852013-12-16 16:03:08 +0000349 set(SHLIBDIR "${LLVM_LIBRARY_OUTPUT_INTDIR}")
Chandler Carruth3511dd32012-06-28 06:36:24 +0000350
351 if(BUILD_SHARED_LIBS)
352 set(LLVM_SHARED_LIBS_ENABLED "1")
353 else()
354 set(LLVM_SHARED_LIBS_ENABLED "0")
355 endif(BUILD_SHARED_LIBS)
356
357 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
358 set(SHLIBPATH_VAR "DYLD_LIBRARY_PATH")
359 else() # Default for all other unix like systems.
360 # CMake hardcodes the library locaction using rpath.
361 # Therefore LD_LIBRARY_PATH is not required to run binaries in the
362 # build dir. We pass it anyways.
363 set(SHLIBPATH_VAR "LD_LIBRARY_PATH")
364 endif()
365
366 # Configuration-time: See Unit/lit.site.cfg.in
NAKAMURA Takumi0dc10d52013-12-04 11:15:17 +0000367 if (CMAKE_CFG_INTDIR STREQUAL ".")
368 set(LLVM_BUILD_MODE ".")
369 else ()
370 set(LLVM_BUILD_MODE "%(build_mode)s")
371 endif ()
Chandler Carruth3511dd32012-06-28 06:36:24 +0000372
373 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
374 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
NAKAMURA Takumie73df852013-12-16 16:03:08 +0000375 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
376 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
Chandler Carruth3511dd32012-06-28 06:36:24 +0000377 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
378 set(ENABLE_SHARED ${LLVM_SHARED_LIBS_ENABLED})
379 set(SHLIBPATH_VAR ${SHLIBPATH_VAR})
380
381 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
382 set(ENABLE_ASSERTIONS "1")
383 else()
384 set(ENABLE_ASSERTIONS "0")
385 endif()
386
Tim Northoverbfe84682013-02-14 16:49:32 +0000387 set(HOST_OS ${CMAKE_SYSTEM_NAME})
388 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
Chandler Carruth3511dd32012-06-28 06:36:24 +0000389
Roman Divackyc9871112013-08-27 19:25:01 +0000390 if (CLANG_ENABLE_ARCMT)
391 set(ENABLE_CLANG_ARCMT "1")
392 else()
393 set(ENABLE_CLANG_ARCMT "0")
394 endif()
395 if (CLANG_ENABLE_REWRITER)
396 set(ENABLE_CLANG_REWRITER "1")
397 else()
398 set(ENABLE_CLANG_REWRITER "0")
399 endif()
400 if (CLANG_ENABLE_STATIC_ANALYZER)
401 set(ENABLE_CLANG_STATIC_ANALYZER "1")
402 else()
403 set(ENABLE_CLANG_STATIC_ANALYZER "0")
404 endif()
405
Chandler Carruth3511dd32012-06-28 06:36:24 +0000406 configure_file(${input} ${output} @ONLY)
407endfunction()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000408
409# A raw function to create a lit target. This is used to implement the testuite
410# management functions.
411function(add_lit_target target comment)
NAKAMURA Takumi69a89c72013-12-19 17:11:08 +0000412 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
Chandler Carruth69ce6652012-06-30 10:14:14 +0000413 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
414 separate_arguments(LIT_ARGS)
NAKAMURA Takumi0dc10d52013-12-04 11:15:17 +0000415 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
416 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
417 endif ()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000418 set(LIT_COMMAND
419 ${PYTHON_EXECUTABLE}
NAKAMURA Takumi69a89c72013-12-19 17:11:08 +0000420 ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py
Chandler Carruth69ce6652012-06-30 10:14:14 +0000421 ${LIT_ARGS}
422 )
423 foreach(param ${ARG_PARAMS})
424 list(APPEND LIT_COMMAND --param ${param})
425 endforeach()
NAKAMURA Takumi04a664e2012-12-24 22:43:59 +0000426 if( ARG_DEPENDS )
427 add_custom_target(${target}
428 COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS}
429 COMMENT "${comment}"
430 )
431 add_dependencies(${target} ${ARG_DEPENDS})
432 else()
433 add_custom_target(${target}
Nico Weberb42359d2013-12-29 00:11:20 +0000434 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
NAKAMURA Takumi04a664e2012-12-24 22:43:59 +0000435 message(STATUS "${target} does nothing.")
436 endif()
NAKAMURA Takumi03fc7302013-12-02 11:31:19 +0000437
438 # Tests should be excluded from "Build Solution".
439 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
Chandler Carruth69ce6652012-06-30 10:14:14 +0000440endfunction()
441
442# A function to add a set of lit test suites to be driven through 'check-*' targets.
443function(add_lit_testsuite target comment)
444 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
445
NAKAMURA Takumi54d22742012-10-10 13:32:55 +0000446 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
447 if(NOT EXCLUDE_FROM_ALL)
448 # Register the testsuites, params and depends for the global check rule.
449 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS})
450 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
451 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
452 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
453 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000454
455 # Produce a specific suffixed check rule.
456 add_lit_target(${target} ${comment}
457 ${ARG_DEFAULT_ARGS}
458 PARAMS ${ARG_PARAMS}
459 DEPENDS ${ARG_DEPENDS}
460 ARGS ${ARG_ARGS}
461 )
462endfunction()