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