| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 1 | # If we are not building as a part of LLVM, build lld as a standalone project, |
| 2 | # using LLVM as an external library. |
| 3 | |
| Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 4 | |
| 5 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 6 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 7 | project(lld) |
| 8 | cmake_minimum_required(VERSION 2.8) |
| 9 | |
| 10 | set(LLD_PATH_TO_LLVM_SOURCE "" CACHE PATH |
| 11 | "Path to LLVM source code. Not necessary if using an installed LLVM.") |
| 12 | set(LLD_PATH_TO_LLVM_BUILD "" CACHE PATH |
| 13 | "Path to the directory where LLVM was built or installed.") |
| 14 | |
| 15 | if (LLD_PATH_TO_LLVM_SOURCE) |
| 16 | if (NOT EXISTS "${LLD_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake") |
| 17 | message(FATAL_ERROR "Please set LLD_PATH_TO_LLVM_SOURCE to the root " |
| 18 | "directory of LLVM source code.") |
| 19 | else() |
| 20 | get_filename_component(LLVM_MAIN_SRC_DIR ${LLD_PATH_TO_LLVM_SOURCE} |
| 21 | ABSOLUTE) |
| 22 | list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") |
| 23 | endif() |
| 24 | endif() |
| 25 | |
| 26 | list(APPEND CMAKE_MODULE_PATH "${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake") |
| 27 | |
| 28 | get_filename_component(PATH_TO_LLVM_BUILD ${LLD_PATH_TO_LLVM_BUILD} |
| 29 | ABSOLUTE) |
| 30 | |
| 31 | include(AddLLVM) |
| Michael J. Spencer | db14508 | 2012-12-10 23:52:34 +0000 | [diff] [blame] | 32 | include(TableGen) |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 33 | include("${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake") |
| 34 | include(HandleLLVMOptions) |
| 35 | |
| 36 | set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 37 | |
| 38 | set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include") |
| 39 | set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR}) |
| 40 | |
| 41 | set(CMAKE_INCLUDE_CURRENT_DIR ON) |
| 42 | include_directories("${PATH_TO_LLVM_BUILD}/include" |
| 43 | "${LLVM_MAIN_INCLUDE_DIR}") |
| 44 | link_directories("${PATH_TO_LLVM_BUILD}/lib") |
| 45 | |
| Michael J. Spencer | db14508 | 2012-12-10 23:52:34 +0000 | [diff] [blame] | 46 | if( EXISTS "${LLD_PATH_TO_LLVM_BUILD}/bin/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}" ) |
| 47 | set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}") |
| 48 | else() |
| 49 | # FIXME: This is an utter hack. |
| 50 | set(LLVM_TABLEGEN_EXE "${PATH_TO_LLVM_BUILD}/bin/Debug/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}") |
| 51 | endif() |
| 52 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 53 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 54 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 55 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 56 | |
| 57 | set(LLD_BUILT_STANDALONE 1) |
| 58 | endif() |
| 59 | |
| 60 | set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 61 | set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 62 | |
| 63 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) |
| 64 | message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite " |
| 65 | "the makefiles distributed with LLVM. Please create a directory and run cmake " |
| 66 | "from there, passing the path to this source directory as the last argument. " |
| 67 | "This process created the file `CMakeCache.txt' and the directory " |
| 68 | "`CMakeFiles'. Please delete them.") |
| 69 | endif() |
| 70 | |
| Michael J. Spencer | d4eb47c | 2013-04-06 00:56:40 +0000 | [diff] [blame^] | 71 | list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules") |
| 72 | |
| 73 | option(LLD_USE_VTUNE |
| 74 | "Enable VTune user task tracking." |
| 75 | OFF) |
| 76 | if (LLD_USE_VTUNE) |
| 77 | find_package(VTune) |
| 78 | if (VTUNE_FOUND) |
| 79 | include_directories(${VTune_INCLUDE_DIRS}) |
| 80 | list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES}) |
| 81 | add_definitions(-DLLD_HAS_VTUNE) |
| 82 | endif() |
| 83 | endif() |
| 84 | |
| Michael J. Spencer | c404806 | 2013-01-05 04:16:52 +0000 | [diff] [blame] | 85 | # lld requires c++11 to build. Make sure that we have a compiler and standard |
| 86 | # library combination that can do that. |
| 87 | if (MSVC11) |
| 88 | # Do nothing, we're good. |
| 89 | elseif (NOT MSVC) |
| 90 | # gcc and clang require the -std=c++0x or -std=c++11 flag. |
| 91 | if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR |
| 92 | "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 93 | if (NOT ("${CMAKE_CXX_FLAGS}" MATCHES "-std=c\\+\\+0x" OR |
| Chandler Carruth | 8b95c03 | 2013-01-19 09:41:42 +0000 | [diff] [blame] | 94 | "${CMAKE_CXX_FLAGS}" MATCHES "-std=gnu\\+\\+0x" OR |
| 95 | "${CMAKE_CXX_FLAGS}" MATCHES "-std=c\\+\\+11" OR |
| 96 | "${CMAKE_CXX_FLAGS}" MATCHES "-std=gnu\\+\\+11")) |
| Michael J. Spencer | c404806 | 2013-01-05 04:16:52 +0000 | [diff] [blame] | 97 | message(FATAL_ERROR |
| 98 | "lld requires c++11. Clang and gcc require -std=c++0x or -std=c++11 to " |
| 99 | "enter this mode. Please set CMAKE_CXX_FLAGS accordingly.") |
| 100 | endif() |
| Michael J. Spencer | e753cbc | 2012-03-09 05:27:43 +0000 | [diff] [blame] | 101 | endif() |
| Michael J. Spencer | c404806 | 2013-01-05 04:16:52 +0000 | [diff] [blame] | 102 | else() |
| 103 | message(FATAL_ERROR "The selected compiler does not support c++11 which is " |
| 104 | "required to build lld.") |
| Nick Kledzik | 1a6615d | 2012-03-08 00:18:30 +0000 | [diff] [blame] | 105 | endif() |
| 106 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 107 | macro(add_lld_library name) |
| 108 | llvm_process_sources(srcs ${ARGN}) |
| 109 | if (MSVC_IDE OR XCODE) |
| 110 | string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) |
| 111 | list(GET split_path -1 dir) |
| 112 | file(GLOB_RECURSE headers |
| 113 | ../../include/lld${dir}/*.h) |
| 114 | set(srcs ${srcs} ${headers}) |
| 115 | endif() |
| 116 | if (MODULE) |
| 117 | set(libkind MODULE) |
| 118 | elseif (SHARED_LIBRARY) |
| 119 | set(libkind SHARED) |
| 120 | else() |
| 121 | set(libkind) |
| 122 | endif() |
| 123 | add_library(${name} ${libkind} ${srcs}) |
| 124 | if (LLVM_COMMON_DEPENDS) |
| 125 | add_dependencies(${name} ${LLVM_COMMON_DEPENDS}) |
| 126 | endif() |
| 127 | |
| 128 | target_link_libraries(${name} ${LLVM_USED_LIBS}) |
| 129 | llvm_config(${name} ${LLVM_LINK_COMPONENTS}) |
| 130 | target_link_libraries(${name} ${LLVM_COMMON_LIBS}) |
| 131 | link_system_libs(${name}) |
| 132 | |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 133 | install(TARGETS ${name} |
| 134 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 135 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 136 | set_target_properties(${name} PROPERTIES FOLDER "lld libraries") |
| 137 | endmacro(add_lld_library) |
| 138 | |
| 139 | macro(add_lld_executable name) |
| 140 | add_llvm_executable(${name} ${ARGN}) |
| 141 | set_target_properties(${name} PROPERTIES FOLDER "lld executables") |
| 142 | endmacro(add_lld_executable) |
| 143 | |
| 144 | include_directories(BEFORE |
| 145 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 146 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 147 | ) |
| 148 | |
| 149 | install(DIRECTORY include/ |
| 150 | DESTINATION include |
| 151 | FILES_MATCHING |
| 152 | PATTERN "*.h" |
| 153 | PATTERN ".svn" EXCLUDE |
| 154 | ) |
| 155 | |
| 156 | add_subdirectory(lib) |
| 157 | add_subdirectory(tools) |
| Michael J. Spencer | a55e37f | 2013-03-01 00:03:36 +0000 | [diff] [blame] | 158 | add_subdirectory(utils) |
| Michael J. Spencer | 773a8fb | 2011-12-18 08:27:59 +0000 | [diff] [blame] | 159 | |
| 160 | add_subdirectory(test) |
| Michael J. Spencer | 800de03 | 2012-12-19 00:51:07 +0000 | [diff] [blame] | 161 | |
| 162 | if (LLVM_INCLUDE_TESTS AND NOT LLD_BUILT_STANDALONE) |
| 163 | add_subdirectory(unittests) |
| 164 | endif() |