Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 1 | # Check if lld is built as a standalone project. |
| 2 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 3 | project(lld) |
Louis Dionne | afa1afd | 2020-04-22 15:15:05 | [diff] [blame] | 4 | cmake_minimum_required(VERSION 3.13.4) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 5 | |
| 6 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 7 | set(LLD_BUILT_STANDALONE TRUE) |
| 8 | |
| 9 | find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") |
| 10 | if(NOT LLVM_CONFIG_PATH) |
| 11 | message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") |
| 12 | endif() |
| 13 | |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 14 | execute_process(COMMAND "${LLVM_CONFIG_PATH}" |
| 15 | "--obj-root" |
| 16 | "--includedir" |
Michal Gorny | 47132e5 | 2017-01-09 23:17:10 | [diff] [blame] | 17 | "--cmakedir" |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 18 | "--src-root" |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 19 | RESULT_VARIABLE HAD_ERROR |
| 20 | OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT |
| 21 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 22 | if(HAD_ERROR) |
| 23 | message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") |
| 24 | endif() |
| 25 | |
| 26 | string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" LLVM_CONFIG_OUTPUT "${LLVM_CONFIG_OUTPUT}") |
| 27 | |
| 28 | list(GET LLVM_CONFIG_OUTPUT 0 OBJ_ROOT) |
| 29 | list(GET LLVM_CONFIG_OUTPUT 1 MAIN_INCLUDE_DIR) |
Michal Gorny | 47132e5 | 2017-01-09 23:17:10 | [diff] [blame] | 30 | list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH) |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 31 | list(GET LLVM_CONFIG_OUTPUT 3 MAIN_SRC_DIR) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 32 | |
| 33 | set(LLVM_OBJ_ROOT ${OBJ_ROOT} CACHE PATH "path to LLVM build tree") |
| 34 | set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "path to llvm/include") |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 35 | set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 36 | |
| 37 | file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 38 | |
| 39 | if(NOT EXISTS "${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 40 | message(FATAL_ERROR "LLVMConfig.cmake not found") |
| 41 | endif() |
| 42 | include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 43 | |
| 44 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") |
| 45 | |
| 46 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 47 | include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS}) |
| 48 | link_directories(${LLVM_LIBRARY_DIRS}) |
| 49 | |
Michal Gorny | 30dc91a | 2017-01-25 19:33:14 | [diff] [blame] | 50 | set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 51 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
| 52 | find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) |
| 53 | |
| 54 | include(AddLLVM) |
| 55 | include(TableGen) |
| 56 | include(HandleLLVMOptions) |
Josh Stone | b26b32b | 2020-08-17 22:31:32 | [diff] [blame] | 57 | include(CheckAtomic) |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 58 | |
| 59 | if(LLVM_INCLUDE_TESTS) |
Raul Tambre | 86bd8f8 | 2020-09-05 14:52:23 | [diff] [blame] | 60 | find_package(Python3 COMPONENTS Interpreter) |
| 61 | if(NOT Python3_Interpreter_FOUND) |
| 62 | message(WARNING "Python3 not found, using python2 as a fallback") |
| 63 | find_package(Python2 COMPONENTS Interpreter REQUIRED) |
| 64 | if(Python2_VERSION VERSION_LESS 2.7) |
| 65 | message(SEND_ERROR "Python 2.7 or newer is required") |
Saleem Abdulrasool | 216833b | 2020-04-29 01:37:28 | [diff] [blame] | 66 | endif() |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 67 | |
Raul Tambre | 86bd8f8 | 2020-09-05 14:52:23 | [diff] [blame] | 68 | # Treat python2 as python3 |
| 69 | add_executable(Python3::Interpreter IMPORTED) |
Saleem Abdulrasool | 216833b | 2020-04-29 01:37:28 | [diff] [blame] | 70 | set_target_properties(Python3::Interpreter PROPERTIES |
Raul Tambre | 86bd8f8 | 2020-09-05 14:52:23 | [diff] [blame] | 71 | IMPORTED_LOCATION ${Python2_EXECUTABLE}) |
| 72 | set(Python3_EXECUTABLE ${Python2_EXECUTABLE}) |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 73 | endif() |
| 74 | |
| 75 | # Check prebuilt llvm/utils. |
| 76 | if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} |
| 77 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}) |
| 78 | set(LLVM_UTILS_PROVIDED ON) |
| 79 | endif() |
| 80 | |
| 81 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 82 | # Note: path not really used, except for checking if lit was found |
| 83 | set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 84 | if(NOT LLVM_UTILS_PROVIDED) |
| 85 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) |
| 86 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not) |
| 87 | set(LLVM_UTILS_PROVIDED ON) |
| 88 | set(LLD_TEST_DEPS FileCheck not) |
| 89 | endif() |
| 90 | set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) |
| 91 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h |
| 92 | AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 93 | AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt) |
| 94 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
| 95 | endif() |
| 96 | else() |
| 97 | # Seek installed Lit. |
| 98 | find_program(LLVM_LIT |
| 99 | NAMES llvm-lit lit.py lit |
| 100 | PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit" |
| 101 | DOC "Path to lit.py") |
| 102 | endif() |
| 103 | |
| 104 | if(LLVM_LIT) |
| 105 | # Define the default arguments to use with 'lit', and an option for the user |
| 106 | # to override. |
| 107 | set(LIT_ARGS_DEFAULT "-sv") |
| 108 | if (MSVC OR XCODE) |
| 109 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 110 | endif() |
| 111 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 112 | |
| 113 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 114 | if(WIN32 AND NOT CYGWIN) |
| 115 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 116 | endif() |
| 117 | else() |
| 118 | set(LLVM_INCLUDE_TESTS OFF) |
| 119 | endif() |
| 120 | endif() |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 121 | endif() |
| 122 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 123 | set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Pete Cooper | 69b18f4 | 2016-01-07 00:14:09 | [diff] [blame] | 124 | set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include ) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 125 | set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 126 | |
stevewan | 44f7b40 | 2020-05-11 22:33:55 | [diff] [blame] | 127 | set(LLD_VENDOR ${PACKAGE_VENDOR} CACHE STRING |
| 128 | "Vendor-specific text for showing with version information.") |
| 129 | |
| 130 | if(LLD_VENDOR) |
| 131 | add_definitions(-DLLD_VENDOR="${LLD_VENDOR}") |
| 132 | endif() |
| 133 | |
Shankar Easwaran | c3550f9 | 2014-10-08 03:47:51 | [diff] [blame] | 134 | # Compute the LLD version from the LLVM version. |
| 135 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION |
| 136 | ${PACKAGE_VERSION}) |
| 137 | message(STATUS "LLD version: ${LLD_VERSION}") |
| 138 | |
| 139 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR |
| 140 | ${LLD_VERSION}) |
| 141 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR |
| 142 | ${LLD_VERSION}) |
| 143 | |
Nico Weber | 4f5c65a | 2020-01-16 15:12:06 | [diff] [blame] | 144 | # Configure the Version.inc file. |
| 145 | configure_file( |
| 146 | ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in |
| 147 | ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc) |
| 148 | |
| 149 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 150 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
| 151 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 152 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 153 | "from there, passing the path to this source directory as the last argument. " |
| 154 | "This process created the file `CMakeCache.txt' and the directory " |
| 155 | "`CMakeFiles'. Please delete them.") |
| 156 | endif() |
| 157 | |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 158 | list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules") |
| 159 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 160 | include(AddLLD) |
| 161 | |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 162 | option(LLD_USE_VTUNE |
| 163 | "Enable VTune user task tracking." |
| 164 | OFF) |
| 165 | if (LLD_USE_VTUNE) |
| 166 | find_package(VTune) |
| 167 | if (VTUNE_FOUND) |
| 168 | include_directories(${VTune_INCLUDE_DIRS}) |
| 169 | list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES}) |
| 170 | add_definitions(-DLLD_HAS_VTUNE) |
| 171 | endif() |
| 172 | endif() |
| 173 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 174 | option(LLD_BUILD_TOOLS |
| 175 | "Build the lld tools. If OFF, just generate build targets." ON) |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 | [diff] [blame] | 176 | |
Zachary Turner | 392b715 | 2014-12-02 17:57:54 | [diff] [blame] | 177 | if (MSVC) |
| 178 | add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.' |
Michael J. Spencer | b6396ea | 2015-02-25 01:30:13 | [diff] [blame] | 179 | add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header. |
Zachary Turner | 392b715 | 2014-12-02 17:57:54 | [diff] [blame] | 180 | endif() |
| 181 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 182 | include_directories(BEFORE |
| 183 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 184 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 185 | ) |
| 186 | |
Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 | [diff] [blame] | 187 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 188 | install(DIRECTORY include/ |
| 189 | DESTINATION include |
| 190 | FILES_MATCHING |
| 191 | PATTERN "*.h" |
| 192 | PATTERN ".svn" EXCLUDE |
| 193 | ) |
| 194 | endif() |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 195 | |
Rui Ueyama | 3f85170 | 2017-10-02 21:00:41 | [diff] [blame] | 196 | add_subdirectory(Common) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 197 | add_subdirectory(lib) |
Rui Ueyama | 3178b80 | 2016-03-03 01:56:23 | [diff] [blame] | 198 | add_subdirectory(tools/lld) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 199 | |
Greg Fitzgerald | cedca2f | 2015-01-12 21:41:10 | [diff] [blame] | 200 | if (LLVM_INCLUDE_TESTS) |
Chris Bieneman | 03c48b0 | 2015-10-01 18:17:47 | [diff] [blame] | 201 | add_subdirectory(test) |
Michael J. Spencer | 800de03 | 2012-12-19 00:51:07 | [diff] [blame] | 202 | add_subdirectory(unittests) |
| 203 | endif() |
Reid Kleckner | f00daf1 | 2014-04-18 21:59:05 | [diff] [blame] | 204 | |
| 205 | add_subdirectory(docs) |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 | [diff] [blame] | 206 | add_subdirectory(COFF) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 | [diff] [blame] | 207 | add_subdirectory(ELF) |
Fangrui Song | 6acd300 | 2020-04-02 18:54:05 | [diff] [blame] | 208 | add_subdirectory(MachO) |
Martell Malone | 894dbbe | 2017-09-11 17:02:59 | [diff] [blame] | 209 | add_subdirectory(MinGW) |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 210 | add_subdirectory(wasm) |
Matt Arsenault | 2b2a961 | 2020-05-02 22:32:40 | [diff] [blame] | 211 | |
| 212 | add_subdirectory(cmake/modules) |