Revert "[ARM][TypePromotion] Enable by default"
[lldb.git] / lld / CMakeLists.txt
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}"
15                           "--obj-root"
16                           "--includedir"
17                           "--cmakedir"
18                           "--src-root"
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)
30   list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH)
31   list(GET LLVM_CONFIG_OUTPUT 3 MAIN_SRC_DIR)
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")
35   set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
36
37   file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR)
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
50   set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
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)
57
58   if(LLVM_INCLUDE_TESTS)
59     include(FindPythonInterp)
60     if(NOT PYTHONINTERP_FOUND)
61       message(FATAL_ERROR
62 "Unable to find Python interpreter, required for testing.
63
64 Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
65     endif()
66
67     if(${PYTHON_VERSION_STRING} VERSION_LESS 2.7)
68       message(FATAL_ERROR "Python 2.7 or newer is required")
69     endif()
70
71     # Check prebuilt llvm/utils.
72     if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
73         AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
74       set(LLVM_UTILS_PROVIDED ON)
75     endif()
76
77     if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
78       # Note: path not really used, except for checking if lit was found
79       set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
80       if(NOT LLVM_UTILS_PROVIDED)
81         add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
82         add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
83         set(LLVM_UTILS_PROVIDED ON)
84         set(LLD_TEST_DEPS FileCheck not)
85       endif()
86       set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
87       if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
88           AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
89           AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
90         add_subdirectory(${UNITTEST_DIR} utils/unittest)
91       endif()
92     else()
93       # Seek installed Lit.
94       find_program(LLVM_LIT
95                    NAMES llvm-lit lit.py lit
96                    PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
97                    DOC "Path to lit.py")
98     endif()
99
100     if(LLVM_LIT)
101       # Define the default arguments to use with 'lit', and an option for the user
102       # to override.
103       set(LIT_ARGS_DEFAULT "-sv")
104       if (MSVC OR XCODE)
105         set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
106       endif()
107       set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
108
109       # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
110       if(WIN32 AND NOT CYGWIN)
111         set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
112       endif()
113     else()
114       set(LLVM_INCLUDE_TESTS OFF)
115     endif()
116   endif()
117 endif()
118
119 set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
120 set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
121 set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
122
123 # Compute the LLD version from the LLVM version.
124 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
125   ${PACKAGE_VERSION})
126 message(STATUS "LLD version: ${LLD_VERSION}")
127
128 string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
129   ${LLD_VERSION})
130 string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
131   ${LLD_VERSION})
132
133 # Determine LLD revision and repository.
134 # TODO: Figure out a way to get the revision and the repository on windows.
135 if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
136   execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR}
137                   OUTPUT_VARIABLE LLD_REVISION)
138
139   execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR}
140                   OUTPUT_VARIABLE LLD_REPOSITORY)
141   if ( LLD_REPOSITORY )
142     # Replace newline characters with spaces
143     string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY})
144     # Remove leading spaces
145     STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" )
146     # Remove trailing spaces
147     string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY})
148   endif()
149
150   if ( LLD_REVISION )
151     # Replace newline characters with spaces
152     string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION})
153     # Remove leading spaces
154     STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" )
155     # Remove trailing spaces
156     string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION})
157   endif()
158 endif ()
159
160 # Configure the Version.inc file.
161 configure_file(
162   ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in
163   ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc)
164
165
166 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
167   message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
168 "the makefiles distributed with LLVM. Please create a directory and run cmake "
169 "from there, passing the path to this source directory as the last argument. "
170 "This process created the file `CMakeCache.txt' and the directory "
171 "`CMakeFiles'. Please delete them.")
172 endif()
173
174 list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
175
176 include(AddLLD)
177
178 option(LLD_USE_VTUNE
179        "Enable VTune user task tracking."
180        OFF)
181 if (LLD_USE_VTUNE)
182   find_package(VTune)
183   if (VTUNE_FOUND)
184     include_directories(${VTune_INCLUDE_DIRS})
185     list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
186     add_definitions(-DLLD_HAS_VTUNE)
187   endif()
188 endif()
189
190 option(LLD_BUILD_TOOLS
191   "Build the lld tools. If OFF, just generate build targets." ON)
192
193 if (MSVC)
194   add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
195   add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
196 endif()
197
198 include_directories(BEFORE
199   ${CMAKE_CURRENT_BINARY_DIR}/include
200   ${CMAKE_CURRENT_SOURCE_DIR}/include
201   )
202
203 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
204   install(DIRECTORY include/
205     DESTINATION include
206     FILES_MATCHING
207     PATTERN "*.h"
208     PATTERN ".svn" EXCLUDE
209     )
210 endif()
211
212 add_subdirectory(Common)
213 add_subdirectory(lib)
214 add_subdirectory(tools/lld)
215
216 if (LLVM_INCLUDE_TESTS)
217   add_subdirectory(test)
218   add_subdirectory(unittests)
219 endif()
220
221 add_subdirectory(docs)
222 add_subdirectory(COFF)
223 add_subdirectory(ELF)
224 add_subdirectory(MinGW)
225 add_subdirectory(wasm)