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