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