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