| 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 | |
| Reid Kleckner | 8c18019 | 2016-03-30 17:28:21 +0000 | [diff] [blame] | 11 | # LLVM_REQUIRES_EH is an internal flag that individual targets can use to |
| 12 | # force EH |
| 13 | if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) |
| 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() |
| Andrey Bokhanko | b7201cc | 2016-09-01 14:39:54 +0000 | [diff] [blame] | 18 | if(MSVC) |
| 19 | list(APPEND LLVM_COMPILE_FLAGS "/EHsc") |
| 20 | endif() |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 21 | else() |
| 22 | if(LLVM_COMPILER_IS_GCC_COMPATIBLE) |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 23 | list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions") |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 24 | elseif(MSVC) |
| 25 | list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0) |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 26 | list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-") |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 27 | endif() |
| 28 | endif() |
| 29 | |
| Dan Liew | a5bdc84 | 2014-07-22 15:41:18 +0000 | [diff] [blame] | 30 | # LLVM_REQUIRES_RTTI is an internal flag that individual |
| 31 | # targets can use to force RTTI |
| Tom Stellard | 18bf626 | 2015-11-04 20:57:43 +0000 | [diff] [blame] | 32 | set(LLVM_CONFIG_HAS_RTTI YES CACHE INTERNAL "") |
| Dan Liew | a5bdc84 | 2014-07-22 15:41:18 +0000 | [diff] [blame] | 33 | if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI)) |
| Tom Stellard | 18bf626 | 2015-11-04 20:57:43 +0000 | [diff] [blame] | 34 | set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "") |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 35 | list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) |
| 36 | if (LLVM_COMPILER_IS_GCC_COMPATIBLE) |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 37 | list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti") |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 38 | elseif (MSVC) |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 39 | list(APPEND LLVM_COMPILE_FLAGS "/GR-") |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 40 | endif () |
| Andrey Bokhanko | b7201cc | 2016-09-01 14:39:54 +0000 | [diff] [blame] | 41 | elseif(MSVC) |
| 42 | list(APPEND LLVM_COMPILE_FLAGS "/GR") |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 43 | endif() |
| 44 | |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 45 | # Assume that; |
| 46 | # - LLVM_COMPILE_FLAGS is list. |
| 47 | # - PROPERTY COMPILE_FLAGS is string. |
| Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 48 | string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}") |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 49 | |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 50 | if(update_src_props) |
| NAKAMURA Takumi | b524c22 | 2014-01-28 11:40:04 +0000 | [diff] [blame] | 51 | foreach(fn ${sources}) |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 52 | get_filename_component(suf ${fn} EXT) |
| 53 | if("${suf}" STREQUAL ".cpp") |
| NAKAMURA Takumi | d40cdc9 | 2014-01-31 17:32:42 +0000 | [diff] [blame] | 54 | set_property(SOURCE ${fn} APPEND_STRING PROPERTY |
| 55 | COMPILE_FLAGS "${target_compile_flags}") |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 56 | endif() |
| 57 | endforeach() |
| 58 | else() |
| 59 | # Update target props, since all sources are C++. |
| 60 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 61 | COMPILE_FLAGS "${target_compile_flags}") |
| 62 | endif() |
| 63 | |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 64 | set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS}) |
| 65 | endfunction() |
| 66 | |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 67 | function(add_llvm_symbol_exports target_name export_file) |
| 68 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| NAKAMURA Takumi | bbd2aaa | 2013-12-29 16:15:26 +0000 | [diff] [blame] | 69 | set(native_export_file "${target_name}.exports") |
| NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 70 | add_custom_command(OUTPUT ${native_export_file} |
| 71 | COMMAND sed -e "s/^/_/" < ${export_file} > ${native_export_file} |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 72 | DEPENDS ${export_file} |
| 73 | VERBATIM |
| 74 | COMMENT "Creating export file for ${target_name}") |
| 75 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 76 | LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
| Chandler Carruth | 2aff750 | 2016-07-19 22:46:39 +0000 | [diff] [blame] | 77 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX") |
| 78 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 79 | LINK_FLAGS " -Wl,-bE:${export_file}") |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 80 | elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) |
| 81 | # 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] | 82 | set(native_export_file "${target_name}.exports") |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 83 | # FIXME: Don't write the "local:" line on OpenBSD. |
| Sylvestre Ledru | b0cec31 | 2017-04-17 20:51:50 +0000 | [diff] [blame] | 84 | # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M) |
| NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 85 | add_custom_command(OUTPUT ${native_export_file} |
| Sylvestre Ledru | f22ebb7 | 2018-03-29 09:44:09 +0000 | [diff] [blame] | 86 | COMMAND echo "LLVM_${LLVM_VERSION_MAJOR} {" > ${native_export_file} |
| NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 87 | COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || : |
| 88 | COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file} |
| 89 | COMMAND echo " local: *;" >> ${native_export_file} |
| 90 | COMMAND echo "};" >> ${native_export_file} |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 91 | DEPENDS ${export_file} |
| 92 | VERBATIM |
| 93 | COMMENT "Creating export file for ${target_name}") |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 94 | if (${LLVM_LINKER_IS_SOLARISLD}) |
| Rafael Espindola | ec1d069 | 2015-06-22 12:34:54 +0000 | [diff] [blame] | 95 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 96 | LINK_FLAGS " -Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
| 97 | else() |
| 98 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 99 | LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
| 100 | endif() |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 101 | else() |
| NAKAMURA Takumi | bbd2aaa | 2013-12-29 16:15:26 +0000 | [diff] [blame] | 102 | set(native_export_file "${target_name}.def") |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 103 | |
| NAKAMURA Takumi | 8121075 | 2013-12-29 16:15:18 +0000 | [diff] [blame] | 104 | add_custom_command(OUTPUT ${native_export_file} |
| NAKAMURA Takumi | 3eb0666 | 2015-07-05 08:56:38 +0000 | [diff] [blame] | 105 | COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" |
| 106 | < ${export_file} > ${native_export_file} |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 107 | DEPENDS ${export_file} |
| 108 | VERBATIM |
| 109 | COMMENT "Creating export file for ${target_name}") |
| Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 110 | set(export_file_linker_flag "${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}") |
| 111 | if(MSVC) |
| Reid Kleckner | ec6789b | 2015-04-22 16:23:00 +0000 | [diff] [blame] | 112 | set(export_file_linker_flag "/DEF:\"${export_file_linker_flag}\"") |
| NAKAMURA Takumi | 0a062bd | 2013-12-29 16:19:13 +0000 | [diff] [blame] | 113 | endif() |
| Chris Bieneman | 970555b | 2014-10-30 22:37:58 +0000 | [diff] [blame] | 114 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 115 | LINK_FLAGS " ${export_file_linker_flag}") |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 116 | endif() |
| 117 | |
| 118 | add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) |
| NAKAMURA Takumi | 14f1f44 | 2014-01-27 17:39:38 +0000 | [diff] [blame] | 119 | set_target_properties(${target_name}_exports PROPERTIES FOLDER "Misc") |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 120 | |
| 121 | get_property(srcs TARGET ${target_name} PROPERTY SOURCES) |
| 122 | foreach(src ${srcs}) |
| 123 | get_filename_component(extension ${src} EXT) |
| 124 | if(extension STREQUAL ".cpp") |
| 125 | set(first_source_file ${src}) |
| 126 | break() |
| 127 | endif() |
| 128 | endforeach() |
| 129 | |
| 130 | # Force re-linking when the exports file changes. Actually, it |
| 131 | # forces recompilation of the source file. The LINK_DEPENDS target |
| 132 | # property only works for makefile-based generators. |
| Quentin Colombet | cb2ae8d | 2014-01-16 06:43:55 +0000 | [diff] [blame] | 133 | # FIXME: This is not safe because this will create the same target |
| 134 | # ${native_export_file} in several different file: |
| 135 | # - One where we emitted ${target_name}_exports |
| 136 | # - One where we emitted the build command for the following object. |
| 137 | # set_property(SOURCE ${first_source_file} APPEND PROPERTY |
| 138 | # OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 139 | |
| 140 | set_property(DIRECTORY APPEND |
| 141 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file}) |
| 142 | |
| 143 | add_dependencies(${target_name} ${target_name}_exports) |
| NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 144 | |
| 145 | # Add dependency to *_exports later -- CMake issue 14747 |
| 146 | list(APPEND LLVM_COMMON_DEPENDS ${target_name}_exports) |
| 147 | set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 148 | endfunction(add_llvm_symbol_exports) |
| 149 | |
| Shoaib Meenai | fce46161 | 2018-06-14 23:26:33 +0000 | [diff] [blame] | 150 | if(APPLE) |
| 151 | execute_process( |
| 152 | COMMAND "${CMAKE_LINKER}" -v |
| 153 | ERROR_VARIABLE stderr |
| 154 | ) |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 155 | set(LLVM_LINKER_DETECTED YES) |
| Shoaib Meenai | fce46161 | 2018-06-14 23:26:33 +0000 | [diff] [blame] | 156 | if("${stderr}" MATCHES "PROJECT:ld64") |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 157 | set(LLVM_LINKER_IS_LD64 YES) |
| Shoaib Meenai | fce46161 | 2018-06-14 23:26:33 +0000 | [diff] [blame] | 158 | message(STATUS "Linker detection: ld64") |
| 159 | else() |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 160 | set(LLVM_LINKER_DETECTED NO) |
| Shoaib Meenai | fce46161 | 2018-06-14 23:26:33 +0000 | [diff] [blame] | 161 | message(STATUS "Linker detection: unknown") |
| 162 | endif() |
| 163 | elseif(NOT WIN32) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 164 | # Detect what linker we have here |
| Tim Shen | 5a16604 | 2017-10-30 21:12:14 +0000 | [diff] [blame] | 165 | if( LLVM_USE_LINKER ) |
| 166 | set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version) |
| 167 | else() |
| Shoaib Meenai | fd7befa | 2018-04-26 06:04:46 +0000 | [diff] [blame] | 168 | separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}") |
| 169 | set(command ${CMAKE_C_COMPILER} ${flags} -Wl,--version) |
| Tim Shen | 5a16604 | 2017-10-30 21:12:14 +0000 | [diff] [blame] | 170 | endif() |
| NAKAMURA Takumi | 8b1578f | 2015-01-06 09:44:29 +0000 | [diff] [blame] | 171 | execute_process( |
| Tim Shen | 5a16604 | 2017-10-30 21:12:14 +0000 | [diff] [blame] | 172 | COMMAND ${command} |
| NAKAMURA Takumi | 8b1578f | 2015-01-06 09:44:29 +0000 | [diff] [blame] | 173 | OUTPUT_VARIABLE stdout |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 174 | ERROR_VARIABLE stderr |
| NAKAMURA Takumi | 8b1578f | 2015-01-06 09:44:29 +0000 | [diff] [blame] | 175 | ) |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 176 | set(LLVM_LINKER_DETECTED YES) |
| Rafael Espindola | 19c39ee | 2014-12-04 17:54:35 +0000 | [diff] [blame] | 177 | if("${stdout}" MATCHES "GNU gold") |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 178 | set(LLVM_LINKER_IS_GOLD YES) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 179 | message(STATUS "Linker detection: GNU Gold") |
| 180 | elseif("${stdout}" MATCHES "^LLD") |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 181 | set(LLVM_LINKER_IS_LLD YES) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 182 | message(STATUS "Linker detection: LLD") |
| 183 | elseif("${stdout}" MATCHES "GNU ld") |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 184 | set(LLVM_LINKER_IS_GNULD YES) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 185 | message(STATUS "Linker detection: GNU ld") |
| Michal Gorny | 0eaaf27 | 2017-11-17 17:12:14 +0000 | [diff] [blame] | 186 | elseif("${stderr}" MATCHES "Solaris Link Editors" OR |
| 187 | "${stdout}" MATCHES "Solaris Link Editors") |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 188 | set(LLVM_LINKER_IS_SOLARISLD YES) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 189 | message(STATUS "Linker detection: Solaris ld") |
| 190 | else() |
| Shoaib Meenai | d65dba5 | 2018-06-14 23:40:04 +0000 | [diff] [blame] | 191 | set(LLVM_LINKER_DETECTED NO) |
| Rui Ueyama | 845b981 | 2017-07-12 21:43:14 +0000 | [diff] [blame] | 192 | message(STATUS "Linker detection: unknown") |
| Rafael Espindola | 19c39ee | 2014-12-04 17:54:35 +0000 | [diff] [blame] | 193 | endif() |
| 194 | endif() |
| 195 | |
| Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 196 | function(add_link_opts target_name) |
| Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 197 | # Don't use linker optimizations in debug builds since it slows down the |
| 198 | # linker in a context where the optimizations are not important. |
| 199 | if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 200 | |
| Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 201 | # Pass -O3 to the linker. This enabled different optimizations on different |
| 202 | # linkers. |
| Chandler Carruth | 2aff750 | 2016-07-19 22:46:39 +0000 | [diff] [blame] | 203 | if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin|SunOS|AIX" OR WIN32)) |
| Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 204 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 205 | LINK_FLAGS " -Wl,-O3") |
| 206 | endif() |
| 207 | |
| 208 | if(LLVM_LINKER_IS_GOLD) |
| 209 | # With gold gc-sections is always safe. |
| NAKAMURA Takumi | 748627c | 2014-10-20 12:12:21 +0000 | [diff] [blame] | 210 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 211 | LINK_FLAGS " -Wl,--gc-sections") |
| Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 212 | # Note that there is a bug with -Wl,--icf=safe so it is not safe |
| 213 | # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704. |
| 214 | endif() |
| 215 | |
| 216 | if(NOT LLVM_NO_DEAD_STRIP) |
| 217 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 218 | # ld64's implementation of -dead_strip breaks tools that use plugins. |
| 219 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 220 | LINK_FLAGS " -Wl,-dead_strip") |
| Rafael Espindola | c32ed57 | 2015-06-22 15:06:17 +0000 | [diff] [blame] | 221 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 222 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 223 | LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections") |
| Brad Smith | 3baae56 | 2018-06-23 21:43:27 +0000 | [diff] [blame] | 224 | elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") |
| Rafael Espindola | 24766f9 | 2015-04-06 15:04:31 +0000 | [diff] [blame] | 225 | # Object files are compiled with -ffunction-data-sections. |
| 226 | # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks |
| 227 | # tools that use plugins. Always pass --gc-sections once we require |
| 228 | # a newer linker. |
| 229 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 230 | LINK_FLAGS " -Wl,--gc-sections") |
| 231 | endif() |
| Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 232 | endif() |
| 233 | endif() |
| Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 234 | endfunction(add_link_opts) |
| Nico Weber | 62588e1 | 2013-12-30 03:36:05 +0000 | [diff] [blame] | 235 | |
| NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 236 | # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. |
| Brian Gesiak | 615a3bb | 2017-09-29 19:50:41 +0000 | [diff] [blame] | 237 | # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, |
| 238 | # or a certain builder, for eaxample, msbuild.exe, would be confused. |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 239 | function(set_output_directory target) |
| Ramkumar Ramachandra | cad135a | 2015-11-10 18:26:34 +0000 | [diff] [blame] | 240 | cmake_parse_arguments(ARG "" "BINARY_DIR;LIBRARY_DIR" "" ${ARGN}) |
| NAKAMURA Takumi | 38d45a2 | 2014-07-04 04:23:15 +0000 | [diff] [blame] | 241 | |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 242 | # module_dir -- corresponding to LIBRARY_OUTPUT_DIRECTORY. |
| NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 243 | # It affects output of add_library(MODULE). |
| 244 | if(WIN32 OR CYGWIN) |
| 245 | # DLL platform |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 246 | set(module_dir ${ARG_BINARY_DIR}) |
| NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 247 | else() |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 248 | set(module_dir ${ARG_LIBRARY_DIR}) |
| NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 249 | endif() |
| NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 250 | if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") |
| 251 | foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) |
| 252 | string(TOUPPER "${build_mode}" CONFIG_SUFFIX) |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 253 | if(ARG_BINARY_DIR) |
| 254 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINARY_DIR}) |
| 255 | set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) |
| 256 | endif() |
| 257 | if(ARG_LIBRARY_DIR) |
| 258 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBRARY_DIR}) |
| 259 | set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) |
| 260 | endif() |
| 261 | if(module_dir) |
| 262 | string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${module_dir}) |
| 263 | set_target_properties(${target} PROPERTIES "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi}) |
| 264 | endif() |
| NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 265 | endforeach() |
| 266 | else() |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 267 | if(ARG_BINARY_DIR) |
| 268 | set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${ARG_BINARY_DIR}) |
| 269 | endif() |
| 270 | if(ARG_LIBRARY_DIR) |
| 271 | set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBRARY_DIR}) |
| 272 | endif() |
| 273 | if(module_dir) |
| 274 | set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${module_dir}) |
| 275 | endif() |
| NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 276 | endif() |
| 277 | endfunction() |
| 278 | |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 279 | # If on Windows and building with MSVC, add the resource script containing the |
| 280 | # VERSIONINFO data to the project. This embeds version resource information |
| 281 | # into the output .exe or .dll. |
| 282 | # TODO: Enable for MinGW Windows builds too. |
| 283 | # |
| 284 | function(add_windows_version_resource_file OUT_VAR) |
| 285 | set(sources ${ARGN}) |
| Shoaib Meenai | 6391458 | 2017-10-25 17:11:28 +0000 | [diff] [blame] | 286 | if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 287 | set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc) |
| NAKAMURA Takumi | ec782b4 | 2015-06-14 21:47:29 +0000 | [diff] [blame] | 288 | if(EXISTS ${resource_file}) |
| 289 | set(sources ${sources} ${resource_file}) |
| 290 | source_group("Resource Files" ${resource_file}) |
| 291 | set(windows_resource_file ${resource_file} PARENT_SCOPE) |
| 292 | endif() |
| Shoaib Meenai | 6391458 | 2017-10-25 17:11:28 +0000 | [diff] [blame] | 293 | endif(MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 294 | |
| 295 | set(${OUT_VAR} ${sources} PARENT_SCOPE) |
| 296 | endfunction(add_windows_version_resource_file) |
| 297 | |
| 298 | # set_windows_version_resource_properties(name resource_file... |
| 299 | # VERSION_MAJOR int |
| 300 | # Optional major version number (defaults to LLVM_VERSION_MAJOR) |
| 301 | # VERSION_MINOR int |
| 302 | # Optional minor version number (defaults to LLVM_VERSION_MINOR) |
| 303 | # VERSION_PATCHLEVEL int |
| 304 | # Optional patchlevel version number (defaults to LLVM_VERSION_PATCH) |
| 305 | # VERSION_STRING |
| 306 | # Optional version string (defaults to PACKAGE_VERSION) |
| 307 | # PRODUCT_NAME |
| 308 | # Optional product name string (defaults to "LLVM") |
| 309 | # ) |
| 310 | function(set_windows_version_resource_properties name resource_file) |
| 311 | cmake_parse_arguments(ARG |
| 312 | "" |
| 313 | "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME" |
| 314 | "" |
| 315 | ${ARGN}) |
| 316 | |
| 317 | if (NOT DEFINED ARG_VERSION_MAJOR) |
| 318 | set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 319 | endif() |
| 320 | |
| 321 | if (NOT DEFINED ARG_VERSION_MINOR) |
| 322 | set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 323 | endif() |
| 324 | |
| 325 | if (NOT DEFINED ARG_VERSION_PATCHLEVEL) |
| 326 | set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) |
| 327 | endif() |
| 328 | |
| 329 | if (NOT DEFINED ARG_VERSION_STRING) |
| 330 | set(ARG_VERSION_STRING ${PACKAGE_VERSION}) |
| 331 | endif() |
| 332 | |
| 333 | if (NOT DEFINED ARG_PRODUCT_NAME) |
| 334 | set(ARG_PRODUCT_NAME "LLVM") |
| 335 | endif() |
| 336 | |
| 337 | set_property(SOURCE ${resource_file} |
| Peter Collingbourne | a89468b | 2015-06-18 01:15:18 +0000 | [diff] [blame] | 338 | PROPERTY COMPILE_FLAGS /nologo) |
| 339 | set_property(SOURCE ${resource_file} |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 340 | PROPERTY COMPILE_DEFINITIONS |
| 341 | "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}" |
| 342 | "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}" |
| 343 | "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}" |
| 344 | "RC_VERSION_FIELD_4=0" |
| 345 | "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\"" |
| 346 | "RC_INTERNAL_NAME=\"${name}\"" |
| 347 | "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\"" |
| 348 | "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"") |
| 349 | endfunction(set_windows_version_resource_properties) |
| 350 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 351 | # llvm_add_library(name sources... |
| NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 352 | # SHARED;STATIC |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 353 | # STATIC by default w/o BUILD_SHARED_LIBS. |
| 354 | # SHARED by default w/ BUILD_SHARED_LIBS. |
| Axel Naumann | b457beb | 2016-01-12 07:44:58 +0000 | [diff] [blame] | 355 | # OBJECT |
| 356 | # Also create an OBJECT library target. Default if STATIC && SHARED. |
| NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 357 | # MODULE |
| 358 | # Target ${name} might not be created on unsupported platforms. |
| 359 | # Check with "if(TARGET ${name})". |
| Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 360 | # DISABLE_LLVM_LINK_LLVM_DYLIB |
| 361 | # Do not link this library to libLLVM, even if |
| 362 | # LLVM_LINK_LLVM_DYLIB is enabled. |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 363 | # OUTPUT_NAME name |
| 364 | # Corresponds to OUTPUT_NAME in target properties. |
| 365 | # DEPENDS targets... |
| 366 | # Same semantics as add_dependencies(). |
| 367 | # LINK_COMPONENTS components... |
| 368 | # Same as the variable LLVM_LINK_COMPONENTS. |
| 369 | # LINK_LIBS lib_targets... |
| 370 | # Same semantics as target_link_libraries(). |
| NAKAMURA Takumi | dea00df | 2014-02-13 01:00:52 +0000 | [diff] [blame] | 371 | # ADDITIONAL_HEADERS |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 372 | # May specify header files for IDE generators. |
| Chris Bieneman | 5e96fe9 | 2015-11-04 23:11:12 +0000 | [diff] [blame] | 373 | # SONAME |
| 374 | # Should set SONAME link flags and create symlinks |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 375 | # PLUGIN_TOOL |
| 376 | # The tool (i.e. cmake target) that this plugin will link against |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 377 | # ) |
| 378 | function(llvm_add_library name) |
| 379 | cmake_parse_arguments(ARG |
| Axel Naumann | b457beb | 2016-01-12 07:44:58 +0000 | [diff] [blame] | 380 | "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME" |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 381 | "OUTPUT_NAME;PLUGIN_TOOL" |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 382 | "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 383 | ${ARGN}) |
| 384 | list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) |
| NAKAMURA Takumi | dea00df | 2014-02-13 01:00:52 +0000 | [diff] [blame] | 385 | if(ARG_ADDITIONAL_HEADERS) |
| 386 | # Pass through ADDITIONAL_HEADERS. |
| 387 | set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS}) |
| 388 | endif() |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 389 | if(ARG_OBJLIBS) |
| 390 | set(ALL_FILES ${ARG_OBJLIBS}) |
| 391 | else() |
| 392 | llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) |
| 393 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 394 | |
| 395 | if(ARG_MODULE) |
| 396 | if(ARG_SHARED OR ARG_STATIC) |
| 397 | message(WARNING "MODULE with SHARED|STATIC doesn't make sense.") |
| 398 | endif() |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 399 | # Plugins that link against a tool are allowed even when plugins in general are not |
| 400 | if(NOT LLVM_ENABLE_PLUGINS AND NOT (ARG_PLUGIN_TOOL AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)) |
| NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 401 | message(STATUS "${name} ignored -- Loadable modules not supported on this platform.") |
| 402 | return() |
| 403 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 404 | else() |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 405 | if(ARG_PLUGIN_TOOL) |
| 406 | message(WARNING "PLUGIN_TOOL without MODULE doesn't make sense.") |
| 407 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 408 | if(BUILD_SHARED_LIBS AND NOT ARG_STATIC) |
| 409 | set(ARG_SHARED TRUE) |
| 410 | endif() |
| 411 | if(NOT ARG_SHARED) |
| 412 | set(ARG_STATIC TRUE) |
| 413 | endif() |
| 414 | endif() |
| 415 | |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 416 | # Generate objlib |
| Axel Naumann | b457beb | 2016-01-12 07:44:58 +0000 | [diff] [blame] | 417 | if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT) |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 418 | # Generate an obj library for both targets. |
| 419 | set(obj_name "obj.${name}") |
| 420 | add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL |
| 421 | ${ALL_FILES} |
| 422 | ) |
| 423 | llvm_update_compile_flags(${obj_name}) |
| 424 | set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>") |
| 425 | |
| NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 426 | # Do add_dependencies(obj) later due to CMake issue 14747. |
| 427 | list(APPEND objlibs ${obj_name}) |
| 428 | |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 429 | set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") |
| 430 | endif() |
| 431 | |
| 432 | if(ARG_SHARED AND ARG_STATIC) |
| 433 | # static |
| 434 | set(name_static "${name}_static") |
| 435 | if(ARG_OUTPUT_NAME) |
| NAKAMURA Takumi | b47a2c0 | 2014-02-28 00:28:13 +0000 | [diff] [blame] | 436 | set(output_name OUTPUT_NAME "${ARG_OUTPUT_NAME}") |
| NAKAMURA Takumi | e3408ab | 2014-02-21 14:17:17 +0000 | [diff] [blame] | 437 | endif() |
| 438 | # DEPENDS has been appended to LLVM_COMMON_LIBS. |
| 439 | llvm_add_library(${name_static} STATIC |
| 440 | ${output_name} |
| 441 | OBJLIBS ${ALL_FILES} # objlib |
| 442 | LINK_LIBS ${ARG_LINK_LIBS} |
| 443 | LINK_COMPONENTS ${ARG_LINK_COMPONENTS} |
| 444 | ) |
| 445 | # FIXME: Add name_static to anywhere in TARGET ${name}'s PROPERTY. |
| 446 | set(ARG_STATIC) |
| 447 | endif() |
| 448 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 449 | if(ARG_MODULE) |
| 450 | add_library(${name} MODULE ${ALL_FILES}) |
| Peter Collingbourne | b192a20 | 2016-11-28 21:59:14 +0000 | [diff] [blame] | 451 | llvm_setup_rpath(${name}) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 452 | elseif(ARG_SHARED) |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 453 | add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 454 | add_library(${name} SHARED ${ALL_FILES}) |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 455 | |
| 456 | llvm_setup_rpath(${name}) |
| 457 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 458 | else() |
| 459 | add_library(${name} STATIC ${ALL_FILES}) |
| 460 | endif() |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 461 | |
| Chris Bieneman | 958edcb | 2016-11-19 01:32:09 +0000 | [diff] [blame] | 462 | setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS}) |
| 463 | |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 464 | if(DEFINED windows_resource_file) |
| 465 | set_windows_version_resource_properties(${name} ${windows_resource_file}) |
| 466 | set(windows_resource_file ${windows_resource_file} PARENT_SCOPE) |
| 467 | endif() |
| 468 | |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 469 | set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| NAKAMURA Takumi | bb7483d | 2015-09-08 07:42:06 +0000 | [diff] [blame] | 470 | # $<TARGET_OBJECTS> doesn't require compile flags. |
| 471 | if(NOT obj_name) |
| 472 | llvm_update_compile_flags(${name}) |
| 473 | endif() |
| Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 474 | add_link_opts( ${name} ) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 475 | if(ARG_OUTPUT_NAME) |
| 476 | set_target_properties(${name} |
| 477 | PROPERTIES |
| 478 | OUTPUT_NAME ${ARG_OUTPUT_NAME} |
| 479 | ) |
| 480 | endif() |
| Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 481 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 482 | if(ARG_MODULE) |
| NAKAMURA Takumi | e72e2e9 | 2014-02-13 11:19:21 +0000 | [diff] [blame] | 483 | set_target_properties(${name} PROPERTIES |
| 484 | PREFIX "" |
| 485 | SUFFIX ${LLVM_PLUGIN_EXT} |
| 486 | ) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 487 | endif() |
| 488 | |
| 489 | if(ARG_SHARED) |
| NAKAMURA Takumi | 543105f | 2014-04-10 15:47:04 +0000 | [diff] [blame] | 490 | if(WIN32) |
| 491 | set_target_properties(${name} PROPERTIES |
| 492 | PREFIX "" |
| 493 | ) |
| 494 | endif() |
| Michal Gorny | 6b929d5 | 2016-10-04 06:09:18 +0000 | [diff] [blame] | 495 | |
| 496 | # Set SOVERSION on shared libraries that lack explicit SONAME |
| 497 | # specifier, on *nix systems that are not Darwin. |
| 498 | if(UNIX AND NOT APPLE AND NOT ARG_SONAME) |
| 499 | set_target_properties(${name} |
| 500 | PROPERTIES |
| Michal Gorny | 6083191 | 2017-01-17 21:04:19 +0000 | [diff] [blame] | 501 | # Since 4.0.0, the ABI version is indicated by the major version |
| Michal Gorny | c4ede8f | 2018-08-08 20:45:03 +0000 | [diff] [blame] | 502 | SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX} |
| Sylvestre Ledru | f22ebb7 | 2018-03-29 09:44:09 +0000 | [diff] [blame] | 503 | VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}) |
| Michal Gorny | 6b929d5 | 2016-10-04 06:09:18 +0000 | [diff] [blame] | 504 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 505 | endif() |
| Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 506 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 507 | if(ARG_MODULE OR ARG_SHARED) |
| Richard Smith | 2b91a7f | 2014-09-26 22:40:15 +0000 | [diff] [blame] | 508 | # Do not add -Dname_EXPORTS to the command-line when building files in this |
| 509 | # target. Doing so is actively harmful for the modules build because it |
| 510 | # creates extra module variants, and not useful because we don't use these |
| 511 | # macros. |
| 512 | set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) |
| 513 | |
| Nico Weber | 06473f8 | 2013-12-29 05:39:01 +0000 | [diff] [blame] | 514 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 515 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 516 | endif() |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 517 | endif() |
| 518 | |
| Andrew Wilkins | a4f3705 | 2015-11-10 23:19:21 +0000 | [diff] [blame] | 519 | if(ARG_SHARED AND UNIX) |
| 520 | if(NOT APPLE AND ARG_SONAME) |
| 521 | get_target_property(output_name ${name} OUTPUT_NAME) |
| 522 | if(${output_name} STREQUAL "output_name-NOTFOUND") |
| 523 | set(output_name ${name}) |
| 524 | endif() |
| Sylvestre Ledru | f22ebb7 | 2018-03-29 09:44:09 +0000 | [diff] [blame] | 525 | set(library_name ${output_name}-${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}) |
| Andrew Wilkins | a4f3705 | 2015-11-10 23:19:21 +0000 | [diff] [blame] | 526 | set(api_name ${output_name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}) |
| 527 | set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name}) |
| 528 | llvm_install_library_symlink(${api_name} ${library_name} SHARED |
| 529 | COMPONENT ${name} |
| 530 | ALWAYS_GENERATE) |
| 531 | llvm_install_library_symlink(${output_name} ${library_name} SHARED |
| 532 | COMPONENT ${name} |
| 533 | ALWAYS_GENERATE) |
| 534 | endif() |
| 535 | endif() |
| 536 | |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 537 | if(ARG_MODULE AND LLVM_EXPORT_SYMBOLS_FOR_PLUGINS AND ARG_PLUGIN_TOOL AND (WIN32 OR CYGWIN)) |
| 538 | # On DLL platforms symbols are imported from the tool by linking against it. |
| 539 | set(llvm_libs ${ARG_PLUGIN_TOOL}) |
| 540 | elseif (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS) |
| Andrew Wilkins | 095e22d | 2016-02-12 01:42:43 +0000 | [diff] [blame] | 541 | if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) |
| 542 | set(llvm_libs LLVM) |
| 543 | else() |
| 544 | llvm_map_components_to_libnames(llvm_libs |
| 545 | ${ARG_LINK_COMPONENTS} |
| 546 | ${LLVM_LINK_COMPONENTS} |
| 547 | ) |
| 548 | endif() |
| Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 549 | else() |
| Andrew Wilkins | 095e22d | 2016-02-12 01:42:43 +0000 | [diff] [blame] | 550 | # Components have not been defined explicitly in CMake, so add the |
| 551 | # dependency information for this library as defined by LLVMBuild. |
| 552 | # |
| 553 | # It would be nice to verify that we have the dependencies for this library |
| 554 | # name, but using get_property(... SET) doesn't suffice to determine if a |
| 555 | # property has been set to an empty value. |
| 556 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) |
| Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 557 | endif() |
| NAKAMURA Takumi | a39b612 | 2014-02-26 11:58:01 +0000 | [diff] [blame] | 558 | |
| Chris Bieneman | 6650b02 | 2016-06-08 22:48:01 +0000 | [diff] [blame] | 559 | if(ARG_STATIC) |
| 560 | set(libtype INTERFACE) |
| Steven Wu | ec6f56e | 2016-05-26 04:35:35 +0000 | [diff] [blame] | 561 | else() |
| 562 | # We can use PRIVATE since SO knows its dependent libs. |
| Chris Bieneman | 6650b02 | 2016-06-08 22:48:01 +0000 | [diff] [blame] | 563 | set(libtype PRIVATE) |
| 564 | endif() |
| 565 | |
| 566 | target_link_libraries(${name} ${libtype} |
| Steven Wu | ec6f56e | 2016-05-26 04:35:35 +0000 | [diff] [blame] | 567 | ${ARG_LINK_LIBS} |
| 568 | ${lib_deps} |
| 569 | ${llvm_libs} |
| 570 | ) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 571 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 572 | if(LLVM_COMMON_DEPENDS) |
| 573 | add_dependencies(${name} ${LLVM_COMMON_DEPENDS}) |
| NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 574 | # Add dependencies also to objlibs. |
| 575 | # CMake issue 14747 -- add_dependencies() might be ignored to objlib's user. |
| 576 | foreach(objlib ${objlibs}) |
| NAKAMURA Takumi | 679e772 | 2014-02-21 14:17:29 +0000 | [diff] [blame] | 577 | add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS}) |
| 578 | endforeach() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 579 | endif() |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 580 | |
| 581 | if(ARG_SHARED OR ARG_MODULE) |
| 582 | llvm_externalize_debuginfo(${name}) |
| Justin Bogner | 8fa2608 | 2018-07-10 17:32:48 +0000 | [diff] [blame] | 583 | llvm_codesign(${name}) |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 584 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 585 | endfunction() |
| 586 | |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 587 | function(add_llvm_install_targets target) |
| 588 | cmake_parse_arguments(ARG "" "COMPONENT;PREFIX" "DEPENDS" ${ARGN}) |
| 589 | if(ARG_COMPONENT) |
| 590 | set(component_option -DCMAKE_INSTALL_COMPONENT="${ARG_COMPONENT}") |
| 591 | endif() |
| 592 | if(ARG_PREFIX) |
| 593 | set(prefix_option -DCMAKE_INSTALL_PREFIX="${ARG_PREFIX}") |
| 594 | endif() |
| 595 | |
| 596 | add_custom_target(${target} |
| 597 | DEPENDS ${ARG_DEPENDS} |
| 598 | COMMAND "${CMAKE_COMMAND}" |
| 599 | ${component_option} |
| 600 | ${prefix_option} |
| 601 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" |
| 602 | USES_TERMINAL) |
| 603 | add_custom_target(${target}-stripped |
| 604 | DEPENDS ${ARG_DEPENDS} |
| 605 | COMMAND "${CMAKE_COMMAND}" |
| 606 | ${component_option} |
| 607 | ${prefix_option} |
| 608 | -DCMAKE_INSTALL_DO_STRIP=1 |
| 609 | -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" |
| 610 | USES_TERMINAL) |
| 611 | endfunction() |
| 612 | |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 613 | macro(add_llvm_library name) |
| Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 614 | cmake_parse_arguments(ARG |
| Michael Gottesman | 31e9363 | 2016-09-09 19:45:34 +0000 | [diff] [blame] | 615 | "SHARED;BUILDTREE_ONLY" |
| Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 616 | "" |
| 617 | "" |
| 618 | ${ARGN}) |
| Michael Gottesman | 31e9363 | 2016-09-09 19:45:34 +0000 | [diff] [blame] | 619 | if( BUILD_SHARED_LIBS OR ARG_SHARED ) |
| 620 | llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS}) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 621 | else() |
| Michael Gottesman | 31e9363 | 2016-09-09 19:45:34 +0000 | [diff] [blame] | 622 | llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS}) |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 623 | endif() |
| Michael Gottesman | 31e9363 | 2016-09-09 19:45:34 +0000 | [diff] [blame] | 624 | |
| 625 | # Libraries that are meant to only be exposed via the build tree only are |
| 626 | # never installed and are only exported as a target in the special build tree |
| 627 | # config file. |
| 628 | if (NOT ARG_BUILDTREE_ONLY) |
| Dan Liew | 80189d2 | 2015-06-29 18:45:56 +0000 | [diff] [blame] | 629 | set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) |
| 630 | endif() |
| NAKAMURA Takumi | e7038df | 2014-02-10 09:05:11 +0000 | [diff] [blame] | 631 | |
| Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 632 | if( EXCLUDE_FROM_ALL ) |
| 633 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
| Michael Gottesman | 31e9363 | 2016-09-09 19:45:34 +0000 | [diff] [blame] | 634 | elseif(ARG_BUILDTREE_ONLY) |
| 635 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) |
| 636 | else() |
| Derek Schuff | eb22463 | 2016-09-16 18:50:39 +0000 | [diff] [blame] | 637 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR |
| 638 | (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM")) |
| Sumanth Gundapaneni | 279c73f | 2015-12-16 17:07:15 +0000 | [diff] [blame] | 639 | set(install_dir lib${LLVM_LIBDIR_SUFFIX}) |
| Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 640 | if(ARG_SHARED OR BUILD_SHARED_LIBS) |
| Sumanth Gundapaneni | 279c73f | 2015-12-16 17:07:15 +0000 | [diff] [blame] | 641 | if(WIN32 OR CYGWIN OR MINGW) |
| Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 642 | set(install_type RUNTIME) |
| Sumanth Gundapaneni | 279c73f | 2015-12-16 17:07:15 +0000 | [diff] [blame] | 643 | set(install_dir bin) |
| Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 644 | else() |
| Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 645 | set(install_type LIBRARY) |
| Chris Bieneman | c2368aa | 2015-04-16 17:40:51 +0000 | [diff] [blame] | 646 | endif() |
| Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 647 | else() |
| Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 648 | set(install_type ARCHIVE) |
| Chris Bieneman | 8427169 | 2015-04-16 16:56:18 +0000 | [diff] [blame] | 649 | endif() |
| Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 650 | |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 651 | if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR |
| 652 | NOT LLVM_DISTRIBUTION_COMPONENTS) |
| 653 | set(export_to_llvmexports EXPORT LLVMExports) |
| Justin Bogner | 80bee97 | 2016-11-08 05:02:18 +0000 | [diff] [blame] | 654 | set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True) |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 655 | endif() |
| 656 | |
| Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 657 | install(TARGETS ${name} |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 658 | ${export_to_llvmexports} |
| 659 | ${install_type} DESTINATION ${install_dir} |
| 660 | COMPONENT ${name}) |
| Chris Bieneman | a985e6b | 2015-04-16 18:08:33 +0000 | [diff] [blame] | 661 | |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 662 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 663 | add_llvm_install_targets(install-${name} |
| 664 | DEPENDS ${name} |
| 665 | COMPONENT ${name}) |
| Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 666 | endif() |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 667 | endif() |
| NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 668 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
| Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 669 | endif() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 670 | set_target_properties(${name} PROPERTIES FOLDER "Libraries") |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 671 | endmacro(add_llvm_library name) |
| 672 | |
| Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 673 | macro(add_llvm_loadable_module name) |
| NAKAMURA Takumi | 487f387 | 2014-02-13 11:25:17 +0000 | [diff] [blame] | 674 | llvm_add_library(${name} MODULE ${ARGN}) |
| 675 | if(NOT TARGET ${name}) |
| NAKAMURA Takumi | a8c1c3f | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 676 | # Add empty "phony" target |
| 677 | add_custom_target(${name}) |
| Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 678 | else() |
| Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 679 | if( EXCLUDE_FROM_ALL ) |
| Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 680 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
| Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 681 | else() |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 682 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| NAKAMURA Takumi | 44f64ea | 2014-07-13 13:33:26 +0000 | [diff] [blame] | 683 | if(WIN32 OR CYGWIN) |
| 684 | # DLL platform |
| 685 | set(dlldir "bin") |
| 686 | else() |
| 687 | set(dlldir "lib${LLVM_LIBDIR_SUFFIX}") |
| 688 | endif() |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 689 | |
| 690 | if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR |
| 691 | NOT LLVM_DISTRIBUTION_COMPONENTS) |
| 692 | set(export_to_llvmexports EXPORT LLVMExports) |
| Justin Bogner | 80bee97 | 2016-11-08 05:02:18 +0000 | [diff] [blame] | 693 | set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True) |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 694 | endif() |
| 695 | |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 696 | install(TARGETS ${name} |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 697 | ${export_to_llvmexports} |
| 698 | LIBRARY DESTINATION ${dlldir} |
| 699 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 700 | endif() |
| NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 701 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
| Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 702 | endif() |
| Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 703 | endif() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 704 | |
| 705 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
| Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 706 | endmacro(add_llvm_loadable_module name) |
| 707 | |
| 708 | |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 709 | macro(add_llvm_executable name) |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 710 | cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "DEPENDS" ${ARGN}) |
| Andrew Wilkins | 9211396 | 2015-09-01 03:14:31 +0000 | [diff] [blame] | 711 | llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ) |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 712 | |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 713 | list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS}) |
| 714 | |
| NAKAMURA Takumi | e6bc093 | 2015-08-27 16:10:47 +0000 | [diff] [blame] | 715 | # Generate objlib |
| 716 | if(LLVM_ENABLE_OBJLIB) |
| 717 | # Generate an obj library for both targets. |
| 718 | set(obj_name "obj.${name}") |
| 719 | add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL |
| 720 | ${ALL_FILES} |
| 721 | ) |
| 722 | llvm_update_compile_flags(${obj_name}) |
| 723 | set(ALL_FILES "$<TARGET_OBJECTS:${obj_name}>") |
| 724 | |
| 725 | set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries") |
| 726 | endif() |
| 727 | |
| NAKAMURA Takumi | b5288ba | 2015-08-28 00:36:58 +0000 | [diff] [blame] | 728 | add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) |
| 729 | |
| Jordan Rose | 3d75297 | 2015-09-10 17:18:51 +0000 | [diff] [blame] | 730 | if(XCODE) |
| 731 | # Note: the dummy.cpp source file provides no definitions. However, |
| 732 | # it forces Xcode to properly link the static library. |
| Jordan Rose | 85a22f8 | 2015-09-10 17:55:02 +0000 | [diff] [blame] | 733 | list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp") |
| Jordan Rose | 3d75297 | 2015-09-10 17:18:51 +0000 | [diff] [blame] | 734 | endif() |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 735 | |
| Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 736 | if( EXCLUDE_FROM_ALL ) |
| 737 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 738 | else() |
| 739 | add_executable(${name} ${ALL_FILES}) |
| 740 | endif() |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 741 | |
| Chris Bieneman | 958edcb | 2016-11-19 01:32:09 +0000 | [diff] [blame] | 742 | setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS}) |
| 743 | |
| Jonas Hahnfeld | 277a09d | 2016-11-03 06:58:16 +0000 | [diff] [blame] | 744 | if(NOT ARG_NO_INSTALL_RPATH) |
| 745 | llvm_setup_rpath(${name}) |
| 746 | endif() |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 747 | |
| Greg Bedwell | 95213c3 | 2015-06-12 15:58:29 +0000 | [diff] [blame] | 748 | if(DEFINED windows_resource_file) |
| 749 | set_windows_version_resource_properties(${name} ${windows_resource_file}) |
| 750 | endif() |
| 751 | |
| NAKAMURA Takumi | bb7483d | 2015-09-08 07:42:06 +0000 | [diff] [blame] | 752 | # $<TARGET_OBJECTS> doesn't require compile flags. |
| 753 | if(NOT LLVM_ENABLE_OBJLIB) |
| 754 | llvm_update_compile_flags(${name}) |
| 755 | endif() |
| Rafael Espindola | 8cb7876 | 2014-11-02 12:14:22 +0000 | [diff] [blame] | 756 | add_link_opts( ${name} ) |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 757 | |
| Richard Smith | 2b91a7f | 2014-09-26 22:40:15 +0000 | [diff] [blame] | 758 | # Do not add -Dname_EXPORTS to the command-line when building files in this |
| 759 | # target. Doing so is actively harmful for the modules build because it |
| 760 | # creates extra module variants, and not useful because we don't use these |
| 761 | # macros. |
| 762 | set_target_properties( ${name} PROPERTIES DEFINE_SYMBOL "" ) |
| 763 | |
| Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 764 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 765 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 766 | endif(LLVM_EXPORTED_SYMBOL_FILE) |
| 767 | |
| Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 768 | if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) |
| 769 | set(USE_SHARED USE_SHARED) |
| 770 | endif() |
| 771 | |
| Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 772 | set(EXCLUDE_FROM_ALL OFF) |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 773 | set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
| Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 774 | llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} ) |
| Oscar Fuentes | 3fca0e8 | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 775 | if( LLVM_COMMON_DEPENDS ) |
| 776 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 777 | endif( LLVM_COMMON_DEPENDS ) |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 778 | |
| Chris Bieneman | 48eaa54 | 2015-12-08 21:51:48 +0000 | [diff] [blame] | 779 | if(NOT ARG_IGNORE_EXTERNALIZE_DEBUGINFO) |
| 780 | llvm_externalize_debuginfo(${name}) |
| 781 | endif() |
| Eric Fiselier | 87c87f4 | 2017-02-10 01:59:20 +0000 | [diff] [blame] | 782 | if (LLVM_PTHREAD_LIB) |
| Artem Belevich | df7103d | 2016-06-21 19:34:40 +0000 | [diff] [blame] | 783 | # libpthreads overrides some standard library symbols, so main |
| 784 | # executable must be linked with it in order to provide consistent |
| 785 | # API for all shared libaries loaded by this executable. |
| Shoaib Meenai | d806af3 | 2017-12-05 21:49:56 +0000 | [diff] [blame] | 786 | target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) |
| Artem Belevich | df7103d | 2016-06-21 19:34:40 +0000 | [diff] [blame] | 787 | endif() |
| Justin Bogner | 8fa2608 | 2018-07-10 17:32:48 +0000 | [diff] [blame] | 788 | |
| 789 | llvm_codesign(${name}) |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 790 | endmacro(add_llvm_executable name) |
| 791 | |
| Reid Kleckner | 3e8c445 | 2015-03-18 20:09:13 +0000 | [diff] [blame] | 792 | function(export_executable_symbols target) |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 793 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 794 | # The symbol file should contain the symbols we want the executable to |
| 795 | # export |
| 796 | set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) |
| 797 | elseif (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS) |
| 798 | # Extract the symbols to export from the static libraries that the |
| 799 | # executable links against. |
| 800 | set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) |
| 801 | set(exported_symbol_file ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${target}.symbols) |
| 802 | # We need to consider not just the direct link dependencies, but also the |
| 803 | # transitive link dependencies. Do this by starting with the set of direct |
| 804 | # dependencies, then the dependencies of those dependencies, and so on. |
| 805 | get_target_property(new_libs ${target} LINK_LIBRARIES) |
| 806 | set(link_libs ${new_libs}) |
| 807 | while(NOT "${new_libs}" STREQUAL "") |
| 808 | foreach(lib ${new_libs}) |
| John Brawn | 24ca18e | 2016-07-05 13:16:54 +0000 | [diff] [blame] | 809 | if(TARGET ${lib}) |
| 810 | get_target_property(lib_type ${lib} TYPE) |
| 811 | if("${lib_type}" STREQUAL "STATIC_LIBRARY") |
| 812 | list(APPEND static_libs ${lib}) |
| 813 | else() |
| 814 | list(APPEND other_libs ${lib}) |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 815 | endif() |
| John Brawn | 24ca18e | 2016-07-05 13:16:54 +0000 | [diff] [blame] | 816 | get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES) |
| 817 | foreach(transitive_lib ${transitive_libs}) |
| 818 | list(FIND link_libs ${transitive_lib} idx) |
| 819 | if(TARGET ${transitive_lib} AND idx EQUAL -1) |
| 820 | list(APPEND newer_libs ${transitive_lib}) |
| 821 | list(APPEND link_libs ${transitive_lib}) |
| 822 | endif() |
| 823 | endforeach(transitive_lib) |
| 824 | endif() |
| John Brawn | 3546c2f | 2016-05-26 11:16:43 +0000 | [diff] [blame] | 825 | endforeach(lib) |
| 826 | set(new_libs ${newer_libs}) |
| 827 | set(newer_libs "") |
| 828 | endwhile() |
| 829 | if (MSVC) |
| 830 | set(mangling microsoft) |
| 831 | else() |
| 832 | set(mangling itanium) |
| 833 | endif() |
| 834 | add_custom_command(OUTPUT ${exported_symbol_file} |
| 835 | COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file} |
| 836 | WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} |
| 837 | DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs} |
| 838 | VERBATIM |
| 839 | COMMENT "Generating export list for ${target}") |
| 840 | add_llvm_symbol_exports( ${target} ${exported_symbol_file} ) |
| 841 | # If something links against this executable then we want a |
| 842 | # transitive link against only the libraries whose symbols |
| 843 | # we aren't exporting. |
| 844 | set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${other_libs}") |
| 845 | # The default import library suffix that cmake uses for cygwin/mingw is |
| 846 | # ".dll.a", but for clang.exe that causes a collision with libclang.dll, |
| 847 | # where the import libraries of both get named libclang.dll.a. Use a suffix |
| 848 | # of ".exe.a" to avoid this. |
| 849 | if(CYGWIN OR MINGW) |
| 850 | set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".exe.a") |
| 851 | endif() |
| 852 | elseif(NOT (WIN32 OR CYGWIN)) |
| 853 | # On Windows auto-exporting everything doesn't work because of the limit on |
| 854 | # the size of the exported symbol table, but on other platforms we can do |
| 855 | # it without any trouble. |
| Reid Kleckner | 3e8c445 | 2015-03-18 20:09:13 +0000 | [diff] [blame] | 856 | set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1) |
| Chris Bieneman | 914742b | 2015-11-24 00:58:58 +0000 | [diff] [blame] | 857 | if (APPLE) |
| Chris Bieneman | ccabd0e | 2015-12-03 22:51:08 +0000 | [diff] [blame] | 858 | set_property(TARGET ${target} APPEND_STRING PROPERTY |
| Chris Bieneman | ac6677a | 2015-12-03 22:55:36 +0000 | [diff] [blame] | 859 | LINK_FLAGS " -rdynamic") |
| Chris Bieneman | 914742b | 2015-11-24 00:58:58 +0000 | [diff] [blame] | 860 | endif() |
| Reid Kleckner | 3e8c445 | 2015-03-18 20:09:13 +0000 | [diff] [blame] | 861 | endif() |
| 862 | endfunction() |
| 863 | |
| Chris Bieneman | 170fd9cb | 2015-09-10 17:23:32 +0000 | [diff] [blame] | 864 | if(NOT LLVM_TOOLCHAIN_TOOLS) |
| 865 | set (LLVM_TOOLCHAIN_TOOLS |
| 866 | llvm-ar |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 867 | llvm-ranlib |
| 868 | llvm-lib |
| Chris Bieneman | 170fd9cb | 2015-09-10 17:23:32 +0000 | [diff] [blame] | 869 | llvm-objdump |
| Hans Wennborg | f23db0d | 2018-08-01 07:51:55 +0000 | [diff] [blame] | 870 | llvm-rc |
| Chris Bieneman | 170fd9cb | 2015-09-10 17:23:32 +0000 | [diff] [blame] | 871 | ) |
| 872 | endif() |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 873 | |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 874 | macro(add_llvm_tool name) |
| Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 875 | if( NOT LLVM_BUILD_TOOLS ) |
| Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 876 | set(EXCLUDE_FROM_ALL ON) |
| 877 | endif() |
| Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 878 | add_llvm_executable(${name} ${ARGN}) |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 879 | |
| Chris Bieneman | 44d2990 | 2016-09-27 17:47:24 +0000 | [diff] [blame] | 880 | if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 881 | if( LLVM_BUILD_TOOLS ) |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 882 | if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR |
| 883 | NOT LLVM_DISTRIBUTION_COMPONENTS) |
| 884 | set(export_to_llvmexports EXPORT LLVMExports) |
| Justin Bogner | 80bee97 | 2016-11-08 05:02:18 +0000 | [diff] [blame] | 885 | set_property(GLOBAL PROPERTY LLVM_HAS_EXPORTS True) |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 886 | endif() |
| 887 | |
| NAKAMURA Takumi | ef97607 | 2014-02-09 16:36:03 +0000 | [diff] [blame] | 888 | install(TARGETS ${name} |
| Justin Bogner | 4ce3e0c | 2016-11-04 21:55:23 +0000 | [diff] [blame] | 889 | ${export_to_llvmexports} |
| Chris Bieneman | 2724f14 | 2016-06-08 21:19:26 +0000 | [diff] [blame] | 890 | RUNTIME DESTINATION ${LLVM_TOOLS_INSTALL_DIR} |
| Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 891 | COMPONENT ${name}) |
| 892 | |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 893 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 894 | add_llvm_install_targets(install-${name} |
| 895 | DEPENDS ${name} |
| 896 | COMPONENT ${name}) |
| Chris Bieneman | 0d9289d | 2015-02-18 19:25:47 +0000 | [diff] [blame] | 897 | endif() |
| Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 898 | endif() |
| Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 899 | endif() |
| NAKAMURA Takumi | 8faf660 | 2014-02-09 16:36:16 +0000 | [diff] [blame] | 900 | if( LLVM_BUILD_TOOLS ) |
| 901 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
| 902 | endif() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 903 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 904 | endmacro(add_llvm_tool name) |
| 905 | |
| 906 | |
| 907 | macro(add_llvm_example name) |
| Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 908 | if( NOT LLVM_BUILD_EXAMPLES ) |
| Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 909 | set(EXCLUDE_FROM_ALL ON) |
| 910 | endif() |
| Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 911 | add_llvm_executable(${name} ${ARGN}) |
| Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 912 | if( LLVM_BUILD_EXAMPLES ) |
| 913 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 914 | endif() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 915 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
| Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 916 | endmacro(add_llvm_example name) |
| Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 917 | |
| Michael Gottesman | be5b787 | 2016-07-10 02:43:47 +0000 | [diff] [blame] | 918 | # This is a macro that is used to create targets for executables that are needed |
| 919 | # for development, but that are not intended to be installed by default. |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 920 | macro(add_llvm_utility name) |
| Michael Gottesman | be5b787 | 2016-07-10 02:43:47 +0000 | [diff] [blame] | 921 | if ( NOT LLVM_BUILD_UTILS ) |
| 922 | set(EXCLUDE_FROM_ALL ON) |
| 923 | endif() |
| 924 | |
| Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 925 | add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN}) |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 926 | set_target_properties(${name} PROPERTIES FOLDER "Utils") |
| Michael Gottesman | be5b787 | 2016-07-10 02:43:47 +0000 | [diff] [blame] | 927 | if( LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS ) |
| Derek Schuff | ef9928e | 2015-03-27 16:53:06 +0000 | [diff] [blame] | 928 | install (TARGETS ${name} |
| Tom Stellard | edd69bc | 2017-07-05 12:57:30 +0000 | [diff] [blame] | 929 | RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR} |
| Derek Schuff | ef9928e | 2015-03-27 16:53:06 +0000 | [diff] [blame] | 930 | COMPONENT ${name}) |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 931 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 932 | add_llvm_install_targets(install-${name} |
| 933 | DEPENDS ${name} |
| 934 | COMPONENT ${name}) |
| Derek Schuff | ef9928e | 2015-03-27 16:53:06 +0000 | [diff] [blame] | 935 | endif() |
| 936 | endif() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 937 | endmacro(add_llvm_utility name) |
| 938 | |
| Justin Bogner | 5204717 | 2017-08-31 00:36:33 +0000 | [diff] [blame] | 939 | macro(add_llvm_fuzzer name) |
| Justin Bogner | c3b67fb | 2017-09-01 17:02:22 +0000 | [diff] [blame] | 940 | cmake_parse_arguments(ARG "" "DUMMY_MAIN" "" ${ARGN}) |
| Matt Morehouse | 5436866 | 2017-10-12 21:58:41 +0000 | [diff] [blame] | 941 | if( LLVM_LIB_FUZZING_ENGINE ) |
| 942 | set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) |
| 943 | add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) |
| Matt Morehouse | 492a5b4 | 2017-12-06 23:32:46 +0000 | [diff] [blame] | 944 | target_link_libraries(${name} PRIVATE ${LLVM_LIB_FUZZING_ENGINE}) |
| Matt Morehouse | 5436866 | 2017-10-12 21:58:41 +0000 | [diff] [blame] | 945 | set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") |
| 946 | elseif( LLVM_USE_SANITIZE_COVERAGE ) |
| Justin Bogner | 5204717 | 2017-08-31 00:36:33 +0000 | [diff] [blame] | 947 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer") |
| Justin Bogner | 7f28d73 | 2017-09-02 23:43:04 +0000 | [diff] [blame] | 948 | set(LLVM_OPTIONAL_SOURCES ${ARG_DUMMY_MAIN}) |
| Justin Bogner | c3b67fb | 2017-09-01 17:02:22 +0000 | [diff] [blame] | 949 | add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS}) |
| Justin Bogner | 5204717 | 2017-08-31 00:36:33 +0000 | [diff] [blame] | 950 | set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") |
| Justin Bogner | c3b67fb | 2017-09-01 17:02:22 +0000 | [diff] [blame] | 951 | elseif( ARG_DUMMY_MAIN ) |
| 952 | add_llvm_executable(${name} ${ARG_DUMMY_MAIN} ${ARG_UNPARSED_ARGUMENTS}) |
| 953 | set_target_properties(${name} PROPERTIES FOLDER "Fuzzers") |
| Matt Morehouse | 5436866 | 2017-10-12 21:58:41 +0000 | [diff] [blame] | 954 | endif() |
| Justin Bogner | 5204717 | 2017-08-31 00:36:33 +0000 | [diff] [blame] | 955 | endmacro() |
| Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 956 | |
| Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 957 | macro(add_llvm_target target_name) |
| Oscar Fuentes | 4f0f335 | 2011-07-25 20:17:01 +0000 | [diff] [blame] | 958 | include_directories(BEFORE |
| 959 | ${CMAKE_CURRENT_BINARY_DIR} |
| 960 | ${CMAKE_CURRENT_SOURCE_DIR}) |
| NAKAMURA Takumi | 45374cc | 2014-03-04 17:05:28 +0000 | [diff] [blame] | 961 | add_llvm_library(LLVM${target_name} ${ARGN}) |
| Oscar Fuentes | ba1186c | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 962 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
| Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 963 | endmacro(add_llvm_target) |
| Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 964 | |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 965 | function(canonicalize_tool_name name output) |
| 966 | string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" nameStrip ${name}) |
| 967 | string(REPLACE "-" "_" nameUNDERSCORE ${nameStrip}) |
| 968 | string(TOUPPER ${nameUNDERSCORE} nameUPPER) |
| 969 | set(${output} "${nameUPPER}" PARENT_SCOPE) |
| 970 | endfunction(canonicalize_tool_name) |
| 971 | |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 972 | # Custom add_subdirectory wrapper |
| Tobias Grosser | e3421b5 | 2016-04-29 13:03:40 +0000 | [diff] [blame] | 973 | # Takes in a project name (i.e. LLVM), the subdirectory name, and an optional |
| 974 | # path if it differs from the name. |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 975 | macro(add_llvm_subdirectory project type name) |
| NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 976 | set(add_llvm_external_dir "${ARGN}") |
| 977 | if("${add_llvm_external_dir}" STREQUAL "") |
| 978 | set(add_llvm_external_dir ${name}) |
| 979 | endif() |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 980 | canonicalize_tool_name(${name} nameUPPER) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 981 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir}/CMakeLists.txt) |
| 982 | # Treat it as in-tree subproject. |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 983 | option(${project}_${type}_${nameUPPER}_BUILD |
| 984 | "Whether to build ${name} as part of ${project}" On) |
| 985 | mark_as_advanced(${project}_${type}_${name}_BUILD) |
| 986 | if(${project}_${type}_${nameUPPER}_BUILD) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 987 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${add_llvm_external_dir} ${add_llvm_external_dir}) |
| 988 | # Don't process it in add_llvm_implicit_projects(). |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 989 | set(${project}_${type}_${nameUPPER}_BUILD OFF) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 990 | endif() |
| 991 | else() |
| 992 | set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR |
| 993 | "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" |
| 994 | CACHE PATH "Path to ${name} source directory") |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 995 | set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT ON) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 996 | if(NOT LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR OR NOT EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}) |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 997 | set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 998 | endif() |
| 999 | if("${LLVM_EXTERNAL_${nameUPPER}_BUILD}" STREQUAL "OFF") |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1000 | set(${project}_${type}_${nameUPPER}_BUILD_DEFAULT OFF) |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 1001 | endif() |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1002 | option(${project}_${type}_${nameUPPER}_BUILD |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 1003 | "Whether to build ${name} as part of LLVM" |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1004 | ${${project}_${type}_${nameUPPER}_BUILD_DEFAULT}) |
| 1005 | if (${project}_${type}_${nameUPPER}_BUILD) |
| NAKAMURA Takumi | 6fa8532 | 2015-08-22 05:11:02 +0000 | [diff] [blame] | 1006 | if(EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}) |
| 1007 | add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir}) |
| 1008 | elseif(NOT "${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}" STREQUAL "") |
| 1009 | message(WARNING "Nonexistent directory for ${name}: ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}") |
| 1010 | endif() |
| NAKAMURA Takumi | 04e2da5 | 2015-08-22 04:53:52 +0000 | [diff] [blame] | 1011 | # FIXME: It'd be redundant. |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1012 | set(${project}_${type}_${nameUPPER}_BUILD Off) |
| Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 1013 | endif() |
| 1014 | endif() |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1015 | endmacro() |
| 1016 | |
| 1017 | # Add external project that may want to be built as part of llvm such as Clang, |
| 1018 | # lld, and Polly. This adds two options. One for the source directory of the |
| 1019 | # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to |
| 1020 | # enable or disable building it with everything else. |
| 1021 | # Additional parameter can be specified as the name of directory. |
| 1022 | macro(add_llvm_external_project name) |
| Manuel Klimek | f80abb9 | 2015-10-22 08:31:46 +0000 | [diff] [blame] | 1023 | add_llvm_subdirectory(LLVM TOOL ${name} ${ARGN}) |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1024 | endmacro() |
| Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 1025 | |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1026 | macro(add_llvm_tool_subdirectory name) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1027 | add_llvm_external_project(${name}) |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1028 | endmacro(add_llvm_tool_subdirectory) |
| 1029 | |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1030 | function(get_project_name_from_src_var var output) |
| 1031 | string(REGEX MATCH "LLVM_EXTERNAL_(.*)_SOURCE_DIR" |
| 1032 | MACHED_TOOL "${var}") |
| 1033 | if(MACHED_TOOL) |
| 1034 | set(${output} ${CMAKE_MATCH_1} PARENT_SCOPE) |
| 1035 | else() |
| 1036 | set(${output} PARENT_SCOPE) |
| 1037 | endif() |
| 1038 | endfunction() |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1039 | |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1040 | function(create_subdirectory_options project type) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1041 | file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") |
| 1042 | foreach(dir ${sub-dirs}) |
| 1043 | if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt") |
| 1044 | canonicalize_tool_name(${dir} name) |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1045 | option(${project}_${type}_${name}_BUILD |
| 1046 | "Whether to build ${name} as part of ${project}" On) |
| 1047 | mark_as_advanced(${project}_${type}_${name}_BUILD) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1048 | endif() |
| 1049 | endforeach() |
| Chris Bieneman | 70997c3 | 2015-10-20 16:42:58 +0000 | [diff] [blame] | 1050 | endfunction(create_subdirectory_options) |
| 1051 | |
| 1052 | function(create_llvm_tool_options) |
| 1053 | create_subdirectory_options(LLVM TOOL) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1054 | endfunction(create_llvm_tool_options) |
| 1055 | |
| Chris Bieneman | 74c98f0 | 2016-03-08 18:43:28 +0000 | [diff] [blame] | 1056 | function(llvm_add_implicit_projects project) |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1057 | set(list_of_implicit_subdirs "") |
| 1058 | file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") |
| 1059 | foreach(dir ${sub-dirs}) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1060 | if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt") |
| 1061 | canonicalize_tool_name(${dir} name) |
| Chris Bieneman | 74c98f0 | 2016-03-08 18:43:28 +0000 | [diff] [blame] | 1062 | if (${project}_TOOL_${name}_BUILD) |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1063 | get_filename_component(fn "${dir}" NAME) |
| 1064 | list(APPEND list_of_implicit_subdirs "${fn}") |
| 1065 | endif() |
| 1066 | endif() |
| 1067 | endforeach() |
| 1068 | |
| 1069 | foreach(external_proj ${list_of_implicit_subdirs}) |
| Chris Bieneman | 74c98f0 | 2016-03-08 18:43:28 +0000 | [diff] [blame] | 1070 | add_llvm_subdirectory(${project} TOOL "${external_proj}" ${ARGN}) |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1071 | endforeach() |
| Chris Bieneman | 74c98f0 | 2016-03-08 18:43:28 +0000 | [diff] [blame] | 1072 | endfunction(llvm_add_implicit_projects) |
| 1073 | |
| 1074 | function(add_llvm_implicit_projects) |
| 1075 | llvm_add_implicit_projects(LLVM) |
| Chris Bieneman | 580d815 | 2015-07-20 20:36:06 +0000 | [diff] [blame] | 1076 | endfunction(add_llvm_implicit_projects) |
| Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 1077 | |
| Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 1078 | # Generic support for adding a unittest. |
| Chandler Carruth | 94d0251 | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 1079 | function(add_unittest test_suite test_name) |
| Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 1080 | if( NOT LLVM_BUILD_TESTS ) |
| 1081 | set(EXCLUDE_FROM_ALL ON) |
| 1082 | endif() |
| 1083 | |
| Zachary Turner | 94f5032 | 2017-10-27 21:12:28 +0000 | [diff] [blame] | 1084 | # Our current version of gtest does not properly recognize C++11 support |
| 1085 | # with MSVC, so it falls back to tr1 / experimental classes. Since LLVM |
| 1086 | # itself requires C++11, we can safely force it on unconditionally so that |
| Kirill Bobyrev | 0addd17 | 2018-08-28 09:42:41 +0000 | [diff] [blame] | 1087 | # we don't have to fight with the buggy gtest check. |
| Zachary Turner | 94f5032 | 2017-10-27 21:12:28 +0000 | [diff] [blame] | 1088 | add_definitions(-DGTEST_LANG_CXX11=1) |
| 1089 | add_definitions(-DGTEST_HAS_TR1_TUPLE=0) |
| 1090 | |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 1091 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) |
| Chandler Carruth | bf6a4e0 | 2017-01-10 22:32:26 +0000 | [diff] [blame] | 1092 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include) |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 1093 | if (NOT LLVM_ENABLE_THREADS) |
| 1094 | list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0) |
| 1095 | endif () |
| 1096 | |
| Chandler Carruth | 25657e8 | 2017-01-06 23:16:00 +0000 | [diff] [blame] | 1097 | if (SUPPORTS_VARIADIC_MACROS_FLAG) |
| NAKAMURA Takumi | 13961cb | 2014-01-30 22:55:25 +0000 | [diff] [blame] | 1098 | list(APPEND LLVM_COMPILE_FLAGS "-Wno-variadic-macros") |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 1099 | endif () |
| Chandler Carruth | dd9c27b | 2017-01-04 23:40:06 +0000 | [diff] [blame] | 1100 | # Some parts of gtest rely on this GNU extension, don't warn on it. |
| Chandler Carruth | 25657e8 | 2017-01-06 23:16:00 +0000 | [diff] [blame] | 1101 | if(SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG) |
| Chandler Carruth | dd9c27b | 2017-01-04 23:40:06 +0000 | [diff] [blame] | 1102 | list(APPEND LLVM_COMPILE_FLAGS "-Wno-gnu-zero-variadic-macro-arguments") |
| 1103 | endif() |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 1104 | |
| NAKAMURA Takumi | a679f43 | 2014-01-28 09:44:06 +0000 | [diff] [blame] | 1105 | set(LLVM_REQUIRES_RTTI OFF) |
| NAKAMURA Takumi | e42fd0d | 2014-01-07 10:24:14 +0000 | [diff] [blame] | 1106 | |
| Andrew Wilkins | 095e22d | 2016-02-12 01:42:43 +0000 | [diff] [blame] | 1107 | list(APPEND LLVM_LINK_COMPONENTS Support) # gtest needs it for raw_ostream |
| Jonas Hahnfeld | 277a09d | 2016-11-03 06:58:16 +0000 | [diff] [blame] | 1108 | add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN}) |
| NAKAMURA Takumi | baa9f53 | 2013-12-30 06:48:30 +0000 | [diff] [blame] | 1109 | set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) |
| John Brawn | c11ef2a | 2015-09-30 15:20:51 +0000 | [diff] [blame] | 1110 | set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) |
| Artem Belevich | df7103d | 2016-06-21 19:34:40 +0000 | [diff] [blame] | 1111 | # libpthreads overrides some standard library symbols, so main |
| 1112 | # executable must be linked with it in order to provide consistent |
| 1113 | # API for all shared libaries loaded by this executable. |
| Shoaib Meenai | d806af3 | 2017-12-05 21:49:56 +0000 | [diff] [blame] | 1114 | target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB}) |
| Lion Yang | 7bff00e | 2018-09-14 19:43:11 +0000 | [diff] [blame] | 1115 | |
| Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 1116 | add_dependencies(${test_suite} ${test_name}) |
| 1117 | get_target_property(test_suite_folder ${test_suite} FOLDER) |
| 1118 | if (NOT ${test_suite_folder} STREQUAL "NOTFOUND") |
| 1119 | set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}") |
| 1120 | endif () |
| Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 1121 | endfunction() |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1122 | |
| Nico Weber | 1739dbf | 2018-09-14 17:34:46 +0000 | [diff] [blame] | 1123 | # Use for test binaries that call llvm::getInputFileDirectory(). Use of this |
| 1124 | # is discouraged. |
| 1125 | function(add_unittest_with_input_files test_suite test_name) |
| 1126 | set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 1127 | configure_file( |
| 1128 | ${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in |
| 1129 | ${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt) |
| 1130 | |
| 1131 | add_unittest(${test_suite} ${test_name} ${ARGN}) |
| 1132 | endfunction() |
| Zachary Turner | e9f1df8 | 2018-09-05 23:30:17 +0000 | [diff] [blame] | 1133 | |
| Kirill Bobyrev | 0addd17 | 2018-08-28 09:42:41 +0000 | [diff] [blame] | 1134 | # Generic support for adding a benchmark. |
| 1135 | function(add_benchmark benchmark_name) |
| 1136 | if( NOT LLVM_BUILD_BENCHMARKS ) |
| 1137 | set(EXCLUDE_FROM_ALL ON) |
| 1138 | endif() |
| 1139 | |
| 1140 | add_llvm_executable(${benchmark_name} IGNORE_EXTERNALIZE_DEBUGINFO NO_INSTALL_RPATH ${ARGN}) |
| 1141 | set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) |
| 1142 | set_output_directory(${benchmark_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) |
| Aaron Ballman | d7e83e7 | 2018-09-21 23:01:32 +0000 | [diff] [blame] | 1143 | set_property(TARGET ${benchmark_name} PROPERTY FOLDER "Utils") |
| Kirill Bobyrev | 0addd17 | 2018-08-28 09:42:41 +0000 | [diff] [blame] | 1144 | target_link_libraries(${benchmark_name} PRIVATE benchmark) |
| 1145 | endfunction() |
| 1146 | |
| Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 1147 | function(llvm_add_go_executable binary pkgpath) |
| 1148 | cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN}) |
| 1149 | |
| 1150 | if(LLVM_BINDINGS MATCHES "go") |
| 1151 | # FIXME: This should depend only on the libraries Go needs. |
| 1152 | get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS) |
| 1153 | set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX}) |
| 1154 | set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") |
| 1155 | set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") |
| Chandler Carruth | cab512d | 2014-12-29 22:50:30 +0000 | [diff] [blame] | 1156 | set(cppflags "") |
| 1157 | get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES) |
| 1158 | foreach(d ${include_dirs}) |
| 1159 | set(cppflags "${cppflags} -I${d}") |
| 1160 | endforeach(d) |
| Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 1161 | set(ldflags "${CMAKE_EXE_LINKER_FLAGS}") |
| 1162 | add_custom_command(OUTPUT ${binpath} |
| Andrew Wilkins | 5bf7d81 | 2016-07-27 03:21:51 +0000 | [diff] [blame] | 1163 | COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "go=${GO_EXECUTABLE}" "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}" "packages=${LLVM_GO_PACKAGES}" |
| Peter Collingbourne | a4f0bd7 | 2014-11-27 00:15:21 +0000 | [diff] [blame] | 1164 | ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath} |
| 1165 | DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX} |
| 1166 | ${llvmlibs} ${ARG_DEPENDS} |
| 1167 | COMMENT "Building Go executable ${binary}" |
| 1168 | VERBATIM) |
| 1169 | if (ARG_ALL) |
| 1170 | add_custom_target(${binary} ALL DEPENDS ${binpath}) |
| 1171 | else() |
| 1172 | add_custom_target(${binary} DEPENDS ${binpath}) |
| 1173 | endif() |
| 1174 | endif() |
| 1175 | endfunction() |
| 1176 | |
| Michal Gorny | 9283f5b | 2017-01-06 21:33:48 +0000 | [diff] [blame] | 1177 | # This function canonicalize the CMake variables passed by names |
| 1178 | # from CMake boolean to 0/1 suitable for passing into Python or C++, |
| 1179 | # in place. |
| 1180 | function(llvm_canonicalize_cmake_booleans) |
| 1181 | foreach(var ${ARGN}) |
| 1182 | if(${var}) |
| 1183 | set(${var} 1 PARENT_SCOPE) |
| 1184 | else() |
| 1185 | set(${var} 0 PARENT_SCOPE) |
| 1186 | endif() |
| 1187 | endforeach() |
| 1188 | endfunction(llvm_canonicalize_cmake_booleans) |
| 1189 | |
| Greg Bedwell | 99e183c | 2017-11-13 12:40:05 +0000 | [diff] [blame] | 1190 | macro(set_llvm_build_mode) |
| 1191 | # Configuration-time: See Unit/lit.site.cfg.in |
| 1192 | if (CMAKE_CFG_INTDIR STREQUAL ".") |
| 1193 | set(LLVM_BUILD_MODE ".") |
| 1194 | else () |
| 1195 | set(LLVM_BUILD_MODE "%(build_mode)s") |
| 1196 | endif () |
| 1197 | endmacro() |
| 1198 | |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1199 | # This function provides an automatic way to 'configure'-like generate a file |
| Alp Toker | 171b0c3 | 2013-12-20 00:33:39 +0000 | [diff] [blame] | 1200 | # based on a set of common and custom variables, specifically targeting the |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1201 | # variables needed for the 'lit.site.cfg' files. This function bundles the |
| 1202 | # common variables that any Lit instance is likely to need, and custom |
| 1203 | # variables can be passed in. |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1204 | function(configure_lit_site_cfg site_in site_out) |
| Zachary Turner | 71deeee | 2017-09-21 16:18:28 +0000 | [diff] [blame] | 1205 | cmake_parse_arguments(ARG "" "" "MAIN_CONFIG;OUTPUT_MAPPING" ${ARGN}) |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1206 | |
| 1207 | if ("${ARG_MAIN_CONFIG}" STREQUAL "") |
| Zachary Turner | 71deeee | 2017-09-21 16:18:28 +0000 | [diff] [blame] | 1208 | get_filename_component(INPUT_DIR ${site_in} DIRECTORY) |
| 1209 | set(ARG_MAIN_CONFIG "${INPUT_DIR}/lit.cfg") |
| 1210 | endif() |
| 1211 | if ("${ARG_OUTPUT_MAPPING}" STREQUAL "") |
| 1212 | set(ARG_OUTPUT_MAPPING "${site_out}") |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1213 | endif() |
| 1214 | |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1215 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 1216 | set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") |
| 1217 | endforeach(c) |
| 1218 | set(TARGETS_TO_BUILD ${TARGETS_BUILT}) |
| 1219 | |
| 1220 | set(SHLIBEXT "${LTDL_SHLIB_EXT}") |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1221 | |
| Greg Bedwell | 99e183c | 2017-11-13 12:40:05 +0000 | [diff] [blame] | 1222 | set_llvm_build_mode() |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1223 | |
| NAKAMURA Takumi | 3c6f5cd | 2014-01-26 06:18:56 +0000 | [diff] [blame] | 1224 | # They below might not be the build tree but provided binary tree. |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1225 | set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) |
| 1226 | set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR}) |
| Zachary Turner | 50105d2 | 2017-09-19 17:19:10 +0000 | [diff] [blame] | 1227 | string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}") |
| 1228 | 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] | 1229 | |
| 1230 | # SHLIBDIR points the build tree. |
| Zachary Turner | 50105d2 | 2017-09-19 17:19:10 +0000 | [diff] [blame] | 1231 | 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] | 1232 | |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1233 | set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) |
| NAKAMURA Takumi | 8d7a173 | 2014-07-04 04:45:40 +0000 | [diff] [blame] | 1234 | # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for |
| 1235 | # plugins. We may rename it. |
| 1236 | if(LLVM_ENABLE_PLUGINS) |
| 1237 | set(ENABLE_SHARED "1") |
| 1238 | else() |
| 1239 | set(ENABLE_SHARED "0") |
| 1240 | endif() |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1241 | |
| 1242 | if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE) |
| 1243 | set(ENABLE_ASSERTIONS "1") |
| 1244 | else() |
| 1245 | set(ENABLE_ASSERTIONS "0") |
| 1246 | endif() |
| 1247 | |
| Kuba Brecka | a62bbcc | 2015-01-24 01:42:44 +0000 | [diff] [blame] | 1248 | set(HOST_OS ${CMAKE_SYSTEM_NAME}) |
| Tim Northover | bfe8468 | 2013-02-14 16:49:32 +0000 | [diff] [blame] | 1249 | set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1250 | |
| Peter Collingbourne | ce80084 | 2014-10-17 18:32:36 +0000 | [diff] [blame] | 1251 | set(HOST_CC "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}") |
| 1252 | set(HOST_CXX "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") |
| Chandler Carruth | 9719242 | 2014-10-21 00:36:28 +0000 | [diff] [blame] | 1253 | set(HOST_LDFLAGS "${CMAKE_EXE_LINKER_FLAGS}") |
| Peter Collingbourne | 82e3e37 | 2014-10-16 22:48:02 +0000 | [diff] [blame] | 1254 | |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1255 | set(LIT_SITE_CFG_IN_HEADER "## Autogenerated from ${site_in}\n## Do not edit!") |
| Alex Denisov | d5cee4a | 2016-04-16 06:47:41 +0000 | [diff] [blame] | 1256 | |
| NAKAMURA Takumi | fc7f3b7 | 2017-06-17 03:19:08 +0000 | [diff] [blame] | 1257 | # Override config_target_triple (and the env) |
| 1258 | if(LLVM_TARGET_TRIPLE_ENV) |
| 1259 | # This is expanded into the heading. |
| 1260 | string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n" |
| 1261 | "import os\n" |
| 1262 | "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n" |
| 1263 | "config.target_triple = config.environment[target_env] = os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n" |
| 1264 | ) |
| 1265 | |
| 1266 | # This is expanded to; config.target_triple = ""+config.target_triple+"" |
| 1267 | set(TARGET_TRIPLE "\"+config.target_triple+\"") |
| 1268 | endif() |
| 1269 | |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1270 | configure_file(${site_in} ${site_out} @ONLY) |
| Zachary Turner | 957d611 | 2017-09-21 00:24:52 +0000 | [diff] [blame] | 1271 | if (EXISTS "${ARG_MAIN_CONFIG}") |
| 1272 | set(PYTHON_STATEMENT "map_config('${ARG_MAIN_CONFIG}', '${site_out}')") |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1273 | get_property(LLVM_LIT_CONFIG_MAP GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP) |
| 1274 | set(LLVM_LIT_CONFIG_MAP "${LLVM_LIT_CONFIG_MAP}\n${PYTHON_STATEMENT}") |
| 1275 | set_property(GLOBAL PROPERTY LLVM_LIT_CONFIG_MAP ${LLVM_LIT_CONFIG_MAP}) |
| 1276 | endif() |
| 1277 | endfunction() |
| 1278 | |
| Zachary Turner | f8c80f91 | 2017-09-18 21:52:02 +0000 | [diff] [blame] | 1279 | function(dump_all_cmake_variables) |
| 1280 | get_cmake_property(_variableNames VARIABLES) |
| 1281 | foreach (_variableName ${_variableNames}) |
| 1282 | message(STATUS "${_variableName}=${${_variableName}}") |
| 1283 | endforeach() |
| 1284 | endfunction() |
| 1285 | |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1286 | function(get_llvm_lit_path base_dir file_name) |
| 1287 | cmake_parse_arguments(ARG "ALLOW_EXTERNAL" "" "" ${ARGN}) |
| 1288 | |
| 1289 | if (ARG_ALLOW_EXTERNAL) |
| Zachary Turner | 3dd2356 | 2017-09-20 16:01:50 +0000 | [diff] [blame] | 1290 | set(LLVM_DEFAULT_EXTERNAL_LIT "${LLVM_EXTERNAL_LIT}") |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1291 | set (LLVM_EXTERNAL_LIT "" CACHE STRING "Command used to spawn lit") |
| Zachary Turner | 3dd2356 | 2017-09-20 16:01:50 +0000 | [diff] [blame] | 1292 | if ("${LLVM_EXTERNAL_LIT}" STREQUAL "") |
| 1293 | set(LLVM_EXTERNAL_LIT "${LLVM_DEFAULT_EXTERNAL_LIT}") |
| 1294 | endif() |
| 1295 | |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1296 | if (NOT "${LLVM_EXTERNAL_LIT}" STREQUAL "") |
| 1297 | if (EXISTS ${LLVM_EXTERNAL_LIT}) |
| 1298 | get_filename_component(LIT_FILE_NAME ${LLVM_EXTERNAL_LIT} NAME) |
| 1299 | get_filename_component(LIT_BASE_DIR ${LLVM_EXTERNAL_LIT} DIRECTORY) |
| 1300 | set(${file_name} ${LIT_FILE_NAME} PARENT_SCOPE) |
| 1301 | set(${base_dir} ${LIT_BASE_DIR} PARENT_SCOPE) |
| 1302 | return() |
| 1303 | else() |
| 1304 | message(WARN "LLVM_EXTERNAL_LIT set to ${LLVM_EXTERNAL_LIT}, but the path does not exist.") |
| 1305 | endif() |
| 1306 | endif() |
| 1307 | endif() |
| 1308 | |
| 1309 | set(lit_file_name "llvm-lit") |
| Filipe Cabecinhas | 48c9f45 | 2018-06-29 10:34:37 +0000 | [diff] [blame] | 1310 | if (CMAKE_HOST_WIN32 AND NOT CYGWIN) |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1311 | # llvm-lit needs suffix.py for multiprocess to find a main module. |
| 1312 | set(lit_file_name "${lit_file_name}.py") |
| 1313 | endif () |
| 1314 | set(${file_name} ${lit_file_name} PARENT_SCOPE) |
| 1315 | |
| 1316 | get_property(LLVM_LIT_BASE_DIR GLOBAL PROPERTY LLVM_LIT_BASE_DIR) |
| 1317 | if (NOT "${LLVM_LIT_BASE_DIR}" STREQUAL "") |
| 1318 | set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) |
| 1319 | endif() |
| 1320 | |
| 1321 | # Allow individual projects to provide an override |
| 1322 | if (NOT "${LLVM_LIT_OUTPUT_DIR}" STREQUAL "") |
| 1323 | set(LLVM_LIT_BASE_DIR ${LLVM_LIT_OUTPUT_DIR}) |
| 1324 | elseif(NOT "${LLVM_RUNTIME_OUTPUT_INTDIR}" STREQUAL "") |
| 1325 | set(LLVM_LIT_BASE_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 1326 | else() |
| Zachary Turner | 3dd2356 | 2017-09-20 16:01:50 +0000 | [diff] [blame] | 1327 | set(LLVM_LIT_BASE_DIR "") |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1328 | endif() |
| 1329 | |
| 1330 | # Cache this so we don't have to do it again and have subsequent calls |
| 1331 | # potentially disagree on the value. |
| 1332 | set_property(GLOBAL PROPERTY LLVM_LIT_BASE_DIR ${LLVM_LIT_BASE_DIR}) |
| 1333 | set(${base_dir} ${LLVM_LIT_BASE_DIR} PARENT_SCOPE) |
| Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 1334 | endfunction() |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1335 | |
| 1336 | # A raw function to create a lit target. This is used to implement the testuite |
| 1337 | # management functions. |
| 1338 | function(add_lit_target target comment) |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1339 | cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1340 | set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}") |
| 1341 | separate_arguments(LIT_ARGS) |
| NAKAMURA Takumi | 0dc10d5 | 2013-12-04 11:15:17 +0000 | [diff] [blame] | 1342 | if (NOT CMAKE_CFG_INTDIR STREQUAL ".") |
| 1343 | list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) |
| 1344 | endif () |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1345 | |
| 1346 | # Get the path to the lit to *run* tests with. This can be overriden by |
| 1347 | # the user by specifying -DLLVM_EXTERNAL_LIT=<path-to-lit.py> |
| 1348 | get_llvm_lit_path( |
| 1349 | lit_base_dir |
| 1350 | lit_file_name |
| 1351 | ALLOW_EXTERNAL |
| 1352 | ) |
| 1353 | |
| 1354 | set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}") |
| Greg Fitzgerald | 962a339 | 2014-05-21 16:44:03 +0000 | [diff] [blame] | 1355 | list(APPEND LIT_COMMAND ${LIT_ARGS}) |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1356 | foreach(param ${ARG_PARAMS}) |
| 1357 | list(APPEND LIT_COMMAND --param ${param}) |
| 1358 | endforeach() |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1359 | if (ARG_UNPARSED_ARGUMENTS) |
| NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 1360 | add_custom_target(${target} |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1361 | COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS} |
| NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 1362 | COMMENT "${comment}" |
| Chris Bieneman | df04e79 | 2016-06-08 22:19:25 +0000 | [diff] [blame] | 1363 | USES_TERMINAL |
| NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 1364 | ) |
| NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 1365 | else() |
| 1366 | add_custom_target(${target} |
| Nico Weber | b42359d | 2013-12-29 00:11:20 +0000 | [diff] [blame] | 1367 | COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.") |
| NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 1368 | message(STATUS "${target} does nothing.") |
| 1369 | endif() |
| Peter Collingbourne | 2ba7f7b | 2015-02-18 22:25:35 +0000 | [diff] [blame] | 1370 | if (ARG_DEPENDS) |
| 1371 | add_dependencies(${target} ${ARG_DEPENDS}) |
| 1372 | endif() |
| NAKAMURA Takumi | 03fc730 | 2013-12-02 11:31:19 +0000 | [diff] [blame] | 1373 | |
| 1374 | # Tests should be excluded from "Build Solution". |
| 1375 | set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1376 | endfunction() |
| 1377 | |
| 1378 | # A function to add a set of lit test suites to be driven through 'check-*' targets. |
| 1379 | function(add_lit_testsuite target comment) |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1380 | cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1381 | |
| NAKAMURA Takumi | 54d2274 | 2012-10-10 13:32:55 +0000 | [diff] [blame] | 1382 | # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all. |
| 1383 | if(NOT EXCLUDE_FROM_ALL) |
| 1384 | # Register the testsuites, params and depends for the global check rule. |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1385 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS}) |
| NAKAMURA Takumi | 54d2274 | 2012-10-10 13:32:55 +0000 | [diff] [blame] | 1386 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS}) |
| 1387 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS}) |
| 1388 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS}) |
| 1389 | endif() |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1390 | |
| 1391 | # Produce a specific suffixed check rule. |
| 1392 | add_lit_target(${target} ${comment} |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1393 | ${ARG_UNPARSED_ARGUMENTS} |
| Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 1394 | PARAMS ${ARG_PARAMS} |
| 1395 | DEPENDS ${ARG_DEPENDS} |
| 1396 | ARGS ${ARG_ARGS} |
| 1397 | ) |
| 1398 | endfunction() |
| Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 1399 | |
| 1400 | function(add_lit_testsuites project directory) |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 1401 | if (NOT CMAKE_CONFIGURATION_TYPES) |
| Filipe Cabecinhas | c1b849a | 2015-06-19 03:45:40 +0000 | [diff] [blame] | 1402 | cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) |
| Justin Bogner | e889462 | 2016-05-06 21:57:30 +0000 | [diff] [blame] | 1403 | |
| 1404 | # Search recursively for test directories by assuming anything not |
| 1405 | # in a directory called Inputs contains tests. |
| Justin Bogner | 3adaa8c | 2016-06-08 22:36:37 +0000 | [diff] [blame] | 1406 | file(GLOB_RECURSE to_process LIST_DIRECTORIES true ${directory}/*) |
| 1407 | foreach(lit_suite ${to_process}) |
| 1408 | if(NOT IS_DIRECTORY ${lit_suite}) |
| 1409 | continue() |
| 1410 | endif() |
| 1411 | string(FIND ${lit_suite} Inputs is_inputs) |
| Justin Bogner | 25ef9e3 | 2016-07-25 18:07:14 +0000 | [diff] [blame] | 1412 | string(FIND ${lit_suite} Output is_output) |
| Ayman Musa | 2d33869 | 2017-04-13 09:26:49 +0000 | [diff] [blame] | 1413 | if (NOT (is_inputs EQUAL -1 AND is_output EQUAL -1)) |
| Justin Bogner | 3adaa8c | 2016-06-08 22:36:37 +0000 | [diff] [blame] | 1414 | continue() |
| 1415 | endif() |
| Justin Bogner | e889462 | 2016-05-06 21:57:30 +0000 | [diff] [blame] | 1416 | |
| Justin Bogner | 3adaa8c | 2016-06-08 22:36:37 +0000 | [diff] [blame] | 1417 | # Create a check- target for the directory. |
| 1418 | string(REPLACE ${directory} "" name_slash ${lit_suite}) |
| Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 1419 | if (name_slash) |
| 1420 | string(REPLACE "/" "-" name_slash ${name_slash}) |
| 1421 | string(REPLACE "\\" "-" name_dashes ${name_slash}) |
| 1422 | string(TOLOWER "${project}${name_dashes}" name_var) |
| Justin Bogner | 3adaa8c | 2016-06-08 22:36:37 +0000 | [diff] [blame] | 1423 | add_lit_target("check-${name_var}" "Running lit suite ${lit_suite}" |
| 1424 | ${lit_suite} |
| Chris Bieneman | 9ea37d9 | 2015-03-23 20:04:00 +0000 | [diff] [blame] | 1425 | PARAMS ${ARG_PARAMS} |
| 1426 | DEPENDS ${ARG_DEPENDS} |
| 1427 | ARGS ${ARG_ARGS} |
| 1428 | ) |
| 1429 | endif() |
| 1430 | endforeach() |
| 1431 | endif() |
| 1432 | endfunction() |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1433 | |
| Chris Bieneman | 5e96fe9 | 2015-11-04 23:11:12 +0000 | [diff] [blame] | 1434 | function(llvm_install_library_symlink name dest type) |
| 1435 | cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) |
| 1436 | foreach(path ${CMAKE_MODULE_PATH}) |
| 1437 | if(EXISTS ${path}/LLVMInstallSymlink.cmake) |
| 1438 | set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake) |
| 1439 | break() |
| 1440 | endif() |
| 1441 | endforeach() |
| 1442 | |
| 1443 | set(component ${ARG_COMPONENT}) |
| 1444 | if(NOT component) |
| 1445 | set(component ${name}) |
| 1446 | endif() |
| 1447 | |
| 1448 | set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) |
| 1449 | set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) |
| 1450 | |
| Chris Bieneman | 021f874 | 2015-11-11 16:19:39 +0000 | [diff] [blame] | 1451 | set(output_dir lib${LLVM_LIBDIR_SUFFIX}) |
| Chris Bieneman | 5e96fe9 | 2015-11-04 23:11:12 +0000 | [diff] [blame] | 1452 | if(WIN32 AND "${type}" STREQUAL "SHARED") |
| 1453 | set(output_dir bin) |
| 1454 | endif() |
| 1455 | |
| 1456 | install(SCRIPT ${INSTALL_SYMLINK} |
| 1457 | CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" |
| 1458 | COMPONENT ${component}) |
| 1459 | |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 1460 | if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 1461 | add_llvm_install_targets(install-${name} |
| 1462 | DEPENDS ${name} ${dest} install-${dest} |
| 1463 | COMPONENT ${name}) |
| Chris Bieneman | 5e96fe9 | 2015-11-04 23:11:12 +0000 | [diff] [blame] | 1464 | endif() |
| 1465 | endfunction() |
| 1466 | |
| Chris Bieneman | bff03b0 | 2015-09-16 20:49:59 +0000 | [diff] [blame] | 1467 | function(llvm_install_symlink name dest) |
| Saleem Abdulrasool | 27227bb | 2016-12-03 22:03:24 +0000 | [diff] [blame] | 1468 | cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) |
| Chris Bieneman | 0824970 | 2015-09-18 17:39:58 +0000 | [diff] [blame] | 1469 | foreach(path ${CMAKE_MODULE_PATH}) |
| 1470 | if(EXISTS ${path}/LLVMInstallSymlink.cmake) |
| 1471 | set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake) |
| 1472 | break() |
| 1473 | endif() |
| 1474 | endforeach() |
| Ramkumar Ramachandra | cad135a | 2015-11-10 18:26:34 +0000 | [diff] [blame] | 1475 | |
| Saleem Abdulrasool | 27227bb | 2016-12-03 22:03:24 +0000 | [diff] [blame] | 1476 | if(ARG_COMPONENT) |
| 1477 | set(component ${ARG_COMPONENT}) |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1478 | else() |
| Saleem Abdulrasool | 27227bb | 2016-12-03 22:03:24 +0000 | [diff] [blame] | 1479 | if(ARG_ALWAYS_GENERATE) |
| 1480 | set(component ${dest}) |
| 1481 | else() |
| 1482 | set(component ${name}) |
| 1483 | endif() |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1484 | endif() |
| 1485 | |
| Chris Bieneman | 11a7160 | 2015-10-16 23:17:13 +0000 | [diff] [blame] | 1486 | set(full_name ${name}${CMAKE_EXECUTABLE_SUFFIX}) |
| 1487 | set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) |
| 1488 | |
| Chris Bieneman | 0824970 | 2015-09-18 17:39:58 +0000 | [diff] [blame] | 1489 | install(SCRIPT ${INSTALL_SYMLINK} |
| Chris Bieneman | 2724f14 | 2016-06-08 21:19:26 +0000 | [diff] [blame] | 1490 | CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1491 | COMPONENT ${component}) |
| Chris Bieneman | bff03b0 | 2015-09-16 20:49:59 +0000 | [diff] [blame] | 1492 | |
| Roman Lebedev | f1ec7f8 | 2018-08-30 09:32:09 +0000 | [diff] [blame] | 1493 | if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) |
| Shoaib Meenai | a7ac2cb | 2017-11-30 21:48:26 +0000 | [diff] [blame] | 1494 | add_llvm_install_targets(install-${name} |
| 1495 | DEPENDS ${name} ${dest} install-${dest} |
| 1496 | COMPONENT ${name}) |
| Chris Bieneman | bff03b0 | 2015-09-16 20:49:59 +0000 | [diff] [blame] | 1497 | endif() |
| 1498 | endfunction() |
| 1499 | |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1500 | function(add_llvm_tool_symlink link_name target) |
| 1501 | cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN}) |
| Chris Bieneman | dc9b0db | 2016-12-15 18:17:07 +0000 | [diff] [blame] | 1502 | set(dest_binary "$<TARGET_FILE:${target}>") |
| 1503 | |
| Chris Bieneman | 28f05ac | 2016-12-05 17:02:11 +0000 | [diff] [blame] | 1504 | # This got a bit gross... For multi-configuration generators the target |
| 1505 | # properties return the resolved value of the string, not the build system |
| 1506 | # expression. To reconstruct the platform-agnostic path we have to do some |
| 1507 | # magic. First we grab one of the types, and a type-specific path. Then from |
| 1508 | # the type-specific path we find the last occurrence of the type in the path, |
| 1509 | # and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type |
| Zachary Turner | ce92db1 | 2017-09-15 22:10:46 +0000 | [diff] [blame] | 1510 | # agnostic again. |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1511 | if(NOT ARG_OUTPUT_DIR) |
| Chris Bieneman | dc9b0db | 2016-12-15 18:17:07 +0000 | [diff] [blame] | 1512 | # If you're not overriding the OUTPUT_DIR, we can make the link relative in |
| 1513 | # the same directory. |
| Shoaib Meenai | 1295088 | 2018-01-09 07:50:18 +0000 | [diff] [blame] | 1514 | if(CMAKE_HOST_UNIX) |
| Chris Bieneman | dc9b0db | 2016-12-15 18:17:07 +0000 | [diff] [blame] | 1515 | set(dest_binary "$<TARGET_FILE_NAME:${target}>") |
| 1516 | endif() |
| Chris Bieneman | 28f05ac | 2016-12-05 17:02:11 +0000 | [diff] [blame] | 1517 | if(CMAKE_CONFIGURATION_TYPES) |
| 1518 | list(GET CMAKE_CONFIGURATION_TYPES 0 first_type) |
| 1519 | string(TOUPPER ${first_type} first_type_upper) |
| 1520 | set(first_type_suffix _${first_type_upper}) |
| 1521 | endif() |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1522 | get_target_property(target_type ${target} TYPE) |
| 1523 | if(${target_type} STREQUAL "STATIC_LIBRARY") |
| Chris Bieneman | 28f05ac | 2016-12-05 17:02:11 +0000 | [diff] [blame] | 1524 | get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix}) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1525 | elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY") |
| Chris Bieneman | 28f05ac | 2016-12-05 17:02:11 +0000 | [diff] [blame] | 1526 | get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix}) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1527 | else() |
| Chris Bieneman | 28f05ac | 2016-12-05 17:02:11 +0000 | [diff] [blame] | 1528 | get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix}) |
| 1529 | endif() |
| 1530 | if(CMAKE_CONFIGURATION_TYPES) |
| 1531 | string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE) |
| 1532 | string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix) |
| 1533 | string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix) |
| 1534 | string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/" |
| 1535 | path_suffix ${path_suffix}) |
| 1536 | set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix}) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1537 | endif() |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1538 | endif() |
| 1539 | |
| Shoaib Meenai | 1295088 | 2018-01-09 07:50:18 +0000 | [diff] [blame] | 1540 | if(CMAKE_HOST_UNIX) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1541 | set(LLVM_LINK_OR_COPY create_symlink) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1542 | else() |
| 1543 | set(LLVM_LINK_OR_COPY copy) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1544 | endif() |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1545 | |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1546 | set(output_path "${ARG_OUTPUT_DIR}/${link_name}${CMAKE_EXECUTABLE_SUFFIX}") |
| 1547 | |
| 1548 | set(target_name ${link_name}) |
| 1549 | if(TARGET ${link_name}) |
| 1550 | set(target_name ${link_name}-link) |
| Chris Bieneman | 6ee60bc | 2016-09-16 22:19:19 +0000 | [diff] [blame] | 1551 | endif() |
| 1552 | |
| 1553 | |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1554 | if(ARG_ALWAYS_GENERATE) |
| 1555 | set_property(DIRECTORY APPEND PROPERTY |
| 1556 | ADDITIONAL_MAKE_CLEAN_FILES ${dest_binary}) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1557 | add_custom_command(TARGET ${target} POST_BUILD |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1558 | COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}") |
| 1559 | else() |
| 1560 | add_custom_command(OUTPUT ${output_path} |
| Chris Bieneman | bde7e45 | 2015-09-15 02:15:53 +0000 | [diff] [blame] | 1561 | COMMAND ${CMAKE_COMMAND} -E ${LLVM_LINK_OR_COPY} "${dest_binary}" "${output_path}" |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1562 | DEPENDS ${target}) |
| 1563 | add_custom_target(${target_name} ALL DEPENDS ${target} ${output_path}) |
| Chris Bieneman | 6ee60bc | 2016-09-16 22:19:19 +0000 | [diff] [blame] | 1564 | set_target_properties(${target_name} PROPERTIES FOLDER Tools) |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1565 | |
| Chris Bieneman | 44d2990 | 2016-09-27 17:47:24 +0000 | [diff] [blame] | 1566 | # Make sure both the link and target are toolchain tools |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1567 | if (${link_name} IN_LIST LLVM_TOOLCHAIN_TOOLS AND ${target} IN_LIST LLVM_TOOLCHAIN_TOOLS) |
| Petr Hosek | acac3ab | 2016-09-30 06:29:28 +0000 | [diff] [blame] | 1568 | set(TOOL_IS_TOOLCHAIN ON) |
| Chris Bieneman | 895d96a | 2015-09-18 21:08:32 +0000 | [diff] [blame] | 1569 | endif() |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1570 | |
| Petr Hosek | acac3ab | 2016-09-30 06:29:28 +0000 | [diff] [blame] | 1571 | if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) |
| Chris Bieneman | 89e08ed | 2016-12-05 03:28:03 +0000 | [diff] [blame] | 1572 | llvm_install_symlink(${link_name} ${target}) |
| Chris Bieneman | 6d43afc | 2015-09-14 23:09:06 +0000 | [diff] [blame] | 1573 | endif() |
| 1574 | endif() |
| 1575 | endfunction() |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1576 | |
| 1577 | function(llvm_externalize_debuginfo name) |
| 1578 | if(NOT LLVM_EXTERNALIZE_DEBUGINFO) |
| 1579 | return() |
| 1580 | endif() |
| 1581 | |
| Chris Bieneman | 6099a4e | 2016-03-31 20:03:19 +0000 | [diff] [blame] | 1582 | if(NOT LLVM_EXTERNALIZE_DEBUGINFO_SKIP_STRIP) |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1583 | if(APPLE) |
| Justin Bogner | ca12bbb | 2018-06-28 18:36:52 +0000 | [diff] [blame] | 1584 | if(NOT CMAKE_STRIP) |
| 1585 | set(CMAKE_STRIP xcrun strip) |
| 1586 | endif() |
| 1587 | set(strip_command COMMAND ${CMAKE_STRIP} -Sxl $<TARGET_FILE:${name}>) |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1588 | else() |
| Petr Hosek | b7b342e | 2018-08-14 02:00:21 +0000 | [diff] [blame] | 1589 | set(strip_command COMMAND ${CMAKE_STRIP} -g -x $<TARGET_FILE:${name}>) |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1590 | endif() |
| Chris Bieneman | 6099a4e | 2016-03-31 20:03:19 +0000 | [diff] [blame] | 1591 | endif() |
| 1592 | |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1593 | if(APPLE) |
| 1594 | if(CMAKE_CXX_FLAGS MATCHES "-flto" |
| 1595 | OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto") |
| 1596 | |
| 1597 | set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o) |
| Chris Bieneman | ccabd0e | 2015-12-03 22:51:08 +0000 | [diff] [blame] | 1598 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 1599 | LINK_FLAGS " -Wl,-object_path_lto,${lto_object}") |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1600 | endif() |
| Justin Bogner | ca12bbb | 2018-06-28 18:36:52 +0000 | [diff] [blame] | 1601 | if(NOT CMAKE_DSYMUTIL) |
| 1602 | set(CMAKE_DSYMUTIL xcrun dsymutil) |
| 1603 | endif() |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1604 | add_custom_command(TARGET ${name} POST_BUILD |
| Justin Bogner | ca12bbb | 2018-06-28 18:36:52 +0000 | [diff] [blame] | 1605 | COMMAND ${CMAKE_DSYMUTIL} $<TARGET_FILE:${name}> |
| Chris Bieneman | 6099a4e | 2016-03-31 20:03:19 +0000 | [diff] [blame] | 1606 | ${strip_command} |
| 1607 | ) |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1608 | else() |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1609 | add_custom_command(TARGET ${name} POST_BUILD |
| Petr Hosek | 47550bb | 2018-05-09 00:07:42 +0000 | [diff] [blame] | 1610 | COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $<TARGET_FILE:${name}> $<TARGET_FILE:${name}>.debug |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1611 | ${strip_command} -R .gnu_debuglink |
| Petr Hosek | 47550bb | 2018-05-09 00:07:42 +0000 | [diff] [blame] | 1612 | COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$<TARGET_FILE:${name}>.debug $<TARGET_FILE:${name}> |
| Petr Hosek | 7acbeaf | 2017-02-17 19:29:12 +0000 | [diff] [blame] | 1613 | ) |
| Chris Bieneman | bf2c412 | 2015-12-03 18:45:39 +0000 | [diff] [blame] | 1614 | endif() |
| 1615 | endfunction() |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 1616 | |
| Justin Bogner | 8fa2608 | 2018-07-10 17:32:48 +0000 | [diff] [blame] | 1617 | function(llvm_codesign name) |
| 1618 | if(NOT LLVM_CODESIGNING_IDENTITY) |
| 1619 | return() |
| 1620 | endif() |
| 1621 | |
| 1622 | if(APPLE) |
| 1623 | if(NOT CMAKE_CODESIGN) |
| 1624 | set(CMAKE_CODESIGN xcrun codesign) |
| 1625 | endif() |
| 1626 | if(NOT CMAKE_CODESIGN_ALLOCATE) |
| 1627 | execute_process( |
| 1628 | COMMAND xcrun -f codesign_allocate |
| 1629 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 1630 | OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE |
| 1631 | ) |
| 1632 | endif() |
| 1633 | add_custom_command( |
| 1634 | TARGET ${name} POST_BUILD |
| 1635 | COMMAND ${CMAKE_COMMAND} -E |
| 1636 | env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE} |
| 1637 | ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY} |
| 1638 | $<TARGET_FILE:${name}> |
| 1639 | ) |
| 1640 | endif() |
| 1641 | endfunction() |
| 1642 | |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 1643 | function(llvm_setup_rpath name) |
| Mandeep Singh Grang | 96999de | 2016-11-08 00:45:05 +0000 | [diff] [blame] | 1644 | if(CMAKE_INSTALL_RPATH) |
| 1645 | return() |
| 1646 | endif() |
| 1647 | |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 1648 | if(LLVM_INSTALL_PREFIX AND NOT (LLVM_INSTALL_PREFIX STREQUAL CMAKE_INSTALL_PREFIX)) |
| 1649 | set(extra_libdir ${LLVM_LIBRARY_DIR}) |
| 1650 | elseif(LLVM_BUILD_LIBRARY_DIR) |
| 1651 | set(extra_libdir ${LLVM_LIBRARY_DIR}) |
| 1652 | endif() |
| 1653 | |
| 1654 | if (APPLE) |
| 1655 | set(_install_name_dir INSTALL_NAME_DIR "@rpath") |
| 1656 | set(_install_rpath "@loader_path/../lib" ${extra_libdir}) |
| 1657 | elseif(UNIX) |
| Mandeep Singh Grang | 96999de | 2016-11-08 00:45:05 +0000 | [diff] [blame] | 1658 | set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) |
| 1659 | if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") |
| 1660 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 1661 | LINK_FLAGS " -Wl,-z,origin ") |
| Michal Gorny | 93176a8 | 2018-03-08 15:09:38 +0000 | [diff] [blame] | 1662 | endif() |
| 1663 | if(LLVM_LINKER_IS_GNULD) |
| Mandeep Singh Grang | 96999de | 2016-11-08 00:45:05 +0000 | [diff] [blame] | 1664 | # $ORIGIN is not interpreted at link time by ld.bfd |
| 1665 | set_property(TARGET ${name} APPEND_STRING PROPERTY |
| 1666 | LINK_FLAGS " -Wl,-rpath-link,${LLVM_LIBRARY_OUTPUT_INTDIR} ") |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 1667 | endif() |
| 1668 | else() |
| 1669 | return() |
| 1670 | endif() |
| 1671 | |
| Mandeep Singh Grang | 96999de | 2016-11-08 00:45:05 +0000 | [diff] [blame] | 1672 | set_target_properties(${name} PROPERTIES |
| 1673 | BUILD_WITH_INSTALL_RPATH On |
| 1674 | INSTALL_RPATH "${_install_rpath}" |
| 1675 | ${_install_name_dir}) |
| Chris Bieneman | 61e900b | 2016-11-01 17:44:58 +0000 | [diff] [blame] | 1676 | endfunction() |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 1677 | |
| 1678 | function(setup_dependency_debugging name) |
| 1679 | if(NOT LLVM_DEPENDENCY_DEBUGGING) |
| 1680 | return() |
| 1681 | endif() |
| 1682 | |
| 1683 | if("intrinsics_gen" IN_LIST ARGN) |
| 1684 | return() |
| 1685 | endif() |
| 1686 | |
| Nico Weber | 79c6ec4 | 2018-04-25 17:07:46 +0000 | [diff] [blame] | 1687 | set(deny_attributes_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.inc\"))") |
| 1688 | set(deny_intrinsics_inc "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.inc\"))") |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 1689 | |
| Nico Weber | 79c6ec4 | 2018-04-25 17:07:46 +0000 | [diff] [blame] | 1690 | set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_inc} ${deny_intrinsics_inc}'") |
| Chris Bieneman | 958edcb | 2016-11-19 01:32:09 +0000 | [diff] [blame] | 1691 | set_target_properties(${name} PROPERTIES RULE_LAUNCH_COMPILE ${sandbox_command}) |
| Chris Bieneman | 8036e0b | 2016-11-17 04:36:59 +0000 | [diff] [blame] | 1692 | endfunction() |
| Don Hinton | 76d02ce | 2017-09-02 17:28:39 +0000 | [diff] [blame] | 1693 | |
| 1694 | # Figure out if we can track VC revisions. |
| 1695 | function(find_first_existing_file out_var) |
| 1696 | foreach(file ${ARGN}) |
| 1697 | if(EXISTS "${file}") |
| 1698 | set(${out_var} "${file}" PARENT_SCOPE) |
| 1699 | return() |
| 1700 | endif() |
| 1701 | endforeach() |
| 1702 | endfunction() |
| 1703 | |
| 1704 | macro(find_first_existing_vc_file out_var path) |
| 1705 | find_program(git_executable NAMES git git.exe git.cmd) |
| 1706 | # Run from a subdirectory to force git to print an absolute path. |
| 1707 | execute_process(COMMAND ${git_executable} rev-parse --git-dir |
| 1708 | WORKING_DIRECTORY ${path}/cmake |
| 1709 | RESULT_VARIABLE git_result |
| 1710 | OUTPUT_VARIABLE git_dir |
| 1711 | ERROR_QUIET) |
| 1712 | if(git_result EQUAL 0) |
| 1713 | string(STRIP "${git_dir}" git_dir) |
| 1714 | set(${out_var} "${git_dir}/logs/HEAD") |
| 1715 | # some branchless cases (e.g. 'repo') may not yet have .git/logs/HEAD |
| 1716 | if (NOT EXISTS "${git_dir}/logs/HEAD") |
| 1717 | file(WRITE "${git_dir}/logs/HEAD" "") |
| 1718 | endif() |
| 1719 | else() |
| 1720 | find_first_existing_file(${out_var} |
| 1721 | "${path}/.svn/wc.db" # SVN 1.7 |
| 1722 | "${path}/.svn/entries" # SVN 1.6 |
| 1723 | ) |
| 1724 | endif() |
| 1725 | endmacro() |