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) |
| 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 | |
| 14 | execute_process(COMMAND "${LLVM_CONFIG_PATH}" "--obj-root" "--includedir" |
Michal Gorny | 47132e5 | 2017-01-09 23:17:10 | [diff] [blame] | 15 | "--cmakedir" |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 16 | RESULT_VARIABLE HAD_ERROR |
| 17 | OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT |
| 18 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 19 | if(HAD_ERROR) |
| 20 | message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") |
| 21 | endif() |
| 22 | |
| 23 | string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" LLVM_CONFIG_OUTPUT "${LLVM_CONFIG_OUTPUT}") |
| 24 | |
| 25 | list(GET LLVM_CONFIG_OUTPUT 0 OBJ_ROOT) |
| 26 | list(GET LLVM_CONFIG_OUTPUT 1 MAIN_INCLUDE_DIR) |
Michal Gorny | 47132e5 | 2017-01-09 23:17:10 | [diff] [blame] | 27 | list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 28 | |
| 29 | set(LLVM_OBJ_ROOT ${OBJ_ROOT} CACHE PATH "path to LLVM build tree") |
| 30 | set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "path to llvm/include") |
| 31 | |
| 32 | file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR) |
Saleem Abdulrasool | f1af26d | 2016-12-12 05:47:40 | [diff] [blame] | 33 | |
| 34 | if(NOT EXISTS "${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 35 | message(FATAL_ERROR "LLVMConfig.cmake not found") |
| 36 | endif() |
| 37 | include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 38 | |
| 39 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") |
| 40 | |
| 41 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 42 | include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS}) |
| 43 | link_directories(${LLVM_LIBRARY_DIRS}) |
| 44 | |
| 45 | set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) |
| 46 | find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) |
| 47 | |
| 48 | include(AddLLVM) |
| 49 | include(TableGen) |
| 50 | include(HandleLLVMOptions) |
| 51 | endif() |
| 52 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 53 | set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Pete Cooper | 69b18f4 | 2016-01-07 00:14:09 | [diff] [blame] | 54 | set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include ) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 55 | set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 56 | |
Shankar Easwaran | c3550f9 | 2014-10-08 03:47:51 | [diff] [blame] | 57 | # Compute the LLD version from the LLVM version. |
| 58 | string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION |
| 59 | ${PACKAGE_VERSION}) |
| 60 | message(STATUS "LLD version: ${LLD_VERSION}") |
| 61 | |
| 62 | string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR |
| 63 | ${LLD_VERSION}) |
| 64 | string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR |
| 65 | ${LLD_VERSION}) |
| 66 | |
| 67 | # Determine LLD revision and repository. |
| 68 | # TODO: Figure out a way to get the revision and the repository on windows. |
| 69 | if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" ) |
| 70 | execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR} |
| 71 | OUTPUT_VARIABLE LLD_REVISION) |
| 72 | |
| 73 | execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR} |
| 74 | OUTPUT_VARIABLE LLD_REPOSITORY) |
| 75 | if ( LLD_REPOSITORY ) |
| 76 | # Replace newline characters with spaces |
| 77 | string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY}) |
| 78 | # Remove leading spaces |
| 79 | STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" ) |
| 80 | # Remove trailing spaces |
| 81 | string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY}) |
| 82 | endif() |
| 83 | |
| 84 | if ( LLD_REVISION ) |
| 85 | # Replace newline characters with spaces |
| 86 | string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION}) |
| 87 | # Remove leading spaces |
| 88 | STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" ) |
| 89 | # Remove trailing spaces |
| 90 | string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION}) |
| 91 | endif() |
| 92 | endif () |
| 93 | |
| 94 | # Configure the Version.inc file. |
| 95 | configure_file( |
| 96 | ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Config/Version.inc.in |
| 97 | ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Config/Version.inc) |
| 98 | |
| 99 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 100 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
| 101 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 102 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 103 | "from there, passing the path to this source directory as the last argument. " |
| 104 | "This process created the file `CMakeCache.txt' and the directory " |
| 105 | "`CMakeFiles'. Please delete them.") |
| 106 | endif() |
| 107 | |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 108 | list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules") |
| 109 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 110 | include(AddLLD) |
| 111 | |
Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 | [diff] [blame] | 112 | option(LLD_USE_VTUNE |
| 113 | "Enable VTune user task tracking." |
| 114 | OFF) |
| 115 | if (LLD_USE_VTUNE) |
| 116 | find_package(VTune) |
| 117 | if (VTUNE_FOUND) |
| 118 | include_directories(${VTune_INCLUDE_DIRS}) |
| 119 | list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES}) |
| 120 | add_definitions(-DLLD_HAS_VTUNE) |
| 121 | endif() |
| 122 | endif() |
| 123 | |
Petr Hosek | f367a2a | 2016-12-23 00:22:47 | [diff] [blame] | 124 | option(LLD_BUILD_TOOLS |
| 125 | "Build the lld tools. If OFF, just generate build targets." ON) |
Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 | [diff] [blame] | 126 | |
Zachary Turner | 392b715 | 2014-12-02 17:57:54 | [diff] [blame] | 127 | if (MSVC) |
| 128 | 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] | 129 | 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] | 130 | endif() |
| 131 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 132 | include_directories(BEFORE |
| 133 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 134 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 135 | ) |
| 136 | |
Hans Wennborg | 2391fdd | 2013-08-24 00:24:15 | [diff] [blame] | 137 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 138 | install(DIRECTORY include/ |
| 139 | DESTINATION include |
| 140 | FILES_MATCHING |
| 141 | PATTERN "*.h" |
| 142 | PATTERN ".svn" EXCLUDE |
| 143 | ) |
| 144 | endif() |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 145 | |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 146 | add_subdirectory(lib) |
Rui Ueyama | 3178b80 | 2016-03-03 01:56:23 | [diff] [blame] | 147 | add_subdirectory(tools/lld) |
Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 | [diff] [blame] | 148 | |
Greg Fitzgerald | cedca2f | 2015-01-12 21:41:10 | [diff] [blame] | 149 | if (LLVM_INCLUDE_TESTS) |
Chris Bieneman | 03c48b0 | 2015-10-01 18:17:47 | [diff] [blame] | 150 | add_subdirectory(test) |
Michael J. Spencer | 800de03 | 2012-12-19 00:51:07 | [diff] [blame] | 151 | add_subdirectory(unittests) |
| 152 | endif() |
Reid Kleckner | f00daf1 | 2014-04-18 21:59:05 | [diff] [blame] | 153 | |
| 154 | add_subdirectory(docs) |
Rui Ueyama | 411c6360 | 2015-05-28 19:09:30 | [diff] [blame] | 155 | add_subdirectory(COFF) |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 | [diff] [blame] | 156 | add_subdirectory(ELF) |