John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.13.4) |
| 2 | |
Michał Górny | 9dd01a5 | 2022-10-24 04:31:37 | [diff] [blame] | 3 | if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) |
| 4 | set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) |
| 5 | endif() |
| 6 | include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake |
| 7 | NO_POLICY_SCOPE) |
| 8 | |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 9 | # If we are not building as a part of LLVM, build LLD as an |
| 10 | # standalone project, using LLVM as an external library: |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 11 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 12 | project(lld) |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 13 | set(LLD_BUILT_STANDALONE TRUE) |
| 14 | endif() |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 15 | |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 16 | # Must go below project(..) |
| 17 | include(GNUInstallDirs) |
| 18 | |
| 19 | if(LLD_BUILT_STANDALONE) |
Tobias Hieta | b135650 | 2022-08-05 19:45:55 | [diff] [blame] | 20 | set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to") |
Jez Ng | 606cb85 | 2022-02-22 23:14:47 | [diff] [blame] | 21 | set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 22 | set(CMAKE_CXX_EXTENSIONS NO) |
| 23 | |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 24 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 25 | |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 26 | find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") |
John Ericson | e0eeae9 | 2022-02-02 15:37:13 | [diff] [blame] | 27 | list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 28 | |
Tom Stellard | 91f3f0b | 2022-08-06 13:22:19 | [diff] [blame] | 29 | # Turn into CACHE PATHs for overwritting |
| 30 | set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") |
| 31 | set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree") |
| 32 | set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 33 | |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 34 | find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} |
| 35 | NO_DEFAULT_PATH) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 36 | |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 37 | # They are used as destination of target generators. |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 38 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
John Ericson | e941b03 | 2022-08-19 02:44:46 | [diff] [blame] | 39 | 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] | 40 | |
| 41 | include(AddLLVM) |
| 42 | include(TableGen) |
| 43 | include(HandleLLVMOptions) |
Markus Böck | af2796c | 2021-03-15 19:56:08 | [diff] [blame] | 44 | include(GetErrcMessages) |
Josh Stone | b26b32b | 2020-08-17 22:31:32 | [diff] [blame] | 45 | include(CheckAtomic) |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 46 | |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 47 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 48 | |
John Ericson | cc56a50 | 2022-07-26 07:17:30 | [diff] [blame] | 49 | include_directories(${LLVM_INCLUDE_DIRS}) |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 50 | link_directories(${LLVM_LIBRARY_DIRS}) |
| 51 | |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 52 | if(LLVM_INCLUDE_TESTS) |
Christopher Tetreault | 3997076 | 2021-03-15 16:33:31 | [diff] [blame] | 53 | find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED |
| 54 | COMPONENTS Interpreter) |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 55 | |
| 56 | # Check prebuilt llvm/utils. |
| 57 | if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} |
| 58 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}) |
| 59 | set(LLVM_UTILS_PROVIDED ON) |
| 60 | endif() |
| 61 | |
| 62 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 63 | # Note: path not really used, except for checking if lit was found |
| 64 | set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 65 | if(NOT LLVM_UTILS_PROVIDED) |
| 66 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) |
| 67 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not) |
| 68 | set(LLVM_UTILS_PROVIDED ON) |
| 69 | set(LLD_TEST_DEPS FileCheck not) |
| 70 | endif() |
| 71 | set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) |
| 72 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h |
| 73 | AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 74 | AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt) |
| 75 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
| 76 | endif() |
| 77 | else() |
| 78 | # Seek installed Lit. |
| 79 | find_program(LLVM_LIT |
| 80 | NAMES llvm-lit lit.py lit |
| 81 | PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit" |
| 82 | DOC "Path to lit.py") |
| 83 | endif() |
| 84 | |
| 85 | if(LLVM_LIT) |
| 86 | # Define the default arguments to use with 'lit', and an option for the user |
| 87 | # to override. |
| 88 | set(LIT_ARGS_DEFAULT "-sv") |
| 89 | if (MSVC OR XCODE) |
| 90 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 91 | endif() |
| 92 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 93 | |
Markus Böck | af2796c | 2021-03-15 19:56:08 | [diff] [blame] | 94 | get_errc_messages(LLVM_LIT_ERRC_MESSAGES) |
| 95 | |
Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 | [diff] [blame] | 96 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 97 | if(WIN32 AND NOT CYGWIN) |
| 98 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 99 | endif() |
| 100 | else() |
| 101 | set(LLVM_INCLUDE_TESTS OFF) |
| 102 | endif() |
| 103 | endif() |
Mariusz Ceier | 9383e9c | 2021-05-19 15:07:39 | [diff] [blame] | 104 | |
| 105 | if(LLVM_HAVE_LIBXAR) |
| 106 | set(XAR_LIB xar) |
| 107 | endif() |
John Ericson | a1da5f3 | 2022-01-02 06:29:26 | [diff] [blame] | 108 | endif() # standalone |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 109 | |
John Ericson | 07b7498 | 2022-06-11 06:11:59 | [diff] [blame] | 110 | set(LLD_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH |
| 111 | "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") |
| 112 | mark_as_advanced(LLD_TOOLS_INSTALL_DIR) |
| 113 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 114 | set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Pete Cooper | 69b18f4 | 2016-01-07 00:14:09 | [diff] [blame] | 115 | set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include ) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 116 | set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 117 | |
stevewan | 44f7b40 | 2020-05-11 22:33:55 | [diff] [blame] | 118 | set(LLD_VENDOR ${PACKAGE_VENDOR} CACHE STRING |
| 119 | "Vendor-specific text for showing with version information.") |
| 120 | |
| 121 | if(LLD_VENDOR) |
| 122 | add_definitions(-DLLD_VENDOR="${LLD_VENDOR}") |
| 123 | endif() |
| 124 | |
Shankar Easwaran | c3550f9 | 2014-10-08 03:47:51 | [diff] [blame] | 125 | # Compute the LLD version from the LLVM version. |
| 126 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION |
| 127 | ${PACKAGE_VERSION}) |
| 128 | message(STATUS "LLD version: ${LLD_VERSION}") |
| 129 | |
| 130 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR |
| 131 | ${LLD_VERSION}) |
| 132 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR |
| 133 | ${LLD_VERSION}) |
| 134 | |
Nico Weber | 4f5c65a | 2020-01-16 15:12:06 | [diff] [blame] | 135 | # Configure the Version.inc file. |
| 136 | configure_file( |
| 137 | ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in |
| 138 | ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc) |
| 139 | |
| 140 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 141 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
| 142 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 143 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 144 | "from there, passing the path to this source directory as the last argument. " |
| 145 | "This process created the file `CMakeCache.txt' and the directory " |
| 146 | "`CMakeFiles'. Please delete them.") |
| 147 | endif() |
| 148 | |
John Ericson | 8965370 | 2021-12-30 06:22:48 | [diff] [blame] | 149 | # Add path for custom modules. |
| 150 | list(INSERT CMAKE_MODULE_PATH 0 |
| 151 | "${LLD_SOURCE_DIR}/cmake/modules" |
John Ericson | b3af9fb | 2022-01-01 17:51:16 | [diff] [blame] | 152 | "${LLVM_COMMON_CMAKE_UTILS}/Modules" |
John Ericson | 8965370 | 2021-12-30 06:22:48 | [diff] [blame] | 153 | ) |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 154 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 155 | include(AddLLD) |
| 156 | |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 157 | option(LLD_USE_VTUNE |
| 158 | "Enable VTune user task tracking." |
| 159 | OFF) |
| 160 | if (LLD_USE_VTUNE) |
| 161 | find_package(VTune) |
| 162 | if (VTUNE_FOUND) |
| 163 | include_directories(${VTune_INCLUDE_DIRS}) |
| 164 | list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES}) |
| 165 | add_definitions(-DLLD_HAS_VTUNE) |
| 166 | endif() |
| 167 | endif() |
| 168 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 169 | option(LLD_BUILD_TOOLS |
| 170 | "Build the lld tools. If OFF, just generate build targets." ON) |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 | [diff] [blame] | 171 | |
Mateusz Mikuła | 61e0b2b | 2020-09-15 05:39:15 | [diff] [blame] | 172 | option(LLD_DEFAULT_LD_LLD_IS_MINGW |
| 173 | "Use MinGW as the default backend for ld.lld. If OFF, ELF will be used." OFF) |
| 174 | if (LLD_DEFAULT_LD_LLD_IS_MINGW) |
| 175 | add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1") |
| 176 | endif() |
| 177 | |
Zachary Turner | 392b715 | 2014-12-02 17:57:54 | [diff] [blame] | 178 | if (MSVC) |
| 179 | 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] | 180 | 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] | 181 | endif() |
| 182 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 183 | include_directories(BEFORE |
| 184 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 185 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 186 | ) |
| 187 | |
Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 | [diff] [blame] | 188 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 189 | install(DIRECTORY include/ |
John Ericson | 8965370 | 2021-12-30 06:22:48 | [diff] [blame] | 190 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 | [diff] [blame] | 191 | FILES_MATCHING |
| 192 | PATTERN "*.h" |
Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 | [diff] [blame] | 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) |
Rui Ueyama | 3178b80 | 2016-03-03 01:56:23 | [diff] [blame] | 197 | add_subdirectory(tools/lld) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 198 | |
Greg Fitzgerald | cedca2f | 2015-01-12 21:41:10 | [diff] [blame] | 199 | if (LLVM_INCLUDE_TESTS) |
Chris Bieneman | 03c48b0 | 2015-10-01 18:17:47 | [diff] [blame] | 200 | add_subdirectory(test) |
Michael J. Spencer | 800de03 | 2012-12-19 00:51:07 | [diff] [blame] | 201 | endif() |
Reid Kleckner | f00daf1 | 2014-04-18 21:59:05 | [diff] [blame] | 202 | |
| 203 | add_subdirectory(docs) |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 | [diff] [blame] | 204 | add_subdirectory(COFF) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 | [diff] [blame] | 205 | add_subdirectory(ELF) |
Fangrui Song | 6acd300 | 2020-04-02 18:54:05 | [diff] [blame] | 206 | add_subdirectory(MachO) |
Martell Malone | 894dbbe | 2017-09-11 17:02:59 | [diff] [blame] | 207 | add_subdirectory(MinGW) |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 | [diff] [blame] | 208 | add_subdirectory(wasm) |
Matt Arsenault | 2b2a961 | 2020-05-02 22:32:40 | [diff] [blame] | 209 | |
| 210 | add_subdirectory(cmake/modules) |