[libc] Fix WrapperGen seeing no arguments as a void argument.
[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.13.4)
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   include(CheckAtomic)
58
59   if(LLVM_INCLUDE_TESTS)
60     find_package(Python3 COMPONENTS Interpreter)
61     if(NOT Python3_Interpreter_FOUND)
62       message(WARNING "Python3 not found, using python2 as a fallback")
63       find_package(Python2 COMPONENTS Interpreter REQUIRED)
64       if(Python2_VERSION VERSION_LESS 2.7)
65         message(SEND_ERROR "Python 2.7 or newer is required")
66       endif()
67
68       # Treat python2 as python3
69       add_executable(Python3::Interpreter IMPORTED)
70       set_target_properties(Python3::Interpreter PROPERTIES
71         IMPORTED_LOCATION ${Python2_EXECUTABLE})
72       set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
73     endif()
74
75     # Check prebuilt llvm/utils.
76     if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
77         AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
78       set(LLVM_UTILS_PROVIDED ON)
79     endif()
80
81     if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
82       # Note: path not really used, except for checking if lit was found
83       set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
84       if(NOT LLVM_UTILS_PROVIDED)
85         add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
86         add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
87         set(LLVM_UTILS_PROVIDED ON)
88         set(LLD_TEST_DEPS FileCheck not)
89       endif()
90       set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
91       if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
92           AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
93           AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
94         add_subdirectory(${UNITTEST_DIR} utils/unittest)
95       endif()
96     else()
97       # Seek installed Lit.
98       find_program(LLVM_LIT
99                    NAMES llvm-lit lit.py lit
100                    PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
101                    DOC "Path to lit.py")
102     endif()
103
104     if(LLVM_LIT)
105       # Define the default arguments to use with 'lit', and an option for the user
106       # to override.
107       set(LIT_ARGS_DEFAULT "-sv")
108       if (MSVC OR XCODE)
109         set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
110       endif()
111       set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
112
113       # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
114       if(WIN32 AND NOT CYGWIN)
115         set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
116       endif()
117     else()
118       set(LLVM_INCLUDE_TESTS OFF)
119     endif()
120   endif()
121 endif()
122
123 set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
124 set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
125 set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
126
127 set(LLD_VENDOR ${PACKAGE_VENDOR} CACHE STRING
128   "Vendor-specific text for showing with version information.")
129
130 if(LLD_VENDOR)
131   add_definitions(-DLLD_VENDOR="${LLD_VENDOR}")
132 endif()
133
134 # Compute the LLD version from the LLVM version.
135 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
136   ${PACKAGE_VERSION})
137 message(STATUS "LLD version: ${LLD_VERSION}")
138
139 string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
140   ${LLD_VERSION})
141 string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
142   ${LLD_VERSION})
143
144 # Configure the Version.inc file.
145 configure_file(
146   ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in
147   ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc)
148
149
150 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
151   message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
152 "the makefiles distributed with LLVM. Please create a directory and run cmake "
153 "from there, passing the path to this source directory as the last argument. "
154 "This process created the file `CMakeCache.txt' and the directory "
155 "`CMakeFiles'. Please delete them.")
156 endif()
157
158 list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
159
160 include(AddLLD)
161
162 option(LLD_USE_VTUNE
163        "Enable VTune user task tracking."
164        OFF)
165 if (LLD_USE_VTUNE)
166   find_package(VTune)
167   if (VTUNE_FOUND)
168     include_directories(${VTune_INCLUDE_DIRS})
169     list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
170     add_definitions(-DLLD_HAS_VTUNE)
171   endif()
172 endif()
173
174 option(LLD_BUILD_TOOLS
175   "Build the lld tools. If OFF, just generate build targets." ON)
176
177 option(LLD_DEFAULT_LD_LLD_IS_MINGW
178     "Use MinGW as the default backend for ld.lld. If OFF, ELF will be used." OFF)
179 if (LLD_DEFAULT_LD_LLD_IS_MINGW)
180   add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
181 endif()
182
183 if (MSVC)
184   add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
185   add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
186 endif()
187
188 include_directories(BEFORE
189   ${CMAKE_CURRENT_BINARY_DIR}/include
190   ${CMAKE_CURRENT_SOURCE_DIR}/include
191   )
192
193 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
194   install(DIRECTORY include/
195     DESTINATION include
196     FILES_MATCHING
197     PATTERN "*.h"
198     )
199 endif()
200
201 add_subdirectory(Common)
202 add_subdirectory(lib)
203 add_subdirectory(tools/lld)
204
205 if (LLVM_INCLUDE_TESTS)
206   add_subdirectory(test)
207   add_subdirectory(unittests)
208 endif()
209
210 add_subdirectory(docs)
211 add_subdirectory(COFF)
212 add_subdirectory(ELF)
213 add_subdirectory(MachO)
214 add_subdirectory(MinGW)
215 add_subdirectory(wasm)
216
217 add_subdirectory(cmake/modules)