Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1 | include(LLVMParseArguments) |
Oscar Fuentes | 751ea9d | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 2 | include(LLVMProcessSources) |
Oscar Fuentes | d8a6dd6 | 2011-04-05 17:02:48 +0000 | [diff] [blame] | 3 | include(LLVM-Config) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 4 | |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 5 | function(llvm_update_compile_flags name) |
NAKAMURA Takumi | b524c22 | 2014-01-28 11:40:04 +0000 | [diff] [blame] | 6 | get_property(sources TARGET ${name} PROPERTY SOURCES) |
| 7 | if("${sources}" MATCHES "\\.c(;|$)") |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 8 | set(update_src_props ON) |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 9 | endif() |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 10 | |
Dan Liew | a5bdc84 | 2014-07-22 15:41:18 +0000 | [diff] [blame] | 11 | # LLVM_REQUIRES_EH is an internal flag that individual |
| 12 | # targets can use to force EH |
Zachary Turner | 66bc908 | 2015-02-25 20:42:19 +0000 | [diff] [blame] | 13 | if((LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) AND NOT CLANG_CL) |
Dan Liew | a5bdc84 | 2014-07-22 15:41:18 +0000 | [diff] [blame] | 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 Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 18 | else() |
| 19 | if(LLVM_COMPILER_IS_GCC_COMPATIBLE) |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 20 | list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions") |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 21 | elseif(MSVC) |
| 22 | list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0) |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 23 | list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-") |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 24 | endif() |
Zachary Turner | 66bc908 | 2015-02-25 20:42:19 +0000 | [diff] [blame] | 25 | if (CLANG_CL) |
| 26 | # FIXME: Remove this once clang-cl supports SEH |
| 27 | list(APPEND LLVM_COMPILE_DEFINITIONS "GTEST_HAS_SEH=0") |
| 28 | endif() |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 29 | endif() |
| 30 | |
Dan Liew | a5bdc84 | 2014-07-22 15:41:18 +0000 | [diff] [blame] | 31 | # LLVM_REQUIRES_RTTI is an internal flag that individual |
| 32 | # targets can use to force RTTI |
| 33 | if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 34 | list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) |
| 35 | if (LLVM_COMPILER_IS_GCC_COMPATIBLE) |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 36 | list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti") |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 37 | elseif (MSVC) |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 38 | list(APPEND LLVM_COMPILE_FLAGS "/GR-") |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 39 | endif () |
| 40 | endif() |
| 41 | |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 42 | # Assume that; |
| 43 | # - LLVM_COMPILE_FLAGS is list. |
| 44 | # - PROPERTY COMPILE_FLAGS is string. |
| 45 | string(REPLACE ";" " " target_compile_flags "${LLVM_COMPILE_FLAGS}") |
| 46 | |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 47 | if(update_src_props) |
NAKAMURA Takumi | b524c22 | 2014-01-28 11:40:04 +0000 | [diff] [blame] | 48 | foreach(fn ${sources}) |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 49 | get_filename_component(suf ${fn} EXT) |
| 50 | if("${suf}" STREQUAL ".cpp") |
NAKAMURA Takumi | d40cdc9 | 2014-01-31 17:32:42 +0000 | [diff] [blame] | 51 | set_property(SOURCE ${fn} APPEND_STRING PROPERTY |
| 52 | COMPILE_FLAGS "${target_compile_flags}") |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 53 | endif() |
| 54 | endforeach() |
| 55 | else() |
| 56 | # Update target props, since all sources are C++. |
| 57 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 58 | COMPILE_FLAGS "${target_compile_flags}") |
| 59 | endif() |
| 60 | |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 61 | set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS}) |
| 62 | endfunction() |
| 63 | |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 64 | function(add_llvm_symbol_exports target_name export_file) |
| 65 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
NAKAMURA Takumi | bbd2aaa | 2013-12-29 16:15:26 +0000 | [diff] [blame] | 66 | set(native_export_file "${target_name}.exports") |
NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 67 | add_custom_command(OUTPUT ${native_export_file} |
| 68 | COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file} |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 69 | DEPENDS ${export_file} |
| 70 | VERBATIM |
| 71 | COMMENT "Creating export file for ${target_name}") |
| 72 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 73 | LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 74 | elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) |
| 75 | # Gold and BFD ld require a version script rather than a plain list. |
NAKAMURA Takumi | bbd2aaa | 2013-12-29 16:15:26 +0000 | [diff] [blame] | 76 | set(native_export_file "${target_name}.exports") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 77 | # FIXME: Don't write the "local:" line on OpenBSD. |
NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 78 | add_custom_command(OUTPUT ${native_export_file} |
| 79 | COMMAND echo "{" > ${native_export_file} |
| 80 | COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || : |
| 81 | COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file} |
| 82 | COMMAND echo " local: *;" >> ${native_export_file} |
| 83 | COMMAND echo "};" >> ${native_export_file} |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 84 | DEPENDS ${export_file} |
| 85 | VERBATIM |
| 86 | COMMENT "Creating export file for ${target_name}") |
| 87 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
Nico Weber | dc78dc9 | 2013-12-29 23:04:48 +0000 | [diff] [blame] | 88 | LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 89 | else() |
NAKAMURA Takumi | bbd2aaa | 2013-12-29 16:15:26 +0000 | [diff] [blame] | 90 | set(native_export_file "${target_name}.def") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 91 | |
Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 92 | set(CAT "cat") |
| 93 | set(export_file_nativeslashes ${export_file}) |
Yaron Keren | e654593 | 2015-05-19 12:59:23 +0000 | [diff] [blame] | 94 | if(WIN32 AND NOT CYGWIN AND NOT MSYS) |
Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 95 | set(CAT "type") |
| 96 | # Convert ${export_file} to native format (backslashes) for "type" |
| 97 | # Does not use file(TO_NATIVE_PATH) as it doesn't create a native |
| 98 | # path but a build-system specific format (see CMake bug |
| 99 | # http://public.kitware.com/Bug/print_bug_page.php?bug_id=5939 ) |
| 100 | string(REPLACE / \\ export_file_nativeslashes ${export_file}) |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 101 | endif() |
| 102 | |
NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 103 | add_custom_command(OUTPUT ${native_export_file} |
| 104 | COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > ${native_export_file} |
Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 105 | COMMAND ${CAT} ${export_file_nativeslashes} >> ${native_export_file} |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 106 | DEPENDS ${export_file} |
| 107 | VERBATIM |
| 108 | COMMENT "Creating export file for ${target_name}") |
Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 109 | set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
| 110 | if(MSVC) |
Reid Kleckner | ec6789b | 2015-04-22 16:23:00 +0000 | [diff] [blame] | 111 | set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"") |
NAKAMURA Takumi | 0a062bd | 2013-12-29 16:19:13 +0000 | [diff] [blame] | 112 | endif() |
Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 113 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 114 | LINK_FLAGS " ${export_file_linker_flag}") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 115 | endif() |
| 116 | |
| 117 | add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) |
NAKAMURA Takumi | 14f1f44 | 2014-01-27 17:39:38 +0000 | [diff] [blame] | 118 | set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 119 | |
| 120 | get_property(srcs TARGET ${target_name} PROPERTY SOURCES) |
| 121 | foreach(src ${srcs}) |
| 122 | get_filename_component(extension ${src} EXT) |
| 123 | if(extension STREQUAL ".cpp") |
| 124 | set(first_source_file ${src}) |
| 125 | break() |
| 126 | endif() |
| 127 | endforeach() |
| 128 | |
| 129 | # Force re-linking when the exports file changes. Actually, it |
| 130 | # forces recompilation of the source file. The LINK_DEPENDS target |
| 131 | # property only works for makefile-based generators. |
Quentin Colombet | cb2ae8d | 2014-01-16 06:43:55 +0000 | [diff] [blame] | 132 | # FIXME: This is not safe because this will create the same target |
| 133 | # ${native_export_file} in several different file: |
| 134 | # - One where we emitted ${target_name}_exports |
| 135 | # - One where we emitted the build command for the following object. |
| 136 | # set_property(SOURCE ${first_source_file} APPEND PROPERTY |
| 137 | # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}) |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 138 | |
| 139 | set_property(DIRECTORY APPEND |
| 140 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file}) |
| 141 | |
| 142 | add_dependencies(${target_name} ${target_name}_exports) |
NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 143 | |
| 144 | # Add dependency to *_exports later -- CMake issue 14747 |
| 145 | list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports) |
| 146 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 147 | endfunction(add_llvm_symbol_exports) |
| 148 | |
Rafael Espindola | 19c39ee | 2014-12-04 17:54:35 +0000 | [diff] [blame] | 149 | if(NOT WIN32 AND NOT APPLE) |
NAKAMURA Takumi | 8b1578f | 2015-01-06 09:44:29 +0000 | [diff] [blame] | 150 | execute_process( |
| 151 | COMMAND ${CMAKE_C_COMPILER} -Wl,--version |
| 152 | OUTPUT_VARIABLE stdout |
NAKAMURA Takumi | 2f3e3dd | 2015-01-06 09:44:44 +0000 | [diff] [blame] | 153 | ERROR_QUIET |
NAKAMURA Takumi | 8b1578f | 2015-01-06 09:44:29 +0000 | [diff] [blame] | 154 | ) |
Rafael Espindola | 19c39ee | 2014-12-04 17:54:35 +0000 | [diff] [blame] | 155 | if("${stdout}" MATCHES "GNU gold") |
| 156 | set(LLVM_LINKER_IS_GOLD ON) |
| 157 | endif() |
| 158 | endif() |
| 159 | |
Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 160 | function(add_link_opts target_name) |
Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 161 | # Don't use linker optimizations in debug builds since it slows down the |
| 162 | # linker in a context where the optimizations are not important. |
| 163 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 164 | |
Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 165 | # Pass -O3 to the linker. This enabled different optimizations on different |
| 166 | # linkers. |
| 167 | if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32)) |
Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 168 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 169 | LINK_FLAGS " -Wl,-O3") |
| 170 | endif() |
| 171 | |
| 172 | if(LLVM_LINKER_IS_GOLD) |
| 173 | # With gold gc-sections is always safe. |
NAKAMURA Takumi | 748627c | 2014-10-20 12:12:21 +0000 | [diff] [blame] | 174 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 175 | LINK_FLAGS " -Wl,--gc-sections") |
Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 176 | # Note that there is a bug with -Wl,--icf=safe so it is not safe |
| 177 | # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704. |
| 178 | endif() |
| 179 | |
| 180 | if(NOT LLVM_NO_DEAD_STRIP) |
| 181 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 182 | # ld64's implementation of -dead_strip breaks tools that use plugins. |
| 183 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 184 | LINK_FLAGS " -Wl,-dead_strip") |
| 185 | elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD) |
| 186 | # Object files are compiled with -ffunction-data-sections. |
| 187 | # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks |
| 188 | # tools that use plugins. Always pass --gc-sections once we require |
| 189 | # a newer linker. |
| 190 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 191 | LINK_FLAGS " -Wl,--gc-sections") |
| 192 | endif() |
Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 193 | endif() |
| 194 | endif() |
Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 195 | endfunction(add_link_opts) |
Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 196 | |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 197 | # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. |
| 198 | # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, |
| 199 | # or a certain builder, for eaxample, msbuild.exe, would be confused. |
| 200 | function(set_output_directory target bindir libdir) |
NAKAMURA Takumi | 38d45a2 | 2014-07-04 04:23:15 +0000 | [diff] [blame] | 201 | # Do nothing if *_OUTPUT_INTDIR is empty. |
| 202 | if("${bindir}" STREQUAL "") |
| 203 | return() |
| 204 | endif() |
| 205 | |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 206 | # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY. |
| 207 | # It affects output of add_library(MODULE). |
| 208 | if(WIN32 OR CYGWIN) |
| 209 | # DLL platform |
| 210 | set(moddir ${bindir}) |
| 211 | else() |
| 212 | set(moddir ${libdir}) |
| 213 | endif() |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 214 | if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") |
| 215 | foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) |
| 216 | string(TOUPPER "${build_mode}" CONFIG_SUFFIX) |
| 217 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir}) |
| 218 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir}) |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 219 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir}) |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 220 | set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) |
| 221 | set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 222 | set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 223 | endforeach() |
| 224 | else() |
| 225 | set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir}) |
| 226 | set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir}) |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 227 | set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir}) |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 228 | endif() |
| 229 | endfunction() |
| 230 | |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 231 | # If on Windows and building with MSVC, add the resource script containing the |
| 232 | # VERSIONINFO data to the project. This embeds version resource information |
| 233 | # into the output .exe or .dll. |
| 234 | # TODO: Enable for MinGW Windows builds too. |
| 235 | # |
| 236 | function(add_windows_version_resource_file OUT_VAR) |
| 237 | set(sources ${ARGN}) |
| 238 | if (MSVC) |
| 239 | set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc) |
NAKAMURA Takumi | ec782b4 | 2015-06-14 21:47:29 +0000 | [diff] [blame] | 240 | if(EXISTS ${resource_file}) |
| 241 | set(sources ${sources} ${resource_file}) |
| 242 | source_group("Resource Files" ${resource_file}) |
| 243 | set(windows_resource_file ${resource_file} PARENT_SCOPE) |
| 244 | endif() |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 245 | endif(MSVC) |
| 246 | |
| 247 | set(${OUT_VAR} ${sources} PARENT_SCOPE) |
| 248 | endfunction(add_windows_version_resource_file) |
| 249 | |
| 250 | # set_windows_version_resource_properties(name resource_file... |
| 251 | # VERSION_MAJOR int |
| 252 | # Optional major version number (defaults to LLVM_VERSION_MAJOR) |
| 253 | # VERSION_MINOR int |
| 254 | # Optional minor version number (defaults to LLVM_VERSION_MINOR) |
| 255 | # VERSION_PATCHLEVEL int |
| 256 | # Optional patchlevel version number (defaults to LLVM_VERSION_PATCH) |
| 257 | # VERSION_STRING |
| 258 | # Optional version string (defaults to PACKAGE_VERSION) |
| 259 | # PRODUCT_NAME |
| 260 | # Optional product name string (defaults to "LLVM") |
| 261 | # ) |
| 262 | function(set_windows_version_resource_properties name resource_file) |
| 263 | cmake_parse_arguments(ARG |
| 264 | "" |
| 265 | "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME" |
| 266 | "" |
| 267 | ${ARGN}) |
| 268 | |
| 269 | if (NOT DEFINED ARG_VERSION_MAJOR) |
| 270 | set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 271 | endif() |
| 272 | |
| 273 | if (NOT DEFINED ARG_VERSION_MINOR) |
| 274 | set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 275 | endif() |
| 276 | |
| 277 | if (NOT DEFINED ARG_VERSION_PATCHLEVEL) |
| 278 | set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) |
| 279 | endif() |
| 280 | |
| 281 | if (NOT DEFINED ARG_VERSION_STRING) |
| 282 | set(ARG_VERSION_STRING ${PACKAGE_VERSION}) |
| 283 | endif() |
| 284 | |
| 285 | if (NOT DEFINED ARG_PRODUCT_NAME) |
| 286 | set(ARG_PRODUCT_NAME "LLVM") |
| 287 | endif() |
| 288 | |
| 289 | set_property(SOURCE ${resource_file} |
| 290 | PROPERTY COMPILE_DEFINITIONS |
| 291 | "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}" |
| 292 | "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}" |
| 293 | "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}" |
| 294 | "RC_VERSION_FIELD_4=0" |
| 295 | "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\"" |
| 296 | "RC_INTERNAL_NAME=\"${name}\"" |
| 297 | "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\"" |
| 298 | "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"") |
| 299 | endfunction(set_windows_version_resource_properties) |
| 300 | |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 301 | # llvm_add_library(name sources... |
NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 302 | # SHARED;STATIC |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 303 | # STATIC by default w/o BUILD_SHARED_LIBS. |
| 304 | # SHARED by default w/ BUILD_SHARED_LIBS. |
NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 305 | # MODULE |
| 306 | # Target ${name} might not be created on unsupported platforms. |
| 307 | # Check with "if(TARGET ${name})". |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 308 | # OUTPUT_NAME name |
| 309 | # Corresponds to OUTPUT_NAME in target properties. |
| 310 | # DEPENDS targets... |
| 311 | # Same semantics as add_dependencies(). |
| 312 | # LINK_COMPONENTS components... |
| 313 | # Same as the variable LLVM_LINK_COMPONENTS. |
| 314 | # LINK_LIBS lib_targets... |
| 315 | # Same semantics as target_link_libraries(). |
NAKAMURA Takumi | dea00df | 2014-02-13 01:00:52 +0000 | [diff] [blame] | 316 | # ADDITIONAL_HEADERS |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 317 | # May specify header files for IDE generators. |
| 318 | # ) |
| 319 | function(llvm_add_library name) |
| 320 | cmake_parse_arguments(ARG |
| 321 | "MODULE;SHARED;STATIC" |
| 322 | "OUTPUT_NAME" |
NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 323 | "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 324 | ${ARGN}) |
| 325 | list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) |
NAKAMURA Takumi | dea00df | 2014-02-13 01:00:52 +0000 | [diff] [blame] | 326 | if(ARG_ADDITIONAL_HEADERS) |
| 327 | # Pass through ADDITIONAL_HEADERS. |
| 328 | set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS}) |
| 329 | endif() |
NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 330 | if(ARG_OBJLIBS) |
| 331 | set(ALL_FILES ${ARG_OBJLIBS}) |
| 332 | else() |
| 333 | llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) |
| 334 | endif() |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 335 | |
| 336 | if(ARG_MODULE) |
| 337 | if(ARG_SHARED OR ARG_STATIC) |
| 338 | message(WARNING "MODULE with SHARED|STATIC doesn't make sense.") |
| 339 | endif() |
NAKAMURA Takumi | 8d7a173 | 2014-07-04 04:45:40 +0000 | [diff] [blame] | 340 | if(NOT LLVM_ENABLE_PLUGINS) |
NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 341 | message(STATUS "${name} ignored -- Loadable modules not supported on this platform.") |
| 342 | return() |
| 343 | endif() |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 344 | else() |
| 345 | if(BUILD_SHARED_LIBS AND NOT ARG_STATIC) |
| 346 | set(ARG_SHARED TRUE) |
| 347 | endif() |
| 348 | if(NOT ARG_SHARED) |
| 349 | set(ARG_STATIC TRUE) |
| 350 | endif() |
| 351 | endif() |
| 352 | |
NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 353 | # Generate objlib |
| 354 | if(ARG_SHARED AND ARG_STATIC) |
| 355 | # Generate an obj library for both targets. |
| 356 | set(obj_name "obj.${name}") |
| 357 | add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL |
| 358 | ${ALL_FILES} |
| 359 | ) |
| 360 | llvm_update_compile_flags(${obj_name}) |
| 361 | set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>") |
| 362 | |
NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 363 | # Do add_dependencies(obj) later due to CMake issue 14747. |
| 364 | list(APPEND objlibs ${obj_name}) |
| 365 | |
NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 366 | set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") |
| 367 | endif() |
| 368 | |
| 369 | if(ARG_SHARED AND ARG_STATIC) |
| 370 | # static |
| 371 | set(name_static "${name}_static") |
| 372 | if(ARG_OUTPUT_NAME) |
NAKAMURA Takumi | b47a2c0 | 2014-02-28 00:28:13 +0000 | [diff] [blame] | 373 | set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}") |
NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 374 | endif() |
| 375 | # DEPENDS has been appended to LLVM_COMMON_LIBS. |
| 376 | llvm_add_library(${name_static} STATIC |
| 377 | ${output_name} |
| 378 | OBJLIBS ${ALL_FILES} # objlib |
| 379 | LINK_LIBS ${ARG_LINK_LIBS} |
| 380 | LINK_COMPONENTS ${ARG_LINK_COMPONENTS} |
| 381 | ) |
| 382 | # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY. |
| 383 | set(ARG_STATIC) |
| 384 | endif() |
| 385 | |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 386 | if(ARG_MODULE) |
| 387 | add_library(${name} MODULE ${ALL_FILES}) |
| 388 | elseif(ARG_SHARED) |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 389 | add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 390 | add_library(${name} SHARED ${ALL_FILES}) |
| 391 | else() |
| 392 | add_library(${name} STATIC ${ALL_FILES}) |
| 393 | endif() |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 394 | |
| 395 | if(DEFINED windows_resource_file) |
| 396 | set_windows_version_resource_properties(${name} ${windows_resource_file}) |
| 397 | set(windows_resource_file ${windows_resource_file} PARENT_SCOPE) |
| 398 | endif() |
| 399 | |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 400 | set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
NAKAMURA Takumi | b524c22 | 2014-01-28 11:40:04 +0000 | [diff] [blame] | 401 | llvm_update_compile_flags(${name}) |
Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 402 | add_link_opts( ${name} ) |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 403 | if(ARG_OUTPUT_NAME) |
| 404 | set_target_properties(${name} |
| 405 | PROPERTIES |
| 406 | OUTPUT_NAME ${ARG_OUTPUT_NAME} |
| 407 | ) |
| 408 | endif() |
Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 409 | |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 410 | if(ARG_MODULE) |
NAKAMURA Takumi | e72e2e9 | 2014-02-13 11:19:21 +0000 | [diff] [blame] | 411 | set_target_properties(${name} PROPERTIES |
| 412 | PREFIX "" |
| 413 | SUFFIX ${LLVM_PLUGIN_EXT} |
| 414 | ) |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 415 | endif() |
| 416 | |
| 417 | if(ARG_SHARED) |
NAKAMURA Takumi | 543105f | 2014-04-10 15:47:04 +0000 | [diff] [blame] | 418 | if(WIN32) |
| 419 | set_target_properties(${name} PROPERTIES |
| 420 | PREFIX "" |
| 421 | ) |
| 422 | endif() |
Reid Kleckner | 2e3d1e0 | 2015-02-27 18:22:46 +0000 | [diff] [blame] | 423 | |
Chris Bieneman | a8a0596 | 2015-02-18 18:52:06 +0000 | [diff] [blame] | 424 | set_target_properties(${name} |
| 425 | PROPERTIES |
Chris Bieneman | bf2e90a | 2015-03-02 17:50:13 +0000 | [diff] [blame] | 426 | SOVERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR} |
Chris Bieneman | a8a0596 | 2015-02-18 18:52:06 +0000 | [diff] [blame] | 427 | VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}) |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 428 | endif() |
Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 429 | |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 430 | if(ARG_MODULE OR ARG_SHARED) |
Richard Smith | 2b91a7f | 2014-09-26 22:40:15 +0000 | [diff] [blame] | 431 | # Do not add -Dname_EXPORTS to the command-line when building files in this |
| 432 | # target. Doing so is actively harmful for the modules build because it |
| 433 | # creates extra module variants, and not useful because we don't use these |
| 434 | # macros. |
| 435 | set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) |
| 436 | |
Nico Weber | 06473f8 | 2013-12-29 05:39:01 +0000 | [diff] [blame] | 437 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 438 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 439 | endif() |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 440 | endif() |
| 441 | |
NAKAMURA Takumi | a39b612 | 2014-02-26 11:58:01 +0000 | [diff] [blame] | 442 | # Add the explicit dependency information for this library. |
| 443 | # |
| 444 | # It would be nice to verify that we have the dependencies for this library |
| 445 | # name, but using get_property(... SET) doesn't suffice to determine if a |
| 446 | # property has been set to an empty value. |
| 447 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) |
| 448 | |
| 449 | llvm_map_components_to_libnames(llvm_libs |
| 450 | ${ARG_LINK_COMPONENTS} |
| 451 | ${LLVM_LINK_COMPONENTS} |
| 452 | ) |
| 453 | |
| 454 | if(CMAKE_VERSION VERSION_LESS 2.8.12) |
| 455 | # Link libs w/o keywords, assuming PUBLIC. |
| 456 | target_link_libraries(${name} |
| 457 | ${ARG_LINK_LIBS} |
| 458 | ${lib_deps} |
| 459 | ${llvm_libs} |
| 460 | ) |
| 461 | elseif(ARG_STATIC) |
| 462 | target_link_libraries(${name} INTERFACE |
| 463 | ${ARG_LINK_LIBS} |
| 464 | ${lib_deps} |
| 465 | ${llvm_libs} |
| 466 | ) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 467 | else() |
Rafael Espindola | f9dcf90 | 2014-11-07 15:33:56 +0000 | [diff] [blame] | 468 | # We can use PRIVATE since SO knows its dependent libs. |
NAKAMURA Takumi | a39b612 | 2014-02-26 11:58:01 +0000 | [diff] [blame] | 469 | target_link_libraries(${name} PRIVATE |
| 470 | ${ARG_LINK_LIBS} |
| 471 | ${lib_deps} |
| 472 | ${llvm_libs} |
| 473 | ) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 474 | endif() |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 475 | |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 476 | if(LLVM_COMMON_DEPENDS) |
| 477 | add_dependencies(${name} ${LLVM_COMMON_DEPENDS}) |
NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 478 | # Add dependencies also to objlibs. |
| 479 | # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user. |
| 480 | foreach(objlib ${objlibs}) |
NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 481 | add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS}) |
| 482 | endforeach() |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 483 | endif() |
| 484 | endfunction() |
| 485 | |
| 486 | macro(add_llvm_library name) |
Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 487 | cmake_parse_arguments(ARG |
| 488 | "SHARED" |
| 489 | "" |
| 490 | "" |
| 491 | ${ARGN}) |
NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 492 | if( BUILD_SHARED_LIBS ) |
| 493 | llvm_add_library(${name} SHARED ${ARGN}) |
| 494 | else() |
| 495 | llvm_add_library(${name} ${ARGN}) |
| 496 | endif() |
| 497 | set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) |
| 498 | |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 499 | if( EXCLUDE_FROM_ALL ) |
| 500 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
| 501 | else() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 502 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") |
Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 503 | if(ARG_SHARED OR BUILD_SHARED_LIBS) |
| 504 | if(WIN32 OR CYGWIN) |
Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 505 | set(install_type RUNTIME) |
Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 506 | else() |
Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 507 | set(install_type LIBRARY) |
Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 508 | endif() |
Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 509 | else() |
Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 510 | set(install_type ARCHIVE) |
Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 511 | endif() |
Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 512 | |
Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 513 | install(TARGETS ${name} |
| 514 | EXPORT LLVMExports |
| 515 | ${install_type} DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 516 | COMPONENT ${name}) |
| 517 | |
Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 518 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 519 | add_custom_target(install-${name} |
| 520 | DEPENDS ${name} |
| 521 | COMMAND "${CMAKE_COMMAND}" |
| 522 | -DCMAKE_INSTALL_COMPONENT=${name} |
| 523 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 524 | endif() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 525 | endif() |
NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 526 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 527 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 528 | set_target_properties(${name} PROPERTIES FOLDER "Libraries") |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 529 | endmacro(add_llvm_library name) |
| 530 | |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 531 | macro(add_llvm_loadable_module name) |
NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 532 | llvm_add_library(${name} MODULE ${ARGN}) |
| 533 | if(NOT TARGET ${name}) |
NAKAMURA Takumi | a8c1c3f | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 534 | # Add empty "phony" target |
| 535 | add_custom_target(${name}) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 536 | else() |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 537 | if( EXCLUDE_FROM_ALL ) |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 538 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 539 | else() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 540 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 541 | if(WIN32 OR CYGWIN) |
| 542 | # DLL platform |
| 543 | set(dlldir "bin") |
| 544 | else() |
| 545 | set(dlldir "lib${LLVM_LIBDIR_SUFFIX}") |
| 546 | endif() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 547 | install(TARGETS ${name} |
NAKAMURA Takumi | ef97607 | 2014-02-09 16:36:03 +0000 | [diff] [blame] | 548 | EXPORT LLVMExports |
NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 549 | LIBRARY DESTINATION ${dlldir} |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 550 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 551 | endif() |
NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 552 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 553 | endif() |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 554 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 555 | |
| 556 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 557 | endmacro(add_llvm_loadable_module name) |
| 558 | |
| 559 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 560 | macro(add_llvm_executable name) |
Oscar Fuentes | 2c10b22 | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 561 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 562 | add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) |
| 563 | |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 564 | if( EXCLUDE_FROM_ALL ) |
| 565 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 566 | else() |
| 567 | add_executable(${name} ${ALL_FILES}) |
| 568 | endif() |
Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 569 | |
| 570 | if(DEFINED windows_resource_file) |
| 571 | set_windows_version_resource_properties(${name} ${windows_resource_file}) |
| 572 | endif() |
| 573 | |
NAKAMURA Takumi | b524c22 | 2014-01-28 11:40:04 +0000 | [diff] [blame] | 574 | llvm_update_compile_flags(${name}) |
Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 575 | add_link_opts( ${name} ) |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 576 | |
Richard Smith | 2b91a7f | 2014-09-26 22:40:15 +0000 | [diff] [blame] | 577 | # Do not add -Dname_EXPORTS to the command-line when building files in this |
| 578 | # target. Doing so is actively harmful for the modules build because it |
| 579 | # creates extra module variants, and not useful because we don't use these |
| 580 | # macros. |
| 581 | set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) |
| 582 | |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 583 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 584 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 585 | endif(LLVM_EXPORTED_SYMBOL_FILE) |
| 586 | |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 587 | set(EXCLUDE_FROM_ALL OFF) |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 588 | set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 589 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | 3fca0e8 | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 590 | if( LLVM_COMMON_DEPENDS ) |
| 591 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 592 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 593 | endmacro(add_llvm_executable name) |
| 594 | |
Reid Kleckner | 3e8c445 | 2015-03-18 20:09:13 +0000 | [diff] [blame] | 595 | function(export_executable_symbols target) |
| 596 | if (NOT MSVC) # MSVC's linker doesn't support exporting all symbols. |
| 597 | set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) |
| 598 | endif() |
| 599 | endfunction() |
| 600 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 601 | |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 602 | set (LLVM_TOOLCHAIN_TOOLS |
| 603 | llvm-ar |
| 604 | llvm-objdump |
| 605 | ) |
| 606 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 607 | macro(add_llvm_tool name) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 608 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 609 | set(EXCLUDE_FROM_ALL ON) |
| 610 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 611 | add_llvm_executable(${name} ${ARGN}) |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 612 | |
| 613 | list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL) |
| 614 | if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 615 | if( LLVM_BUILD_TOOLS ) |
NAKAMURA Takumi | ef97607 | 2014-02-09 16:36:03 +0000 | [diff] [blame] | 616 | install(TARGETS ${name} |
| 617 | EXPORT LLVMExports |
Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 618 | RUNTIME DESTINATION bin |
| 619 | COMPONENT ${name}) |
| 620 | |
| 621 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 622 | add_custom_target(install-${name} |
| 623 | DEPENDS ${name} |
| 624 | COMMAND "${CMAKE_COMMAND}" |
| 625 | -DCMAKE_INSTALL_COMPONENT=${name} |
| 626 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 627 | endif() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 628 | endif() |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 629 | endif() |
NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 630 | if( LLVM_BUILD_TOOLS ) |
| 631 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
| 632 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 633 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 634 | endmacro(add_llvm_tool name) |
| 635 | |
| 636 | |
| 637 | macro(add_llvm_example name) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 638 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 639 | set(EXCLUDE_FROM_ALL ON) |
| 640 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 641 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 642 | if( LLVM_BUILD_EXAMPLES ) |
| 643 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 644 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 645 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 646 | endmacro(add_llvm_example name) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 647 | |
| 648 | |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 649 | macro(add_llvm_utility name) |
| 650 | add_llvm_executable(${name} ${ARGN}) |
| 651 | set_target_properties(${name} PROPERTIES FOLDER "Utils") |
Derek Schuff | ef9928e | 2015-03-27 16:53:06 +0000 | [diff] [blame] | 652 | if( LLVM_INSTALL_UTILS ) |
| 653 | install (TARGETS ${name} |
| 654 | RUNTIME DESTINATION bin |
| 655 | COMPONENT ${name}) |
| 656 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 657 | add_custom_target(install-${name} |
| 658 | DEPENDS ${name} |
| 659 | COMMAND "${CMAKE_COMMAND}" |
| 660 | -DCMAKE_INSTALL_COMPONENT=${name} |
| 661 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") |
| 662 | endif() |
| 663 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 664 | endmacro(add_llvm_utility name) |
| 665 | |
| 666 | |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 667 | macro(add_llvm_target target_name) |
Oscar Fuentes | 4f0f335 | 2011-07-25 20:17:01 +0000 | [diff] [blame] | 668 | include_directories(BEFORE |
| 669 | ${CMAKE_CURRENT_BINARY_DIR} |
| 670 | ${CMAKE_CURRENT_SOURCE_DIR}) |
NAKAMURA Takumi | 45374cc | 2014-03-04 17:05:28 +0000 | [diff] [blame] | 671 | add_llvm_library(LLVM${target_name} ${ARGN}) |
Oscar Fuentes | ba1186c | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 672 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 673 | endmacro(add_llvm_target) |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 674 | |
| 675 | # Add external project that may want to be built as part of llvm such as Clang, |
| 676 | # lld, and Polly. This adds two options. One for the source directory of the |
| 677 | # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to |
Alp Toker | 171b0c3 | 2013-12-20 00:33:39 +0000 | [diff] [blame] | 678 | # enable or disable building it with everything else. |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 679 | # Additional parameter can be specified as the name of directory. |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 680 | macro(add_llvm_external_project name) |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 681 | set(add_llvm_external_dir "${ARGN}") |
| 682 | if("${add_llvm_external_dir}" STREQUAL "") |
| 683 | set(add_llvm_external_dir ${name}) |
| 684 | endif() |
Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 685 | list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}") |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 686 | string(REPLACE "-" "_" nameUNDERSCORE ${name}) |
| 687 | string(TOUPPER ${nameUNDERSCORE} nameUPPER) |
| 688 | set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}" |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 689 | CACHE PATH "Path to ${name} source directory") |
| 690 | if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL "" |
| 691 | AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt) |
| 692 | option(LLVM_EXTERNAL_${nameUPPER}_BUILD |
| 693 | "Whether to build ${name} as part of LLVM" ON) |
| 694 | if (LLVM_EXTERNAL_${nameUPPER}_BUILD) |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 695 | add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir}) |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 696 | endif() |
| 697 | endif() |
| 698 | endmacro(add_llvm_external_project) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 699 | |
Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 700 | macro(add_llvm_tool_subdirectory name) |
| 701 | list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}") |
| 702 | add_subdirectory(${name}) |
| 703 | endmacro(add_llvm_tool_subdirectory) |
| 704 | |
| 705 | macro(ignore_llvm_tool_subdirectory name) |
| 706 | list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}") |
| 707 | endmacro(ignore_llvm_tool_subdirectory) |
| 708 | |
| 709 | function(add_llvm_implicit_external_projects) |
| 710 | set(list_of_implicit_subdirs "") |
| 711 | file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") |
| 712 | foreach(dir ${sub-dirs}) |
| 713 | if(IS_DIRECTORY "${dir}") |
| 714 | list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore) |
| 715 | if( tool_subdir_ignore EQUAL -1 |
| 716 | AND EXISTS "${dir}/CMakeLists.txt") |
| 717 | get_filename_component(fn "${dir}" NAME) |
| 718 | list(APPEND list_of_implicit_subdirs "${fn}") |
| 719 | endif() |
| 720 | endif() |
| 721 | endforeach() |
| 722 | |
| 723 | foreach(external_proj ${list_of_implicit_subdirs}) |
| 724 | add_llvm_external_project("${external_proj}") |
| 725 | endforeach() |
| 726 | endfunction(add_llvm_implicit_external_projects) |
| 727 | |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 728 | # Generic support for adding a unittest. |
Chandler Carruth | 94d0251 | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 729 | function(add_unittest test_suite test_name) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 730 | if( NOT LLVM_BUILD_TESTS ) |
| 731 | set(EXCLUDE_FROM_ALL ON) |
| 732 | endif() |
| 733 | |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 734 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) |
| 735 | if (NOT LLVM_ENABLE_THREADS) |
| 736 | list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0) |
| 737 | endif () |
| 738 | |
| 739 | if (SUPPORTS_NO_VARIADIC_MACROS_FLAG) |
NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 740 | list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros") |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 741 | endif () |
| 742 | |
NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 743 | set(LLVM_REQUIRES_RTTI OFF) |
NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 744 | |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 745 | add_llvm_executable(${test_name} ${ARGN}) |
NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 746 | set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) |
| 747 | set_output_directory(${test_name} ${outdir} ${outdir}) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 748 | target_link_libraries(${test_name} |
| 749 | gtest |
| 750 | gtest_main |
| 751 | LLVMSupport # gtest needs it for raw_ostream. |
| 752 | ) |
| 753 | |
| 754 | add_dependencies(${test_suite} ${test_name}) |
| 755 | get_target_property(test_suite_folder ${test_suite} FOLDER) |
| 756 | if (NOT ${test_suite_folder} STREQUAL "NOTFOUND") |
| 757 | set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}") |
| 758 | endif () |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 759 | endfunction() |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 760 | |
Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 761 | function(llvm_add_go_executable binary pkgpath) |
| 762 | cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN}) |
| 763 | |
| 764 | if(LLVM_BINDINGS MATCHES "go") |
| 765 | # FIXME: This should depend only on the libraries Go needs. |
| 766 | get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS) |
| 767 | set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX}) |
| 768 | set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") |
| 769 | set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") |
Chandler Carruth | cab512d | 2014-12-29 22:50:30 +0000 | [diff] [blame] | 770 | set(cppflags "") |
| 771 | get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) |
| 772 | foreach(d ${include_dirs}) |
| 773 | set(cppflags "${cppflags} -I${d}") |
| 774 | endforeach(d) |
Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 775 | set(ldflags "${CMAKE_EXE_LINKER_FLAGS}") |
| 776 | add_custom_command(OUTPUT ${binpath} |
Chandler Carruth | cab512d | 2014-12-29 22:50:30 +0000 | [diff] [blame] | 777 | COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" |
Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 778 | ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath} |
| 779 | DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX} |
| 780 | ${llvmlibs} ${ARG_DEPENDS} |
| 781 | COMMENT "Building Go executable ${binary}" |
| 782 | VERBATIM) |
| 783 | if (ARG_ALL) |
| 784 | add_custom_target(${binary} ALL DEPENDS ${binpath}) |
| 785 | else() |
| 786 | add_custom_target(${binary} DEPENDS ${binpath}) |
| 787 | endif() |
| 788 | endif() |
| 789 | endfunction() |
| 790 | |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 791 | # This function provides an automatic way to 'configure'-like generate a file |
Alp Toker | 171b0c3 | 2013-12-20 00:33:39 +0000 | [diff] [blame] | 792 | # based on a set of common and custom variables, specifically targeting the |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 793 | # variables needed for the 'lit.site.cfg' files. This function bundles the |
| 794 | # common variables that any Lit instance is likely to need, and custom |
| 795 | # variables can be passed in. |
| 796 | function(configure_lit_site_cfg input output) |
| 797 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 798 | set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") |
| 799 | endforeach(c) |
| 800 | set(TARGETS_TO_BUILD ${TARGETS_BUILT}) |
| 801 | |
| 802 | set(SHLIBEXT "${LTDL_SHLIB_EXT}") |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 803 | |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 804 | # Configuration-time: See Unit/lit.site.cfg.in |
NAKAMURA Takumi | 0dc10d5 | 2013-12-04 11:15:17 +0000 | [diff] [blame] | 805 | if (CMAKE_CFG_INTDIR STREQUAL ".") |
| 806 | set(LLVM_BUILD_MODE ".") |
| 807 | else () |
| 808 | set(LLVM_BUILD_MODE "%(build_mode)s") |
| 809 | endif () |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 810 | |
NAKAMURA Takumi | 3c6f5cd | 2014-01-26 06:18:56 +0000 | [diff] [blame] | 811 | # They below might not be the build tree but provided binary tree. |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 812 | set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) |
| 813 | set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR}) |
NAKAMURA Takumi | ce78b80 | 2014-01-19 12:52:10 +0000 | [diff] [blame] | 814 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR}) |
| 815 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_DIR}) |
NAKAMURA Takumi | 3c6f5cd | 2014-01-26 06:18:56 +0000 | [diff] [blame] | 816 | |
| 817 | # SHLIBDIR points the build tree. |
NAKAMURA Takumi | 6c5fbbc | 2014-07-04 04:23:26 +0000 | [diff] [blame] | 818 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") |
NAKAMURA Takumi | 3c6f5cd | 2014-01-26 06:18:56 +0000 | [diff] [blame] | 819 | |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 820 | set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) |
NAKAMURA Takumi | 8d7a173 | 2014-07-04 04:45:40 +0000 | [diff] [blame] | 821 | # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for |
| 822 | # plugins. We may rename it. |
| 823 | if(LLVM_ENABLE_PLUGINS) |
| 824 | set(ENABLE_SHARED "1") |
| 825 | else() |
| 826 | set(ENABLE_SHARED "0") |
| 827 | endif() |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 828 | |
| 829 | if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE) |
| 830 | set(ENABLE_ASSERTIONS "1") |
| 831 | else() |
| 832 | set(ENABLE_ASSERTIONS "0") |
| 833 | endif() |
| 834 | |
Kuba Brecka | a62bbcc | 2015-01-24 01:42:44 +0000 | [diff] [blame] | 835 | set(HOST_OS ${CMAKE_SYSTEM_NAME}) |
Tim Northover | bfe8468 | 2013-02-14 16:49:32 +0000 | [diff] [blame] | 836 | set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 837 | |
Peter Collingbourne | ce80084 | 2014-10-17 18:32:36 +0000 | [diff] [blame] | 838 | set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") |
| 839 | set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") |
Chandler Carruth | 9719242 | 2014-10-21 00:36:28 +0000 | [diff] [blame] | 840 | set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") |
Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 841 | |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 842 | configure_file(${input} ${output} @ONLY) |
| 843 | endfunction() |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 844 | |
| 845 | # A raw function to create a lit target. This is used to implement the testuite |
| 846 | # management functions. |
| 847 | function(add_lit_target target comment) |
NAKAMURA Takumi | 69a89c7 | 2013-12-19 17:11:08 +0000 | [diff] [blame] | 848 | parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 849 | set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}") |
| 850 | separate_arguments(LIT_ARGS) |
NAKAMURA Takumi | 0dc10d5 | 2013-12-04 11:15:17 +0000 | [diff] [blame] | 851 | if (NOT CMAKE_CFG_INTDIR STREQUAL ".") |
| 852 | list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) |
| 853 | endif () |
Greg Fitzgerald | 962a339 | 2014-05-21 16:44:03 +0000 | [diff] [blame] | 854 | if (LLVM_MAIN_SRC_DIR) |
| 855 | set (LIT_COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 856 | else() |
| 857 | find_program(LIT_COMMAND llvm-lit) |
| 858 | endif () |
| 859 | list(APPEND LIT_COMMAND ${LIT_ARGS}) |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 860 | foreach(param ${ARG_PARAMS}) |
| 861 | list(APPEND LIT_COMMAND --param ${param}) |
| 862 | endforeach() |
Peter Collingbourne | 2ba7f7b | 2015-02-18 22:25:35 +0000 | [diff] [blame] | 863 | if (ARG_DEFAULT_ARGS) |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 864 | add_custom_target(${target} |
| 865 | COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS} |
| 866 | COMMENT "${comment}" |
Peter Collingbourne | a7fb5cf | 2014-11-17 22:16:15 +0000 | [diff] [blame] | 867 | ${cmake_3_2_USES_TERMINAL} |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 868 | ) |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 869 | else() |
| 870 | add_custom_target(${target} |
Nico Weber | b42359d | 2013-12-29 00:11:20 +0000 | [diff] [blame] | 871 | COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.") |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 872 | message(STATUS "${target} does nothing.") |
| 873 | endif() |
Peter Collingbourne | 2ba7f7b | 2015-02-18 22:25:35 +0000 | [diff] [blame] | 874 | if (ARG_DEPENDS) |
| 875 | add_dependencies(${target} ${ARG_DEPENDS}) |
| 876 | endif() |
NAKAMURA Takumi | 03fc730 | 2013-12-02 11:31:19 +0000 | [diff] [blame] | 877 | |
| 878 | # Tests should be excluded from "Build Solution". |
| 879 | set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 880 | endfunction() |
| 881 | |
| 882 | # A function to add a set of lit test suites to be driven through 'check-*' targets. |
| 883 | function(add_lit_testsuite target comment) |
| 884 | parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) |
| 885 | |
NAKAMURA Takumi | 54d2274 | 2012-10-10 13:32:55 +0000 | [diff] [blame] | 886 | # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all. |
| 887 | if(NOT EXCLUDE_FROM_ALL) |
| 888 | # Register the testsuites, params and depends for the global check rule. |
| 889 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS}) |
| 890 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS}) |
| 891 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS}) |
| 892 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS}) |
| 893 | endif() |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 894 | |
| 895 | # Produce a specific suffixed check rule. |
| 896 | add_lit_target(${target} ${comment} |
| 897 | ${ARG_DEFAULT_ARGS} |
| 898 | PARAMS ${ARG_PARAMS} |
| 899 | DEPENDS ${ARG_DEPENDS} |
| 900 | ARGS ${ARG_ARGS} |
| 901 | ) |
| 902 | endfunction() |
Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 903 | |
| 904 | function(add_lit_testsuites project directory) |
| 905 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| 906 | parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) |
| 907 | file(GLOB_RECURSE litCfg ${directory}/lit*.cfg) |
Chris Bieneman | abc8fb2 | 2015-03-27 21:45:49 +0000 | [diff] [blame] | 908 | set(lit_suites) |
Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 909 | foreach(f ${litCfg}) |
| 910 | get_filename_component(dir ${f} DIRECTORY) |
Chris Bieneman | abc8fb2 | 2015-03-27 21:45:49 +0000 | [diff] [blame] | 911 | set(lit_suites ${lit_suites} ${dir}) |
| 912 | endforeach() |
| 913 | list(REMOVE_DUPLICATES lit_suites) |
| 914 | foreach(dir ${lit_suites}) |
Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 915 | string(REPLACE ${directory} "" name_slash ${dir}) |
| 916 | if (name_slash) |
| 917 | string(REPLACE "/" "-" name_slash ${name_slash}) |
| 918 | string(REPLACE "\\" "-" name_dashes ${name_slash}) |
| 919 | string(TOLOWER "${project}${name_dashes}" name_var) |
| 920 | add_lit_target("check-${name_var}" "Running lit suite ${dir}" |
| 921 | ${dir} |
| 922 | PARAMS ${ARG_PARAMS} |
| 923 | DEPENDS ${ARG_DEPENDS} |
| 924 | ARGS ${ARG_ARGS} |
| 925 | ) |
| 926 | endif() |
| 927 | endforeach() |
| 928 | endif() |
| 929 | endfunction() |