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