blob: 48ac5e038cdbd861afb7b5b0a6f86870e6d64128 [file] [log] [blame]
Saleem Abdulrasoolf1af26d2016-12-12 05:47:401# Check if lld is built as a standalone project.
2if(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 Gorny47132e52017-01-09 23:17:1015 "--cmakedir"
Saleem Abdulrasoolf1af26d2016-12-12 05:47:4016 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 Gorny47132e52017-01-09 23:17:1027 list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH)
Saleem Abdulrasoolf1af26d2016-12-12 05:47:4028
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 Abdulrasoolf1af26d2016-12-12 05:47:4033
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)
51endif()
52
Michael J. Spencer773a8fb2011-12-18 08:27:5953set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Pete Cooper69b18f42016-01-07 00:14:0954set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
Michael J. Spencer773a8fb2011-12-18 08:27:5955set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
56
Shankar Easwaranc3550f92014-10-08 03:47:5157# Compute the LLD version from the LLVM version.
58string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
59 ${PACKAGE_VERSION})
60message(STATUS "LLD version: ${LLD_VERSION}")
61
62string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
63 ${LLD_VERSION})
64string(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.
69if ( 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()
92endif ()
93
94# Configure the Version.inc file.
95configure_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. Spencer773a8fb2011-12-18 08:27:59100if (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.")
106endif()
107
Michael J. Spencerd4eb47c2013-04-06 00:56:40108list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
109
Petr Hosekf367a2a2016-12-23 00:22:47110include(AddLLD)
111
Michael J. Spencerd4eb47c2013-04-06 00:56:40112option(LLD_USE_VTUNE
113 "Enable VTune user task tracking."
114 OFF)
115if (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()
122endif()
123
Petr Hosekf367a2a2016-12-23 00:22:47124option(LLD_BUILD_TOOLS
125 "Build the lld tools. If OFF, just generate build targets." ON)
Nick Kledzik1a6615d2012-03-08 00:18:30126
Zachary Turner392b7152014-12-02 17:57:54127if (MSVC)
128 add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
Michael J. Spencerb6396ea2015-02-25 01:30:13129 add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
Zachary Turner392b7152014-12-02 17:57:54130endif()
131
Michael J. Spencer773a8fb2011-12-18 08:27:59132include_directories(BEFORE
133 ${CMAKE_CURRENT_BINARY_DIR}/include
134 ${CMAKE_CURRENT_SOURCE_DIR}/include
135 )
136
Hans Wennborg2391fdd2013-08-24 00:24:15137if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
138 install(DIRECTORY include/
139 DESTINATION include
140 FILES_MATCHING
141 PATTERN "*.h"
142 PATTERN ".svn" EXCLUDE
143 )
144endif()
Michael J. Spencer773a8fb2011-12-18 08:27:59145
Michael J. Spencer773a8fb2011-12-18 08:27:59146add_subdirectory(lib)
Rui Ueyama3178b802016-03-03 01:56:23147add_subdirectory(tools/lld)
Michael J. Spencer773a8fb2011-12-18 08:27:59148
Greg Fitzgeraldcedca2f2015-01-12 21:41:10149if (LLVM_INCLUDE_TESTS)
Chris Bieneman03c48b02015-10-01 18:17:47150 add_subdirectory(test)
Michael J. Spencer800de032012-12-19 00:51:07151 add_subdirectory(unittests)
152endif()
Reid Klecknerf00daf12014-04-18 21:59:05153
154add_subdirectory(docs)
Rui Ueyama411c63602015-05-28 19:09:30155add_subdirectory(COFF)
Michael J. Spencer84487f12015-07-24 21:03:07156add_subdirectory(ELF)