| Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 +0000 | [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) |
| 4 | cmake_minimum_required(VERSION 3.4.3) |
| 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 +0000 | [diff] [blame] | 14 | execute_process(COMMAND "${LLVM_CONFIG_PATH}" |
| 15 | "--obj-root" |
| 16 | "--includedir" |
| Michal Gorny | 47132e5 | 2017-01-09 23:17:10 +0000 | [diff] [blame] | 17 | "--cmakedir" |
| Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 +0000 | [diff] [blame] | 18 | "--src-root" |
| Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 +0000 | [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 +0000 | [diff] [blame] | 30 | list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH) |
| Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 +0000 | [diff] [blame] | 31 | list(GET LLVM_CONFIG_OUTPUT 3 MAIN_SRC_DIR) |
| Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 +0000 | [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 +0000 | [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 +0000 | [diff] [blame] | 36 | |
| 37 | file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR) |
| Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 +0000 | [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 +0000 | [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 +0000 | [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) |
| Michal Gorny | da7ceb5 | 2017-01-31 14:10:20 +0000 | [diff] [blame] | 57 | |
| 58 | if(LLVM_INCLUDE_TESTS) |
| 59 | set(Python_ADDITIONAL_VERSIONS 2.7) |
| 60 | include(FindPythonInterp) |
| 61 | if(NOT PYTHONINTERP_FOUND) |
| 62 | message(FATAL_ERROR |
| 63 | "Unable to find Python interpreter, required for testing. |
| 64 | |
| 65 | Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") |
| 66 | endif() |
| 67 | |
| 68 | if(${PYTHON_VERSION_STRING} VERSION_LESS 2.7) |
| 69 | message(FATAL_ERROR "Python 2.7 or newer is required") |
| 70 | endif() |
| 71 | |
| 72 | # Check prebuilt llvm/utils. |
| 73 | if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX} |
| 74 | AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX}) |
| 75 | set(LLVM_UTILS_PROVIDED ON) |
| 76 | endif() |
| 77 | |
| 78 | if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 79 | # Note: path not really used, except for checking if lit was found |
| 80 | set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py) |
| 81 | if(NOT LLVM_UTILS_PROVIDED) |
| 82 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck) |
| 83 | add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not) |
| 84 | set(LLVM_UTILS_PROVIDED ON) |
| 85 | set(LLD_TEST_DEPS FileCheck not) |
| 86 | endif() |
| 87 | set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) |
| 88 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h |
| 89 | AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 90 | AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt) |
| 91 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
| 92 | endif() |
| 93 | else() |
| 94 | # Seek installed Lit. |
| 95 | find_program(LLVM_LIT |
| 96 | NAMES llvm-lit lit.py lit |
| 97 | PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit" |
| 98 | DOC "Path to lit.py") |
| 99 | endif() |
| 100 | |
| 101 | if(LLVM_LIT) |
| 102 | # Define the default arguments to use with 'lit', and an option for the user |
| 103 | # to override. |
| 104 | set(LIT_ARGS_DEFAULT "-sv") |
| 105 | if (MSVC OR XCODE) |
| 106 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 107 | endif() |
| 108 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 109 | |
| 110 | # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. |
| 111 | if(WIN32 AND NOT CYGWIN) |
| 112 | set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") |
| 113 | endif() |
| 114 | else() |
| 115 | set(LLVM_INCLUDE_TESTS OFF) |
| 116 | endif() |
| 117 | endif() |
| Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 +0000 | [diff] [blame] | 118 | endif() |
| 119 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 120 | set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| Pete Cooper | 69b18f4 | 2016-01-07 00:14:09 +0000 | [diff] [blame] | 121 | set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include ) |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 122 | set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 123 | |
| Shankar Easwaran | c3550f9 | 2014-10-08 03:47:51 +0000 | [diff] [blame] | 124 | # Compute the LLD version from the LLVM version. |
| 125 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION |
| 126 | ${PACKAGE_VERSION}) |
| 127 | message(STATUS "LLD version: ${LLD_VERSION}") |
| 128 | |
| 129 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR |
| 130 | ${LLD_VERSION}) |
| 131 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR |
| 132 | ${LLD_VERSION}) |
| 133 | |
| 134 | # Determine LLD revision and repository. |
| 135 | # TODO: Figure out a way to get the revision and the repository on windows. |
| 136 | if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" ) |
| 137 | execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR} |
| 138 | OUTPUT_VARIABLE LLD_REVISION) |
| 139 | |
| 140 | execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR} |
| 141 | OUTPUT_VARIABLE LLD_REPOSITORY) |
| 142 | if ( LLD_REPOSITORY ) |
| 143 | # Replace newline characters with spaces |
| 144 | string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY}) |
| 145 | # Remove leading spaces |
| 146 | STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" ) |
| 147 | # Remove trailing spaces |
| 148 | string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY}) |
| 149 | endif() |
| 150 | |
| 151 | if ( LLD_REVISION ) |
| 152 | # Replace newline characters with spaces |
| 153 | string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION}) |
| 154 | # Remove leading spaces |
| 155 | STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" ) |
| 156 | # Remove trailing spaces |
| 157 | string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION}) |
| 158 | endif() |
| 159 | endif () |
| 160 | |
| 161 | # Configure the Version.inc file. |
| 162 | configure_file( |
| 163 | ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Config/Version.inc.in |
| 164 | ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Config/Version.inc) |
| 165 | |
| 166 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 167 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
| 168 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 169 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 170 | "from there, passing the path to this source directory as the last argument. " |
| 171 | "This process created the file `CMakeCache.txt' and the directory " |
| 172 | "`CMakeFiles'. Please delete them.") |
| 173 | endif() |
| 174 | |
| Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 175 | list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules") |
| 176 | |
| Petr Hosek | f367a2a | 2016-12-23 00:22:47 +0000 | [diff] [blame] | 177 | include(AddLLD) |
| 178 | |
| Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame] | 179 | option(LLD_USE_VTUNE |
| 180 | "Enable VTune user task tracking." |
| 181 | OFF) |
| 182 | if (LLD_USE_VTUNE) |
| 183 | find_package(VTune) |
| 184 | if (VTUNE_FOUND) |
| 185 | include_directories(${VTune_INCLUDE_DIRS}) |
| 186 | list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES}) |
| 187 | add_definitions(-DLLD_HAS_VTUNE) |
| 188 | endif() |
| 189 | endif() |
| 190 | |
| Petr Hosek | f367a2a | 2016-12-23 00:22:47 +0000 | [diff] [blame] | 191 | option(LLD_BUILD_TOOLS |
| 192 | "Build the lld tools. If OFF, just generate build targets." ON) |
| Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 193 | |
| Zachary Turner | 392b715 | 2014-12-02 17:57:54 +0000 | [diff] [blame] | 194 | if (MSVC) |
| 195 | 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 +0000 | [diff] [blame] | 196 | 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 +0000 | [diff] [blame] | 197 | endif() |
| 198 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 199 | include_directories(BEFORE |
| 200 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 201 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 202 | ) |
| 203 | |
| Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 +0000 | [diff] [blame] | 204 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 205 | install(DIRECTORY include/ |
| 206 | DESTINATION include |
| 207 | FILES_MATCHING |
| 208 | PATTERN "*.h" |
| 209 | PATTERN ".svn" EXCLUDE |
| 210 | ) |
| 211 | endif() |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 212 | |
| 213 | add_subdirectory(lib) |
| Rui Ueyama | 3178b80 | 2016-03-03 01:56:23 +0000 | [diff] [blame] | 214 | add_subdirectory(tools/lld) |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 215 | |
| Greg Fitzgerald | cedca2f | 2015-01-12 21:41:10 +0000 | [diff] [blame] | 216 | if (LLVM_INCLUDE_TESTS) |
| Chris Bieneman | 03c48b0 | 2015-10-01 18:17:47 +0000 | [diff] [blame] | 217 | add_subdirectory(test) |
| Michael J. Spencer | 800de03 | 2012-12-19 00:51:07 +0000 | [diff] [blame] | 218 | add_subdirectory(unittests) |
| 219 | endif() |
| Reid Kleckner | f00daf1 | 2014-04-18 21:59:05 +0000 | [diff] [blame] | 220 | |
| 221 | add_subdirectory(docs) |
| Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 +0000 | [diff] [blame] | 222 | add_subdirectory(COFF) |
| Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 223 | add_subdirectory(ELF) |