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