blob: 4d081bd8651cdeeb25a3ed9e8f162de5f106b416 [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
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +00005function(llvm_update_compile_flags name)
NAKAMURA Takumib524c222014-01-28 11:40:04 +00006 get_property(sources TARGET ${name} PROPERTY SOURCES)
7 if("${sources}" MATCHES "\\.c(;|$)")
NAKAMURA Takumia679f432014-01-28 09:44:06 +00008 set(update_src_props ON)
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +00009 endif()
NAKAMURA Takumia679f432014-01-28 09:44:06 +000010
Dan Liewa5bdc842014-07-22 15:41:18 +000011 # LLVM_REQUIRES_EH is an internal flag that individual
12 # targets can use to force EH
13 if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH)
14 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
15 message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}")
16 set(LLVM_REQUIRES_RTTI ON)
17 endif()
NAKAMURA Takumia679f432014-01-28 09:44:06 +000018 else()
19 if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +000020 list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
NAKAMURA Takumia679f432014-01-28 09:44:06 +000021 elseif(MSVC)
22 list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +000023 list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
NAKAMURA Takumia679f432014-01-28 09:44:06 +000024 endif()
25 endif()
26
Dan Liewa5bdc842014-07-22 15:41:18 +000027 # LLVM_REQUIRES_RTTI is an internal flag that individual
28 # targets can use to force RTTI
29 if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +000030 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
31 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +000032 list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +000033 elseif (MSVC)
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +000034 list(APPEND LLVM_COMPILE_FLAGS "/GR-")
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +000035 endif ()
36 endif()
37
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +000038 # Assume that;
39 # - LLVM_COMPILE_FLAGS is list.
40 # - PROPERTY COMPILE_FLAGS is string.
41 string(REPLACE ";" " " target_compile_flags "${LLVM_COMPILE_FLAGS}")
42
NAKAMURA Takumia679f432014-01-28 09:44:06 +000043 if(update_src_props)
NAKAMURA Takumib524c222014-01-28 11:40:04 +000044 foreach(fn ${sources})
NAKAMURA Takumia679f432014-01-28 09:44:06 +000045 get_filename_component(suf ${fn} EXT)
46 if("${suf}" STREQUAL ".cpp")
NAKAMURA Takumid40cdc92014-01-31 17:32:42 +000047 set_property(SOURCE ${fn} APPEND_STRING PROPERTY
48 COMPILE_FLAGS "${target_compile_flags}")
NAKAMURA Takumia679f432014-01-28 09:44:06 +000049 endif()
50 endforeach()
51 else()
52 # Update target props, since all sources are C++.
53 set_property(TARGET ${name} APPEND_STRING PROPERTY
54 COMPILE_FLAGS "${target_compile_flags}")
55 endif()
56
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +000057 set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
58endfunction()
59
Nico Weberc27118d2013-12-28 23:31:44 +000060function(add_llvm_symbol_exports target_name export_file)
61 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
NAKAMURA Takumibbd2aaa2013-12-29 16:15:26 +000062 set(native_export_file "${target_name}.exports")
NAKAMURA Takumi81210752013-12-29 16:15:18 +000063 add_custom_command(OUTPUT ${native_export_file}
64 COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file}
Nico Weberc27118d2013-12-28 23:31:44 +000065 DEPENDS ${export_file}
66 VERBATIM
67 COMMENT "Creating export file for ${target_name}")
68 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
NAKAMURA Takumi81210752013-12-29 16:15:18 +000069 LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
Nico Weberc27118d2013-12-28 23:31:44 +000070 elseif(LLVM_HAVE_LINK_VERSION_SCRIPT)
71 # Gold and BFD ld require a version script rather than a plain list.
NAKAMURA Takumibbd2aaa2013-12-29 16:15:26 +000072 set(native_export_file "${target_name}.exports")
Nico Weberc27118d2013-12-28 23:31:44 +000073 # FIXME: Don't write the "local:" line on OpenBSD.
NAKAMURA Takumi81210752013-12-29 16:15:18 +000074 add_custom_command(OUTPUT ${native_export_file}
75 COMMAND echo "{" > ${native_export_file}
76 COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
77 COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
78 COMMAND echo " local: *;" >> ${native_export_file}
79 COMMAND echo "};" >> ${native_export_file}
Nico Weberc27118d2013-12-28 23:31:44 +000080 DEPENDS ${export_file}
81 VERBATIM
82 COMMENT "Creating export file for ${target_name}")
83 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
Nico Weberdc78dc92013-12-29 23:04:48 +000084 LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
Nico Weberc27118d2013-12-28 23:31:44 +000085 else()
NAKAMURA Takumibbd2aaa2013-12-29 16:15:26 +000086 set(native_export_file "${target_name}.def")
Nico Weberc27118d2013-12-28 23:31:44 +000087
Chris Bieneman970555b2014-10-30 22:37:58 +000088 set(CAT "cat")
89 set(export_file_nativeslashes ${export_file})
90 if(WIN32 AND NOT CYGWIN)
91 set(CAT "type")
92 # Convert ${export_file} to native format (backslashes) for "type"
93 # Does not use file(TO_NATIVE_PATH) as it doesn't create a native
94 # path but a build-system specific format (see CMake bug
95 # http://public.kitware.com/Bug/print_bug_page.php?bug_id=5939 )
96 string(REPLACE / \\ export_file_nativeslashes ${export_file})
Nico Weberc27118d2013-12-28 23:31:44 +000097 endif()
98
NAKAMURA Takumi81210752013-12-29 16:15:18 +000099 add_custom_command(OUTPUT ${native_export_file}
100 COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file}
Chris Bieneman970555b2014-10-30 22:37:58 +0000101 COMMAND ${CAT} ${export_file_nativeslashes} >> ${native_export_file}
Nico Weberc27118d2013-12-28 23:31:44 +0000102 DEPENDS ${export_file}
103 VERBATIM
104 COMMENT "Creating export file for ${target_name}")
Chris Bieneman970555b2014-10-30 22:37:58 +0000105 set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}")
106 if(MSVC)
107 set(export_file_linker_flag "/DEF:${export_file_linker_flag}")
NAKAMURA Takumi0a062bd2013-12-29 16:19:13 +0000108 endif()
Chris Bieneman970555b2014-10-30 22:37:58 +0000109 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
110 LINK_FLAGS " ${export_file_linker_flag}")
Nico Weberc27118d2013-12-28 23:31:44 +0000111 endif()
112
113 add_custom_target(${target_name}_exports DEPENDS ${native_export_file})
NAKAMURA Takumi14f1f442014-01-27 17:39:38 +0000114 set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc")
Nico Weberc27118d2013-12-28 23:31:44 +0000115
116 get_property(srcs TARGET ${target_name} PROPERTY SOURCES)
117 foreach(src ${srcs})
118 get_filename_component(extension ${src} EXT)
119 if(extension STREQUAL ".cpp")
120 set(first_source_file ${src})
121 break()
122 endif()
123 endforeach()
124
125 # Force re-linking when the exports file changes. Actually, it
126 # forces recompilation of the source file. The LINK_DEPENDS target
127 # property only works for makefile-based generators.
Quentin Colombetcb2ae8d2014-01-16 06:43:55 +0000128 # FIXME: This is not safe because this will create the same target
129 # ${native_export_file} in several different file:
130 # - One where we emitted ${target_name}_exports
131 # - One where we emitted the build command for the following object.
132 # set_property(SOURCE ${first_source_file} APPEND PROPERTY
133 # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file})
Nico Weberc27118d2013-12-28 23:31:44 +0000134
135 set_property(DIRECTORY APPEND
136 PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file})
137
138 add_dependencies(${target_name} ${target_name}_exports)
NAKAMURA Takumi679e7722014-02-21 14:17:29 +0000139
140 # Add dependency to *_exports later -- CMake issue 14747
141 list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports)
142 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
Nico Weberc27118d2013-12-28 23:31:44 +0000143endfunction(add_llvm_symbol_exports)
144
Rafael Espindola19c39ee2014-12-04 17:54:35 +0000145if(NOT WIN32 AND NOT APPLE)
NAKAMURA Takumi8b1578f2015-01-06 09:44:29 +0000146 execute_process(
147 COMMAND ${CMAKE_C_COMPILER} -Wl,--version
148 OUTPUT_VARIABLE stdout
NAKAMURA Takumi2f3e3dd2015-01-06 09:44:44 +0000149 ERROR_QUIET
NAKAMURA Takumi8b1578f2015-01-06 09:44:29 +0000150 )
Rafael Espindola19c39ee2014-12-04 17:54:35 +0000151 if("${stdout}" MATCHES "GNU gold")
152 set(LLVM_LINKER_IS_GOLD ON)
153 endif()
154endif()
155
Rafael Espindola8cb78762014-11-02 12:14:22 +0000156function(add_link_opts target_name)
157 # Pass -O3 to the linker. This enabled different optimizations on different
158 # linkers.
159 if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32))
160 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
161 LINK_FLAGS " -Wl,-O3")
162 endif()
163
Rafael Espindola19c39ee2014-12-04 17:54:35 +0000164 if(LLVM_LINKER_IS_GOLD)
165 # With gold gc-sections is always safe.
166 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
Rafael Espindola9c971f92014-12-12 14:28:19 +0000167 LINK_FLAGS " -Wl,--gc-sections")
168 # Note that there is a bug with -Wl,--icf=safe so it is not safe
169 # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704.
Rafael Espindola19c39ee2014-12-04 17:54:35 +0000170 endif()
171
NAKAMURA Takumi748627c2014-10-20 12:12:21 +0000172 if(NOT LLVM_NO_DEAD_STRIP)
173 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Rafael Espindolac71e0052014-10-20 21:37:38 +0000174 # ld64's implementation of -dead_strip breaks tools that use plugins.
Nico Weber62588e12013-12-30 03:36:05 +0000175 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
176 LINK_FLAGS " -Wl,-dead_strip")
Rafael Espindola19c39ee2014-12-04 17:54:35 +0000177 elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)
NAKAMURA Takumi748627c2014-10-20 12:12:21 +0000178 # Object files are compiled with -ffunction-data-sections.
Rafael Espindolac71e0052014-10-20 21:37:38 +0000179 # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
180 # tools that use plugins. Always pass --gc-sections once we require
181 # a newer linker.
NAKAMURA Takumi748627c2014-10-20 12:12:21 +0000182 set_property(TARGET ${target_name} APPEND_STRING PROPERTY
183 LINK_FLAGS " -Wl,--gc-sections")
Nico Weber62588e12013-12-30 03:36:05 +0000184 endif()
185 endif()
Rafael Espindola8cb78762014-11-02 12:14:22 +0000186endfunction(add_link_opts)
Nico Weber62588e12013-12-30 03:36:05 +0000187
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000188# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
189# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more,
190# or a certain builder, for eaxample, msbuild.exe, would be confused.
191function(set_output_directory target bindir libdir)
NAKAMURA Takumi38d45a22014-07-04 04:23:15 +0000192 # Do nothing if *_OUTPUT_INTDIR is empty.
193 if("${bindir}" STREQUAL "")
194 return()
195 endif()
196
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000197 # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
198 # It affects output of add_library(MODULE).
199 if(WIN32 OR CYGWIN)
200 # DLL platform
201 set(moddir ${bindir})
202 else()
203 set(moddir ${libdir})
204 endif()
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000205 if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
206 foreach(build_mode ${CMAKE_CONFIGURATION_TYPES})
207 string(TOUPPER "${build_mode}" CONFIG_SUFFIX)
208 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir})
209 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir})
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000210 string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir})
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000211 set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi})
212 set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li})
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000213 set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000214 endforeach()
215 else()
216 set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir})
217 set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir})
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000218 set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir})
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000219 endif()
220endfunction()
221
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000222# llvm_add_library(name sources...
NAKAMURA Takumi487f3872014-02-13 11:25:17 +0000223# SHARED;STATIC
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000224# STATIC by default w/o BUILD_SHARED_LIBS.
225# SHARED by default w/ BUILD_SHARED_LIBS.
NAKAMURA Takumi487f3872014-02-13 11:25:17 +0000226# MODULE
227# Target ${name} might not be created on unsupported platforms.
228# Check with "if(TARGET ${name})".
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000229# OUTPUT_NAME name
230# Corresponds to OUTPUT_NAME in target properties.
231# DEPENDS targets...
232# Same semantics as add_dependencies().
233# LINK_COMPONENTS components...
234# Same as the variable LLVM_LINK_COMPONENTS.
235# LINK_LIBS lib_targets...
236# Same semantics as target_link_libraries().
NAKAMURA Takumidea00df2014-02-13 01:00:52 +0000237# ADDITIONAL_HEADERS
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000238# May specify header files for IDE generators.
239# )
240function(llvm_add_library name)
241 cmake_parse_arguments(ARG
242 "MODULE;SHARED;STATIC"
243 "OUTPUT_NAME"
NAKAMURA Takumie3408ab2014-02-21 14:17:17 +0000244 "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000245 ${ARGN})
246 list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
NAKAMURA Takumidea00df2014-02-13 01:00:52 +0000247 if(ARG_ADDITIONAL_HEADERS)
248 # Pass through ADDITIONAL_HEADERS.
249 set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
250 endif()
NAKAMURA Takumie3408ab2014-02-21 14:17:17 +0000251 if(ARG_OBJLIBS)
252 set(ALL_FILES ${ARG_OBJLIBS})
253 else()
254 llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS})
255 endif()
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000256
257 if(ARG_MODULE)
258 if(ARG_SHARED OR ARG_STATIC)
259 message(WARNING "MODULE with SHARED|STATIC doesn't make sense.")
260 endif()
NAKAMURA Takumi8d7a1732014-07-04 04:45:40 +0000261 if(NOT LLVM_ENABLE_PLUGINS)
NAKAMURA Takumi487f3872014-02-13 11:25:17 +0000262 message(STATUS "${name} ignored -- Loadable modules not supported on this platform.")
263 return()
264 endif()
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000265 else()
266 if(BUILD_SHARED_LIBS AND NOT ARG_STATIC)
267 set(ARG_SHARED TRUE)
268 endif()
269 if(NOT ARG_SHARED)
270 set(ARG_STATIC TRUE)
271 endif()
272 endif()
273
NAKAMURA Takumie3408ab2014-02-21 14:17:17 +0000274 # Generate objlib
275 if(ARG_SHARED AND ARG_STATIC)
276 # Generate an obj library for both targets.
277 set(obj_name "obj.${name}")
278 add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL
279 ${ALL_FILES}
280 )
281 llvm_update_compile_flags(${obj_name})
282 set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>")
283
NAKAMURA Takumi679e7722014-02-21 14:17:29 +0000284 # Do add_dependencies(obj) later due to CMake issue 14747.
285 list(APPEND objlibs ${obj_name})
286
NAKAMURA Takumie3408ab2014-02-21 14:17:17 +0000287 set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
288 endif()
289
290 if(ARG_SHARED AND ARG_STATIC)
291 # static
292 set(name_static "${name}_static")
293 if(ARG_OUTPUT_NAME)
NAKAMURA Takumib47a2c02014-02-28 00:28:13 +0000294 set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}")
NAKAMURA Takumie3408ab2014-02-21 14:17:17 +0000295 endif()
296 # DEPENDS has been appended to LLVM_COMMON_LIBS.
297 llvm_add_library(${name_static} STATIC
298 ${output_name}
299 OBJLIBS ${ALL_FILES} # objlib
300 LINK_LIBS ${ARG_LINK_LIBS}
301 LINK_COMPONENTS ${ARG_LINK_COMPONENTS}
302 )
303 # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY.
304 set(ARG_STATIC)
305 endif()
306
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000307 if(ARG_MODULE)
308 add_library(${name} MODULE ${ALL_FILES})
309 elseif(ARG_SHARED)
310 add_library(${name} SHARED ${ALL_FILES})
311 else()
312 add_library(${name} STATIC ${ALL_FILES})
313 endif()
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000314 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
NAKAMURA Takumib524c222014-01-28 11:40:04 +0000315 llvm_update_compile_flags(${name})
Rafael Espindola8cb78762014-11-02 12:14:22 +0000316 add_link_opts( ${name} )
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000317 if(ARG_OUTPUT_NAME)
318 set_target_properties(${name}
319 PROPERTIES
320 OUTPUT_NAME ${ARG_OUTPUT_NAME}
321 )
322 endif()
Oscar Fuentesffe32e12010-10-14 15:54:41 +0000323
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000324 if(ARG_MODULE)
NAKAMURA Takumie72e2e92014-02-13 11:19:21 +0000325 set_target_properties(${name} PROPERTIES
326 PREFIX ""
327 SUFFIX ${LLVM_PLUGIN_EXT}
328 )
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000329 endif()
330
331 if(ARG_SHARED)
NAKAMURA Takumi543105f2014-04-10 15:47:04 +0000332 if(WIN32)
333 set_target_properties(${name} PROPERTIES
334 PREFIX ""
335 )
336 endif()
Chris Bienemana8a05962015-02-18 18:52:06 +0000337
338 set_target_properties(${name}
339 PROPERTIES
340 SOVERSION ${LLVM_VERSION_MAJOR}
341 VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000342 endif()
Oscar Fuentesffe32e12010-10-14 15:54:41 +0000343
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000344 if(ARG_MODULE OR ARG_SHARED)
Richard Smith2b91a7f2014-09-26 22:40:15 +0000345 # Do not add -Dname_EXPORTS to the command-line when building files in this
346 # target. Doing so is actively harmful for the modules build because it
347 # creates extra module variants, and not useful because we don't use these
348 # macros.
349 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
350
Nico Weber06473f82013-12-29 05:39:01 +0000351 if (LLVM_EXPORTED_SYMBOL_FILE)
352 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
353 endif()
Nico Weberc27118d2013-12-28 23:31:44 +0000354 endif()
355
NAKAMURA Takumia39b6122014-02-26 11:58:01 +0000356 # Add the explicit dependency information for this library.
357 #
358 # It would be nice to verify that we have the dependencies for this library
359 # name, but using get_property(... SET) doesn't suffice to determine if a
360 # property has been set to an empty value.
361 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
362
363 llvm_map_components_to_libnames(llvm_libs
364 ${ARG_LINK_COMPONENTS}
365 ${LLVM_LINK_COMPONENTS}
366 )
367
368 if(CMAKE_VERSION VERSION_LESS 2.8.12)
369 # Link libs w/o keywords, assuming PUBLIC.
370 target_link_libraries(${name}
371 ${ARG_LINK_LIBS}
372 ${lib_deps}
373 ${llvm_libs}
374 )
375 elseif(ARG_STATIC)
376 target_link_libraries(${name} INTERFACE
377 ${ARG_LINK_LIBS}
378 ${lib_deps}
379 ${llvm_libs}
380 )
NAKAMURA Takumi955d27a2014-02-26 06:53:16 +0000381 else()
Rafael Espindolaf9dcf902014-11-07 15:33:56 +0000382 # We can use PRIVATE since SO knows its dependent libs.
NAKAMURA Takumia39b6122014-02-26 11:58:01 +0000383 target_link_libraries(${name} PRIVATE
384 ${ARG_LINK_LIBS}
385 ${lib_deps}
386 ${llvm_libs}
387 )
NAKAMURA Takumi955d27a2014-02-26 06:53:16 +0000388 endif()
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000389
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000390 if(LLVM_COMMON_DEPENDS)
391 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
NAKAMURA Takumi679e7722014-02-21 14:17:29 +0000392 # Add dependencies also to objlibs.
393 # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user.
394 foreach(objlib ${objlibs})
NAKAMURA Takumi679e7722014-02-21 14:17:29 +0000395 add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS})
396 endforeach()
NAKAMURA Takumie7038df2014-02-10 09:05:11 +0000397 endif()
398endfunction()
399
400macro(add_llvm_library name)
401 if( BUILD_SHARED_LIBS )
402 llvm_add_library(${name} SHARED ${ARGN})
403 else()
404 llvm_add_library(${name} ${ARGN})
405 endif()
406 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
407
Nick Lewycky61aed872011-04-29 02:12:06 +0000408 if( EXCLUDE_FROM_ALL )
409 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
410 else()
Hans Wennborg16546272013-08-24 00:20:36 +0000411 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
412 install(TARGETS ${name}
NAKAMURA Takumief976072014-02-09 16:36:03 +0000413 EXPORT LLVMExports
NAKAMURA Takumi506c0dc2014-07-11 14:36:28 +0000414 RUNTIME DESTINATION bin
Hans Wennborg16546272013-08-24 00:20:36 +0000415 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
Chris Bieneman0d9289d2015-02-18 19:25:47 +0000416 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
417 COMPONENT ${name})
418
419 if (NOT CMAKE_CONFIGURATION_TYPES)
420 add_custom_target(install-${name}
421 DEPENDS ${name}
422 COMMAND "${CMAKE_COMMAND}"
423 -DCMAKE_INSTALL_COMPONENT=${name}
424 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
425 endif()
Hans Wennborg16546272013-08-24 00:20:36 +0000426 endif()
NAKAMURA Takumi8faf6602014-02-09 16:36:16 +0000427 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
Nick Lewycky61aed872011-04-29 02:12:06 +0000428 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000429 set_target_properties(${name} PROPERTIES FOLDER "Libraries")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000430endmacro(add_llvm_library name)
431
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000432macro(add_llvm_loadable_module name)
NAKAMURA Takumi487f3872014-02-13 11:25:17 +0000433 llvm_add_library(${name} MODULE ${ARGN})
434 if(NOT TARGET ${name})
NAKAMURA Takumia8c1c3f2010-12-10 02:15:36 +0000435 # Add empty "phony" target
436 add_custom_target(${name})
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000437 else()
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000438 if( EXCLUDE_FROM_ALL )
Nick Lewycky61aed872011-04-29 02:12:06 +0000439 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000440 else()
Hans Wennborg16546272013-08-24 00:20:36 +0000441 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000442 if(WIN32 OR CYGWIN)
443 # DLL platform
444 set(dlldir "bin")
445 else()
446 set(dlldir "lib${LLVM_LIBDIR_SUFFIX}")
447 endif()
Hans Wennborg16546272013-08-24 00:20:36 +0000448 install(TARGETS ${name}
NAKAMURA Takumief976072014-02-09 16:36:03 +0000449 EXPORT LLVMExports
NAKAMURA Takumi44f64ea2014-07-13 13:33:26 +0000450 LIBRARY DESTINATION ${dlldir}
Hans Wennborg16546272013-08-24 00:20:36 +0000451 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
452 endif()
NAKAMURA Takumi8faf6602014-02-09 16:36:16 +0000453 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
Oscar Fuentes638aaec2011-04-26 14:55:27 +0000454 endif()
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000455 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000456
457 set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
Oscar Fuentesbbc10672009-11-10 02:45:37 +0000458endmacro(add_llvm_loadable_module name)
459
460
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000461macro(add_llvm_executable name)
Oscar Fuentes2c10b222008-11-15 02:08:08 +0000462 llvm_process_sources( ALL_FILES ${ARGN} )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000463 if( EXCLUDE_FROM_ALL )
464 add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
465 else()
466 add_executable(${name} ${ALL_FILES})
467 endif()
NAKAMURA Takumib524c222014-01-28 11:40:04 +0000468 llvm_update_compile_flags(${name})
Rafael Espindola8cb78762014-11-02 12:14:22 +0000469 add_link_opts( ${name} )
Nico Weberc27118d2013-12-28 23:31:44 +0000470
Richard Smith2b91a7f2014-09-26 22:40:15 +0000471 # Do not add -Dname_EXPORTS to the command-line when building files in this
472 # target. Doing so is actively harmful for the modules build because it
473 # creates extra module variants, and not useful because we don't use these
474 # macros.
475 set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" )
476
Nico Weberc27118d2013-12-28 23:31:44 +0000477 if (LLVM_EXPORTED_SYMBOL_FILE)
478 add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
479 endif(LLVM_EXPORTED_SYMBOL_FILE)
480
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000481 set(EXCLUDE_FROM_ALL OFF)
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000482 set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
Oscar Fuentes978e5282011-03-29 20:51:08 +0000483 llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
Oscar Fuentes3fca0e82009-08-14 04:38:57 +0000484 if( LLVM_COMMON_DEPENDS )
485 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
486 endif( LLVM_COMMON_DEPENDS )
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000487endmacro(add_llvm_executable name)
488
489
Hans Wennborg16546272013-08-24 00:20:36 +0000490set (LLVM_TOOLCHAIN_TOOLS
491 llvm-ar
492 llvm-objdump
493 )
494
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000495macro(add_llvm_tool name)
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000496 if( NOT LLVM_BUILD_TOOLS )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000497 set(EXCLUDE_FROM_ALL ON)
498 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000499 add_llvm_executable(${name} ${ARGN})
Hans Wennborg16546272013-08-24 00:20:36 +0000500
501 list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL)
502 if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
503 if( LLVM_BUILD_TOOLS )
NAKAMURA Takumief976072014-02-09 16:36:03 +0000504 install(TARGETS ${name}
505 EXPORT LLVMExports
Chris Bieneman0d9289d2015-02-18 19:25:47 +0000506 RUNTIME DESTINATION bin
507 COMPONENT ${name})
508
509 if (NOT CMAKE_CONFIGURATION_TYPES)
510 add_custom_target(install-${name}
511 DEPENDS ${name}
512 COMMAND "${CMAKE_COMMAND}"
513 -DCMAKE_INSTALL_COMPONENT=${name}
514 -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
515 endif()
Hans Wennborg16546272013-08-24 00:20:36 +0000516 endif()
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000517 endif()
NAKAMURA Takumi8faf6602014-02-09 16:36:16 +0000518 if( LLVM_BUILD_TOOLS )
519 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
520 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000521 set_target_properties(${name} PROPERTIES FOLDER "Tools")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000522endmacro(add_llvm_tool name)
523
524
525macro(add_llvm_example name)
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000526 if( NOT LLVM_BUILD_EXAMPLES )
Oscar Fuentes0c2443a2009-11-23 00:21:43 +0000527 set(EXCLUDE_FROM_ALL ON)
528 endif()
Oscar Fuentes46d8a932010-09-25 20:25:25 +0000529 add_llvm_executable(${name} ${ARGN})
Oscar Fuentesdea579f2009-11-23 00:32:42 +0000530 if( LLVM_BUILD_EXAMPLES )
531 install(TARGETS ${name} RUNTIME DESTINATION examples)
532 endif()
Oscar Fuentes3145e922011-02-20 22:06:10 +0000533 set_target_properties(${name} PROPERTIES FOLDER "Examples")
Oscar Fuentesa229b3c2008-09-22 01:08:49 +0000534endmacro(add_llvm_example name)
Oscar Fuentescdc95492008-09-26 04:40:32 +0000535
536
Oscar Fuentes3145e922011-02-20 22:06:10 +0000537macro(add_llvm_utility name)
538 add_llvm_executable(${name} ${ARGN})
539 set_target_properties(${name} PROPERTIES FOLDER "Utils")
540endmacro(add_llvm_utility name)
541
542
Oscar Fuentescdc95492008-09-26 04:40:32 +0000543macro(add_llvm_target target_name)
Oscar Fuentes4f0f3352011-07-25 20:17:01 +0000544 include_directories(BEFORE
545 ${CMAKE_CURRENT_BINARY_DIR}
546 ${CMAKE_CURRENT_SOURCE_DIR})
NAKAMURA Takumi45374cc2014-03-04 17:05:28 +0000547 add_llvm_library(LLVM${target_name} ${ARGN})
Oscar Fuentesba1186c2011-02-20 02:55:27 +0000548 set( CURRENT_LLVM_TARGET LLVM${target_name} )
Oscar Fuentescdc95492008-09-26 04:40:32 +0000549endmacro(add_llvm_target)
Michael J. Spencere734f542012-04-26 19:43:35 +0000550
551# Add external project that may want to be built as part of llvm such as Clang,
552# lld, and Polly. This adds two options. One for the source directory of the
553# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
Alp Toker171b0c32013-12-20 00:33:39 +0000554# enable or disable building it with everything else.
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000555# Additional parameter can be specified as the name of directory.
Michael J. Spencere734f542012-04-26 19:43:35 +0000556macro(add_llvm_external_project name)
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000557 set(add_llvm_external_dir "${ARGN}")
558 if("${add_llvm_external_dir}" STREQUAL "")
559 set(add_llvm_external_dir ${name})
560 endif()
Argyrios Kyrtzidis7eec9d02013-08-21 19:13:44 +0000561 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}")
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000562 string(REPLACE "-" "_" nameUNDERSCORE ${name})
563 string(TOUPPER ${nameUNDERSCORE} nameUPPER)
564 set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}"
Michael J. Spencere734f542012-04-26 19:43:35 +0000565 CACHE PATH "Path to ${name} source directory")
566 if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
567 AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
568 option(LLVM_EXTERNAL_${nameUPPER}_BUILD
569 "Whether to build ${name} as part of LLVM" ON)
570 if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
NAKAMURA Takumi700cd402012-10-05 14:10:17 +0000571 add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir})
Michael J. Spencere734f542012-04-26 19:43:35 +0000572 endif()
573 endif()
574endmacro(add_llvm_external_project)
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000575
Argyrios Kyrtzidis7eec9d02013-08-21 19:13:44 +0000576macro(add_llvm_tool_subdirectory name)
577 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
578 add_subdirectory(${name})
579endmacro(add_llvm_tool_subdirectory)
580
581macro(ignore_llvm_tool_subdirectory name)
582 list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
583endmacro(ignore_llvm_tool_subdirectory)
584
585function(add_llvm_implicit_external_projects)
586 set(list_of_implicit_subdirs "")
587 file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
588 foreach(dir ${sub-dirs})
589 if(IS_DIRECTORY "${dir}")
590 list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore)
591 if( tool_subdir_ignore EQUAL -1
592 AND EXISTS "${dir}/CMakeLists.txt")
593 get_filename_component(fn "${dir}" NAME)
594 list(APPEND list_of_implicit_subdirs "${fn}")
595 endif()
596 endif()
597 endforeach()
598
599 foreach(external_proj ${list_of_implicit_subdirs})
600 add_llvm_external_project("${external_proj}")
601 endforeach()
602endfunction(add_llvm_implicit_external_projects)
603
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000604# Generic support for adding a unittest.
Chandler Carruth94d02512012-06-21 09:51:26 +0000605function(add_unittest test_suite test_name)
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000606 if( NOT LLVM_BUILD_TESTS )
607 set(EXCLUDE_FROM_ALL ON)
608 endif()
609
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +0000610 include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
611 if (NOT LLVM_ENABLE_THREADS)
612 list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
613 endif ()
614
615 if (SUPPORTS_NO_VARIADIC_MACROS_FLAG)
NAKAMURA Takumi13961cb2014-01-30 22:55:25 +0000616 list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros")
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +0000617 endif ()
618
NAKAMURA Takumia679f432014-01-28 09:44:06 +0000619 set(LLVM_REQUIRES_RTTI OFF)
NAKAMURA Takumie42fd0d2014-01-07 10:24:14 +0000620
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000621 add_llvm_executable(${test_name} ${ARGN})
NAKAMURA Takumibaa9f532013-12-30 06:48:30 +0000622 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
623 set_output_directory(${test_name} ${outdir} ${outdir})
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000624 target_link_libraries(${test_name}
625 gtest
626 gtest_main
627 LLVMSupport # gtest needs it for raw_ostream.
628 )
629
630 add_dependencies(${test_suite} ${test_name})
631 get_target_property(test_suite_folder ${test_suite} FOLDER)
632 if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
633 set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}")
634 endif ()
Chandler Carrutha5d42f82012-06-21 05:16:58 +0000635endfunction()
Chandler Carruth3511dd32012-06-28 06:36:24 +0000636
Peter Collingbournea4f0bd72014-11-27 00:15:21 +0000637function(llvm_add_go_executable binary pkgpath)
638 cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
639
640 if(LLVM_BINDINGS MATCHES "go")
641 # FIXME: This should depend only on the libraries Go needs.
642 get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
643 set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
644 set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
645 set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
Chandler Carruthcab512d2014-12-29 22:50:30 +0000646 set(cppflags "")
647 get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
648 foreach(d ${include_dirs})
649 set(cppflags "${cppflags} -I${d}")
650 endforeach(d)
Peter Collingbournea4f0bd72014-11-27 00:15:21 +0000651 set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
652 add_custom_command(OUTPUT ${binpath}
Chandler Carruthcab512d2014-12-29 22:50:30 +0000653 COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
Peter Collingbournea4f0bd72014-11-27 00:15:21 +0000654 ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
655 DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
656 ${llvmlibs} ${ARG_DEPENDS}
657 COMMENT "Building Go executable ${binary}"
658 VERBATIM)
659 if (ARG_ALL)
660 add_custom_target(${binary} ALL DEPENDS ${binpath})
661 else()
662 add_custom_target(${binary} DEPENDS ${binpath})
663 endif()
664 endif()
665endfunction()
666
Chandler Carruth3511dd32012-06-28 06:36:24 +0000667# This function provides an automatic way to 'configure'-like generate a file
Alp Toker171b0c32013-12-20 00:33:39 +0000668# based on a set of common and custom variables, specifically targeting the
Chandler Carruth3511dd32012-06-28 06:36:24 +0000669# variables needed for the 'lit.site.cfg' files. This function bundles the
670# common variables that any Lit instance is likely to need, and custom
671# variables can be passed in.
672function(configure_lit_site_cfg input output)
673 foreach(c ${LLVM_TARGETS_TO_BUILD})
674 set(TARGETS_BUILT "${TARGETS_BUILT} ${c}")
675 endforeach(c)
676 set(TARGETS_TO_BUILD ${TARGETS_BUILT})
677
678 set(SHLIBEXT "${LTDL_SHLIB_EXT}")
Chandler Carruth3511dd32012-06-28 06:36:24 +0000679
Chandler Carruth3511dd32012-06-28 06:36:24 +0000680 # Configuration-time: See Unit/lit.site.cfg.in
NAKAMURA Takumi0dc10d52013-12-04 11:15:17 +0000681 if (CMAKE_CFG_INTDIR STREQUAL ".")
682 set(LLVM_BUILD_MODE ".")
683 else ()
684 set(LLVM_BUILD_MODE "%(build_mode)s")
685 endif ()
Chandler Carruth3511dd32012-06-28 06:36:24 +0000686
NAKAMURA Takumi3c6f5cd2014-01-26 06:18:56 +0000687 # They below might not be the build tree but provided binary tree.
Chandler Carruth3511dd32012-06-28 06:36:24 +0000688 set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
689 set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR})
NAKAMURA Takumice78b802014-01-19 12:52:10 +0000690 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
691 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR})
NAKAMURA Takumi3c6f5cd2014-01-26 06:18:56 +0000692
693 # SHLIBDIR points the build tree.
NAKAMURA Takumi6c5fbbc2014-07-04 04:23:26 +0000694 string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}")
NAKAMURA Takumi3c6f5cd2014-01-26 06:18:56 +0000695
Chandler Carruth3511dd32012-06-28 06:36:24 +0000696 set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
NAKAMURA Takumi8d7a1732014-07-04 04:45:40 +0000697 # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for
698 # plugins. We may rename it.
699 if(LLVM_ENABLE_PLUGINS)
700 set(ENABLE_SHARED "1")
701 else()
702 set(ENABLE_SHARED "0")
703 endif()
Chandler Carruth3511dd32012-06-28 06:36:24 +0000704
705 if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE)
706 set(ENABLE_ASSERTIONS "1")
707 else()
708 set(ENABLE_ASSERTIONS "0")
709 endif()
710
Kuba Breckaa62bbcc2015-01-24 01:42:44 +0000711 set(HOST_OS ${CMAKE_SYSTEM_NAME})
Tim Northoverbfe84682013-02-14 16:49:32 +0000712 set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR})
Chandler Carruth3511dd32012-06-28 06:36:24 +0000713
Peter Collingbournece800842014-10-17 18:32:36 +0000714 set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
715 set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
Chandler Carruth97192422014-10-21 00:36:28 +0000716 set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
Peter Collingbourne82e3e372014-10-16 22:48:02 +0000717
Chandler Carruth3511dd32012-06-28 06:36:24 +0000718 configure_file(${input} ${output} @ONLY)
719endfunction()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000720
721# A raw function to create a lit target. This is used to implement the testuite
722# management functions.
723function(add_lit_target target comment)
NAKAMURA Takumi69a89c72013-12-19 17:11:08 +0000724 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
Chandler Carruth69ce6652012-06-30 10:14:14 +0000725 set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}")
726 separate_arguments(LIT_ARGS)
NAKAMURA Takumi0dc10d52013-12-04 11:15:17 +0000727 if (NOT CMAKE_CFG_INTDIR STREQUAL ".")
728 list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR})
729 endif ()
Greg Fitzgerald962a3392014-05-21 16:44:03 +0000730 if (LLVM_MAIN_SRC_DIR)
731 set (LIT_COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
732 else()
733 find_program(LIT_COMMAND llvm-lit)
734 endif ()
735 list(APPEND LIT_COMMAND ${LIT_ARGS})
Chandler Carruth69ce6652012-06-30 10:14:14 +0000736 foreach(param ${ARG_PARAMS})
737 list(APPEND LIT_COMMAND --param ${param})
738 endforeach()
NAKAMURA Takumi04a664e2012-12-24 22:43:59 +0000739 if( ARG_DEPENDS )
740 add_custom_target(${target}
741 COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS}
742 COMMENT "${comment}"
Peter Collingbournea7fb5cf2014-11-17 22:16:15 +0000743 ${cmake_3_2_USES_TERMINAL}
NAKAMURA Takumi04a664e2012-12-24 22:43:59 +0000744 )
745 add_dependencies(${target} ${ARG_DEPENDS})
746 else()
747 add_custom_target(${target}
Nico Weberb42359d2013-12-29 00:11:20 +0000748 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
NAKAMURA Takumi04a664e2012-12-24 22:43:59 +0000749 message(STATUS "${target} does nothing.")
750 endif()
NAKAMURA Takumi03fc7302013-12-02 11:31:19 +0000751
752 # Tests should be excluded from "Build Solution".
753 set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
Chandler Carruth69ce6652012-06-30 10:14:14 +0000754endfunction()
755
756# A function to add a set of lit test suites to be driven through 'check-*' targets.
757function(add_lit_testsuite target comment)
758 parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN})
759
NAKAMURA Takumi54d22742012-10-10 13:32:55 +0000760 # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all.
761 if(NOT EXCLUDE_FROM_ALL)
762 # Register the testsuites, params and depends for the global check rule.
763 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS})
764 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS})
765 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS})
766 set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS})
767 endif()
Chandler Carruth69ce6652012-06-30 10:14:14 +0000768
769 # Produce a specific suffixed check rule.
770 add_lit_target(${target} ${comment}
771 ${ARG_DEFAULT_ARGS}
772 PARAMS ${ARG_PARAMS}
773 DEPENDS ${ARG_DEPENDS}
774 ARGS ${ARG_ARGS}
775 )
776endfunction()