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 | |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 5 | function(add_llvm_symbol_exports target_name export_file) |
| 6 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 7 | set(native_export_file "symbol.exports") |
| 8 | add_custom_command(OUTPUT symbol.exports |
| 9 | COMMAND sed -e "s/^/_/" < ${export_file} > symbol.exports |
| 10 | DEPENDS ${export_file} |
| 11 | VERBATIM |
| 12 | COMMENT "Creating export file for ${target_name}") |
| 13 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 14 | LINK_FLAGS " -Wl,-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports") |
| 15 | elseif(LLVM_HAVE_LINK_VERSION_SCRIPT) |
| 16 | # Gold and BFD ld require a version script rather than a plain list. |
| 17 | set(native_export_file "symbol.exports") |
| 18 | # FIXME: Don't write the "local:" line on OpenBSD. |
| 19 | add_custom_command(OUTPUT symbol.exports |
| 20 | COMMAND echo "{" > symbol.exports |
| 21 | COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> symbol.exports || : |
Nico Weber | a69d1a8 | 2013-12-28 23:39:49 +0000 | [diff] [blame] | 22 | COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> symbol.exports |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 23 | COMMAND echo " local: *;" >> symbol.exports |
| 24 | COMMAND echo "};" >> symbol.exports |
| 25 | DEPENDS ${export_file} |
| 26 | VERBATIM |
| 27 | COMMENT "Creating export file for ${target_name}") |
| 28 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
| 29 | LINK_FLAGS " -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/symbol.exports") |
| 30 | else() |
| 31 | set(native_export_file "symbol.def") |
| 32 | |
| 33 | set(CAT "type") |
| 34 | if(CYGWIN) |
| 35 | set(CAT "cat") |
| 36 | endif() |
| 37 | |
Nico Weber | 5c8a4a3 | 2013-12-29 04:05:23 +0000 | [diff] [blame] | 38 | # Using ${export_file} in add_custom_command directly confuses cmd.exe. |
| 39 | file(TO_NATIVE_PATH ${export_file} export_file_backslashes) |
| 40 | |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 41 | add_custom_command(OUTPUT symbol.def |
Nico Weber | b42359d | 2013-12-29 00:11:20 +0000 | [diff] [blame] | 42 | COMMAND ${CMAKE_COMMAND} -E echo "EXPORTS" > symbol.def |
Nico Weber | 5c8a4a3 | 2013-12-29 04:05:23 +0000 | [diff] [blame] | 43 | COMMAND ${CAT} ${export_file_backslashes} >> symbol.def |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 44 | DEPENDS ${export_file} |
| 45 | VERBATIM |
| 46 | COMMENT "Creating export file for ${target_name}") |
| 47 | set_property(TARGET ${target_name} APPEND_STRING PROPERTY |
Nico Weber | 1946f3a0 | 2013-12-29 06:12:40 +0000 | [diff] [blame] | 48 | LINK_FLAGS "/DEF:${CMAKE_CURRENT_BINARY_DIR}/symbol.def") |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 49 | endif() |
| 50 | |
| 51 | add_custom_target(${target_name}_exports DEPENDS ${native_export_file}) |
| 52 | |
| 53 | get_property(srcs TARGET ${target_name} PROPERTY SOURCES) |
| 54 | foreach(src ${srcs}) |
| 55 | get_filename_component(extension ${src} EXT) |
| 56 | if(extension STREQUAL ".cpp") |
| 57 | set(first_source_file ${src}) |
| 58 | break() |
| 59 | endif() |
| 60 | endforeach() |
| 61 | |
| 62 | # Force re-linking when the exports file changes. Actually, it |
| 63 | # forces recompilation of the source file. The LINK_DEPENDS target |
| 64 | # property only works for makefile-based generators. |
| 65 | set_property(SOURCE ${first_source_file} APPEND PROPERTY |
| 66 | OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}) |
| 67 | |
| 68 | set_property(DIRECTORY APPEND |
| 69 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${native_export_file}) |
| 70 | |
| 71 | add_dependencies(${target_name} ${target_name}_exports) |
| 72 | endfunction(add_llvm_symbol_exports) |
| 73 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 74 | macro(add_llvm_library name) |
Oscar Fuentes | 2c10b22 | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 75 | llvm_process_sources( ALL_FILES ${ARGN} ) |
| 76 | add_library( ${name} ${ALL_FILES} ) |
Oscar Fuentes | 5ed9626 | 2011-02-18 22:06:14 +0000 | [diff] [blame] | 77 | set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) |
Oscar Fuentes | 8807bdd | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 78 | if( LLVM_COMMON_DEPENDS ) |
| 79 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 80 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 81 | |
| 82 | if( BUILD_SHARED_LIBS ) |
Oscar Fuentes | cc48b9a | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 83 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
NAKAMURA Takumi | cb065a6 | 2013-08-14 03:34:49 +0000 | [diff] [blame] | 84 | if (MSVC) |
| 85 | set_target_properties(${name} |
| 86 | PROPERTIES |
| 87 | IMPORT_SUFFIX ".imp") |
| 88 | endif () |
Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 89 | |
Nico Weber | 06473f8 | 2013-12-29 05:39:01 +0000 | [diff] [blame] | 90 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 91 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 92 | endif() |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 93 | endif() |
| 94 | |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 95 | # Ensure that the system libraries always comes last on the |
| 96 | # list. Without this, linking the unit tests on MinGW fails. |
| 97 | link_system_libs( ${name} ) |
| 98 | |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 99 | if( EXCLUDE_FROM_ALL ) |
| 100 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
| 101 | else() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 102 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") |
| 103 | install(TARGETS ${name} |
| 104 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 105 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 106 | endif() |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 107 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 108 | set_target_properties(${name} PROPERTIES FOLDER "Libraries") |
Daniel Dunbar | faaa76d | 2011-11-29 01:31:52 +0000 | [diff] [blame] | 109 | |
| 110 | # Add the explicit dependency information for this library. |
| 111 | # |
| 112 | # It would be nice to verify that we have the dependencies for this library |
| 113 | # name, but using get_property(... SET) doesn't suffice to determine if a |
| 114 | # property has been set to an empty value. |
| 115 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) |
| 116 | target_link_libraries(${name} ${lib_deps}) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 117 | endmacro(add_llvm_library name) |
| 118 | |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 119 | macro(add_llvm_loadable_module name) |
Oscar Fuentes | ff11a23 | 2010-10-22 19:03:24 +0000 | [diff] [blame] | 120 | if( NOT LLVM_ON_UNIX OR CYGWIN ) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 121 | message(STATUS "Loadable modules not supported on this platform. |
| 122 | ${name} ignored.") |
NAKAMURA Takumi | a8c1c3f | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 123 | # Add empty "phony" target |
| 124 | add_custom_target(${name}) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 125 | else() |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 126 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 9f2b384 | 2010-12-22 08:30:17 +0000 | [diff] [blame] | 127 | if (MODULE) |
| 128 | set(libkind MODULE) |
| 129 | else() |
| 130 | set(libkind SHARED) |
| 131 | endif() |
| 132 | |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 133 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 134 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 135 | endif(LLVM_EXPORTED_SYMBOL_FILE) |
| 136 | |
Oscar Fuentes | 9f2b384 | 2010-12-22 08:30:17 +0000 | [diff] [blame] | 137 | add_library( ${name} ${libkind} ${ALL_FILES} ) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 138 | set_target_properties( ${name} PROPERTIES PREFIX "" ) |
Douglas Gregor | 66df54f | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 139 | |
Oscar Fuentes | cc48b9a | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 140 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 141 | link_system_libs( ${name} ) |
Oscar Fuentes | cc48b9a | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 142 | |
Douglas Gregor | 66df54f | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 143 | if (APPLE) |
| 144 | # Darwin-specific linker flags for loadable modules. |
| 145 | set_target_properties(${name} PROPERTIES |
| 146 | LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 147 | endif() |
| 148 | |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 149 | if( EXCLUDE_FROM_ALL ) |
Nick Lewycky | 61aed87 | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 150 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 151 | else() |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 152 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 153 | install(TARGETS ${name} |
| 154 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 155 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 156 | endif() |
Oscar Fuentes | 638aaec | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 157 | endif() |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 158 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 159 | |
| 160 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 161 | endmacro(add_llvm_loadable_module name) |
| 162 | |
| 163 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 164 | macro(add_llvm_executable name) |
Oscar Fuentes | 2c10b22 | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 165 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 166 | if( EXCLUDE_FROM_ALL ) |
| 167 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 168 | else() |
| 169 | add_executable(${name} ${ALL_FILES}) |
| 170 | endif() |
Nico Weber | c27118d | 2013-12-28 23:31:44 +0000 | [diff] [blame] | 171 | |
| 172 | if (LLVM_EXPORTED_SYMBOL_FILE) |
| 173 | add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} ) |
| 174 | endif(LLVM_EXPORTED_SYMBOL_FILE) |
| 175 | |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 176 | set(EXCLUDE_FROM_ALL OFF) |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 177 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | 3fca0e8 | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 178 | if( LLVM_COMMON_DEPENDS ) |
| 179 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 180 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 181 | link_system_libs( ${name} ) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 182 | endmacro(add_llvm_executable name) |
| 183 | |
| 184 | |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 185 | set (LLVM_TOOLCHAIN_TOOLS |
| 186 | llvm-ar |
| 187 | llvm-objdump |
| 188 | ) |
| 189 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 190 | macro(add_llvm_tool name) |
| 191 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 192 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 193 | set(EXCLUDE_FROM_ALL ON) |
| 194 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 195 | add_llvm_executable(${name} ${ARGN}) |
Hans Wennborg | 1654627 | 2013-08-24 00:20:36 +0000 | [diff] [blame] | 196 | |
| 197 | list(FIND LLVM_TOOLCHAIN_TOOLS ${name} LLVM_IS_${name}_TOOLCHAIN_TOOL) |
| 198 | if (LLVM_IS_${name}_TOOLCHAIN_TOOL GREATER -1 OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 199 | if( LLVM_BUILD_TOOLS ) |
| 200 | install(TARGETS ${name} RUNTIME DESTINATION bin) |
| 201 | endif() |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 202 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 203 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 204 | endmacro(add_llvm_tool name) |
| 205 | |
| 206 | |
| 207 | macro(add_llvm_example name) |
| 208 | # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 209 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 210 | set(EXCLUDE_FROM_ALL ON) |
| 211 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 212 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 213 | if( LLVM_BUILD_EXAMPLES ) |
| 214 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 215 | endif() |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 216 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 217 | endmacro(add_llvm_example name) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 218 | |
| 219 | |
Oscar Fuentes | 3145e92 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 220 | macro(add_llvm_utility name) |
| 221 | add_llvm_executable(${name} ${ARGN}) |
| 222 | set_target_properties(${name} PROPERTIES FOLDER "Utils") |
| 223 | endmacro(add_llvm_utility name) |
| 224 | |
| 225 | |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 226 | macro(add_llvm_target target_name) |
Oscar Fuentes | 4f0f335 | 2011-07-25 20:17:01 +0000 | [diff] [blame] | 227 | include_directories(BEFORE |
| 228 | ${CMAKE_CURRENT_BINARY_DIR} |
| 229 | ${CMAKE_CURRENT_SOURCE_DIR}) |
Douglas Gregor | 85fedbe | 2009-06-23 17:57:35 +0000 | [diff] [blame] | 230 | add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) |
Oscar Fuentes | ba1186c | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 231 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 232 | endmacro(add_llvm_target) |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 233 | |
| 234 | # Add external project that may want to be built as part of llvm such as Clang, |
| 235 | # lld, and Polly. This adds two options. One for the source directory of the |
| 236 | # project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to |
Alp Toker | 171b0c3 | 2013-12-20 00:33:39 +0000 | [diff] [blame] | 237 | # enable or disable building it with everything else. |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 238 | # Additional parameter can be specified as the name of directory. |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 239 | macro(add_llvm_external_project name) |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 240 | set(add_llvm_external_dir "${ARGN}") |
| 241 | if("${add_llvm_external_dir}" STREQUAL "") |
| 242 | set(add_llvm_external_dir ${name}) |
| 243 | endif() |
Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 244 | 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] | 245 | string(REPLACE "-" "_" nameUNDERSCORE ${name}) |
| 246 | string(TOUPPER ${nameUNDERSCORE} nameUPPER) |
| 247 | 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] | 248 | CACHE PATH "Path to ${name} source directory") |
| 249 | if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL "" |
| 250 | AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt) |
| 251 | option(LLVM_EXTERNAL_${nameUPPER}_BUILD |
| 252 | "Whether to build ${name} as part of LLVM" ON) |
| 253 | if (LLVM_EXTERNAL_${nameUPPER}_BUILD) |
NAKAMURA Takumi | 700cd40 | 2012-10-05 14:10:17 +0000 | [diff] [blame] | 254 | add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${add_llvm_external_dir}) |
Michael J. Spencer | e734f54 | 2012-04-26 19:43:35 +0000 | [diff] [blame] | 255 | endif() |
| 256 | endif() |
| 257 | endmacro(add_llvm_external_project) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 258 | |
Argyrios Kyrtzidis | 7eec9d0 | 2013-08-21 19:13:44 +0000 | [diff] [blame] | 259 | macro(add_llvm_tool_subdirectory name) |
| 260 | list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}") |
| 261 | add_subdirectory(${name}) |
| 262 | endmacro(add_llvm_tool_subdirectory) |
| 263 | |
| 264 | macro(ignore_llvm_tool_subdirectory name) |
| 265 | list(APPEND LLVM_IMPLICIT_PROJECT_IGNORE "${CMAKE_CURRENT_SOURCE_DIR}/${name}") |
| 266 | endmacro(ignore_llvm_tool_subdirectory) |
| 267 | |
| 268 | function(add_llvm_implicit_external_projects) |
| 269 | set(list_of_implicit_subdirs "") |
| 270 | file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*") |
| 271 | foreach(dir ${sub-dirs}) |
| 272 | if(IS_DIRECTORY "${dir}") |
| 273 | list(FIND LLVM_IMPLICIT_PROJECT_IGNORE "${dir}" tool_subdir_ignore) |
| 274 | if( tool_subdir_ignore EQUAL -1 |
| 275 | AND EXISTS "${dir}/CMakeLists.txt") |
| 276 | get_filename_component(fn "${dir}" NAME) |
| 277 | list(APPEND list_of_implicit_subdirs "${fn}") |
| 278 | endif() |
| 279 | endif() |
| 280 | endforeach() |
| 281 | |
| 282 | foreach(external_proj ${list_of_implicit_subdirs}) |
| 283 | add_llvm_external_project("${external_proj}") |
| 284 | endforeach() |
| 285 | endfunction(add_llvm_implicit_external_projects) |
| 286 | |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 287 | # Generic support for adding a unittest. |
Chandler Carruth | 94d0251 | 2012-06-21 09:51:26 +0000 | [diff] [blame] | 288 | function(add_unittest test_suite test_name) |
NAKAMURA Takumi | c42bdfc | 2013-01-27 12:46:53 +0000 | [diff] [blame] | 289 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 290 | if( NOT LLVM_BUILD_TESTS ) |
| 291 | set(EXCLUDE_FROM_ALL ON) |
| 292 | endif() |
| 293 | |
| 294 | add_llvm_executable(${test_name} ${ARGN}) |
| 295 | target_link_libraries(${test_name} |
| 296 | gtest |
| 297 | gtest_main |
| 298 | LLVMSupport # gtest needs it for raw_ostream. |
| 299 | ) |
| 300 | |
| 301 | add_dependencies(${test_suite} ${test_name}) |
| 302 | get_target_property(test_suite_folder ${test_suite} FOLDER) |
| 303 | if (NOT ${test_suite_folder} STREQUAL "NOTFOUND") |
| 304 | set_property(TARGET ${test_name} PROPERTY FOLDER "${test_suite_folder}") |
| 305 | endif () |
| 306 | |
| 307 | # Visual Studio 2012 only supports up to 8 template parameters in |
| 308 | # std::tr1::tuple by default, but gtest requires 10 |
| 309 | if (MSVC AND MSVC_VERSION EQUAL 1700) |
| 310 | set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS _VARIADIC_MAX=10) |
| 311 | endif () |
| 312 | |
| 313 | include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) |
| 314 | set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_RTTI=0) |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 315 | if (NOT LLVM_ENABLE_THREADS) |
| 316 | set_property(TARGET ${test_name} APPEND PROPERTY COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0) |
| 317 | endif () |
| 318 | |
Chandler Carruth | 582e8a5 | 2012-06-21 18:44:24 +0000 | [diff] [blame] | 319 | get_property(target_compile_flags TARGET ${test_name} PROPERTY COMPILE_FLAGS) |
| 320 | if (LLVM_COMPILER_IS_GCC_COMPATIBLE) |
| 321 | set(target_compile_flags "${target_compile_flags} -fno-rtti") |
| 322 | elseif (MSVC) |
Aaron Ballman | bde2cd1 | 2013-08-06 23:34:04 +0000 | [diff] [blame] | 323 | llvm_replace_compiler_option(target_compile_flags "/GR" "/GR-") |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 324 | endif () |
Chandler Carruth | 582e8a5 | 2012-06-21 18:44:24 +0000 | [diff] [blame] | 325 | |
| 326 | if (SUPPORTS_NO_VARIADIC_MACROS_FLAG) |
| 327 | set(target_compile_flags "${target_compile_flags} -Wno-variadic-macros") |
| 328 | endif () |
| 329 | set_property(TARGET ${test_name} PROPERTY COMPILE_FLAGS "${target_compile_flags}") |
Chandler Carruth | a5d42f8 | 2012-06-21 05:16:58 +0000 | [diff] [blame] | 330 | endfunction() |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 331 | |
| 332 | # This function provides an automatic way to 'configure'-like generate a file |
Alp Toker | 171b0c3 | 2013-12-20 00:33:39 +0000 | [diff] [blame] | 333 | # based on a set of common and custom variables, specifically targeting the |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 334 | # variables needed for the 'lit.site.cfg' files. This function bundles the |
| 335 | # common variables that any Lit instance is likely to need, and custom |
| 336 | # variables can be passed in. |
| 337 | function(configure_lit_site_cfg input output) |
| 338 | foreach(c ${LLVM_TARGETS_TO_BUILD}) |
| 339 | set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") |
| 340 | endforeach(c) |
| 341 | set(TARGETS_TO_BUILD ${TARGETS_BUILT}) |
| 342 | |
| 343 | set(SHLIBEXT "${LTDL_SHLIB_EXT}") |
NAKAMURA Takumi | e73df85 | 2013-12-16 16:03:08 +0000 | [diff] [blame] | 344 | set(SHLIBDIR "${LLVM_LIBRARY_OUTPUT_INTDIR}") |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 345 | |
| 346 | if(BUILD_SHARED_LIBS) |
| 347 | set(LLVM_SHARED_LIBS_ENABLED "1") |
| 348 | else() |
| 349 | set(LLVM_SHARED_LIBS_ENABLED "0") |
| 350 | endif(BUILD_SHARED_LIBS) |
| 351 | |
| 352 | if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") |
| 353 | set(SHLIBPATH_VAR "DYLD_LIBRARY_PATH") |
| 354 | else() # Default for all other unix like systems. |
| 355 | # CMake hardcodes the library locaction using rpath. |
| 356 | # Therefore LD_LIBRARY_PATH is not required to run binaries in the |
| 357 | # build dir. We pass it anyways. |
| 358 | set(SHLIBPATH_VAR "LD_LIBRARY_PATH") |
| 359 | endif() |
| 360 | |
| 361 | # Configuration-time: See Unit/lit.site.cfg.in |
NAKAMURA Takumi | 0dc10d5 | 2013-12-04 11:15:17 +0000 | [diff] [blame] | 362 | if (CMAKE_CFG_INTDIR STREQUAL ".") |
| 363 | set(LLVM_BUILD_MODE ".") |
| 364 | else () |
| 365 | set(LLVM_BUILD_MODE "%(build_mode)s") |
| 366 | endif () |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 367 | |
| 368 | set(LLVM_SOURCE_DIR ${LLVM_MAIN_SRC_DIR}) |
| 369 | set(LLVM_BINARY_DIR ${LLVM_BINARY_DIR}) |
NAKAMURA Takumi | e73df85 | 2013-12-16 16:03:08 +0000 | [diff] [blame] | 370 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) |
| 371 | string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLVM_LIBS_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 372 | set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) |
| 373 | set(ENABLE_SHARED ${LLVM_SHARED_LIBS_ENABLED}) |
| 374 | set(SHLIBPATH_VAR ${SHLIBPATH_VAR}) |
| 375 | |
| 376 | if(LLVM_ENABLE_ASSERTIONS AND NOT MSVC_IDE) |
| 377 | set(ENABLE_ASSERTIONS "1") |
| 378 | else() |
| 379 | set(ENABLE_ASSERTIONS "0") |
| 380 | endif() |
| 381 | |
Tim Northover | bfe8468 | 2013-02-14 16:49:32 +0000 | [diff] [blame] | 382 | set(HOST_OS ${CMAKE_SYSTEM_NAME}) |
| 383 | set(HOST_ARCH ${CMAKE_SYSTEM_PROCESSOR}) |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 384 | |
Roman Divacky | c987111 | 2013-08-27 19:25:01 +0000 | [diff] [blame] | 385 | if (CLANG_ENABLE_ARCMT) |
| 386 | set(ENABLE_CLANG_ARCMT "1") |
| 387 | else() |
| 388 | set(ENABLE_CLANG_ARCMT "0") |
| 389 | endif() |
| 390 | if (CLANG_ENABLE_REWRITER) |
| 391 | set(ENABLE_CLANG_REWRITER "1") |
| 392 | else() |
| 393 | set(ENABLE_CLANG_REWRITER "0") |
| 394 | endif() |
| 395 | if (CLANG_ENABLE_STATIC_ANALYZER) |
| 396 | set(ENABLE_CLANG_STATIC_ANALYZER "1") |
| 397 | else() |
| 398 | set(ENABLE_CLANG_STATIC_ANALYZER "0") |
| 399 | endif() |
| 400 | |
Chandler Carruth | 3511dd3 | 2012-06-28 06:36:24 +0000 | [diff] [blame] | 401 | configure_file(${input} ${output} @ONLY) |
| 402 | endfunction() |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 403 | |
| 404 | # A raw function to create a lit target. This is used to implement the testuite |
| 405 | # management functions. |
| 406 | function(add_lit_target target comment) |
NAKAMURA Takumi | 69a89c7 | 2013-12-19 17:11:08 +0000 | [diff] [blame] | 407 | parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 408 | set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}") |
| 409 | separate_arguments(LIT_ARGS) |
NAKAMURA Takumi | 0dc10d5 | 2013-12-04 11:15:17 +0000 | [diff] [blame] | 410 | if (NOT CMAKE_CFG_INTDIR STREQUAL ".") |
| 411 | list(APPEND LIT_ARGS --param build_mode=${CMAKE_CFG_INTDIR}) |
| 412 | endif () |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 413 | set(LIT_COMMAND |
| 414 | ${PYTHON_EXECUTABLE} |
NAKAMURA Takumi | 69a89c7 | 2013-12-19 17:11:08 +0000 | [diff] [blame] | 415 | ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 416 | ${LIT_ARGS} |
| 417 | ) |
| 418 | foreach(param ${ARG_PARAMS}) |
| 419 | list(APPEND LIT_COMMAND --param ${param}) |
| 420 | endforeach() |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 421 | if( ARG_DEPENDS ) |
| 422 | add_custom_target(${target} |
| 423 | COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS} |
| 424 | COMMENT "${comment}" |
| 425 | ) |
| 426 | add_dependencies(${target} ${ARG_DEPENDS}) |
| 427 | else() |
| 428 | add_custom_target(${target} |
Nico Weber | b42359d | 2013-12-29 00:11:20 +0000 | [diff] [blame] | 429 | COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.") |
NAKAMURA Takumi | 04a664e | 2012-12-24 22:43:59 +0000 | [diff] [blame] | 430 | message(STATUS "${target} does nothing.") |
| 431 | endif() |
NAKAMURA Takumi | 03fc730 | 2013-12-02 11:31:19 +0000 | [diff] [blame] | 432 | |
| 433 | # Tests should be excluded from "Build Solution". |
| 434 | set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 435 | endfunction() |
| 436 | |
| 437 | # A function to add a set of lit test suites to be driven through 'check-*' targets. |
| 438 | function(add_lit_testsuite target comment) |
| 439 | parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) |
| 440 | |
NAKAMURA Takumi | 54d2274 | 2012-10-10 13:32:55 +0000 | [diff] [blame] | 441 | # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all. |
| 442 | if(NOT EXCLUDE_FROM_ALL) |
| 443 | # Register the testsuites, params and depends for the global check rule. |
| 444 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS}) |
| 445 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS}) |
| 446 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS}) |
| 447 | set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS}) |
| 448 | endif() |
Chandler Carruth | 69ce665 | 2012-06-30 10:14:14 +0000 | [diff] [blame] | 449 | |
| 450 | # Produce a specific suffixed check rule. |
| 451 | add_lit_target(${target} ${comment} |
| 452 | ${ARG_DEFAULT_ARGS} |
| 453 | PARAMS ${ARG_PARAMS} |
| 454 | DEPENDS ${ARG_DEPENDS} |
| 455 | ARGS ${ARG_ARGS} |
| 456 | ) |
| 457 | endfunction() |