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