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