2022-01-02 14:29:26 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13.4)
|
|
|
|
|
|
|
|
# If we are not building as a part of LLVM, build LLD as an
|
|
|
|
# standalone project, using LLVM as an external library:
|
2016-12-12 13:47:40 +08:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
project(lld)
|
2022-01-19 14:45:07 +08:00
|
|
|
set(LLD_BUILT_STANDALONE TRUE)
|
|
|
|
endif()
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-19 14:45:07 +08:00
|
|
|
# Must go below project(..)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
if(LLD_BUILT_STANDALONE)
|
2016-12-12 13:47:40 +08:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
# Rely on llvm-config.
|
|
|
|
set(LLVM_CONFIG_OUTPUT)
|
|
|
|
if(LLVM_CONFIG)
|
|
|
|
set (LLVM_CONFIG_FOUND 1)
|
|
|
|
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
|
|
|
message(DEPRECATION "Using llvm-config to detect the LLVM installation is \
|
|
|
|
deprecated. The installed cmake files should be used \
|
|
|
|
instead. CMake should be able to detect your LLVM install \
|
|
|
|
automatically, but you can also use LLVM_DIR to specify \
|
|
|
|
the path containing LLVMConfig.cmake.")
|
|
|
|
set(CONFIG_COMMAND ${LLVM_CONFIG}
|
|
|
|
"--includedir"
|
|
|
|
"--prefix"
|
|
|
|
"--src-root"
|
|
|
|
"--cmakedir"
|
|
|
|
)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CONFIG_COMMAND}
|
|
|
|
RESULT_VARIABLE HAD_ERROR
|
|
|
|
OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT
|
|
|
|
)
|
|
|
|
if(NOT HAD_ERROR)
|
|
|
|
string(REGEX REPLACE
|
|
|
|
"[ \t]*[\r\n]+[ \t]*" ";"
|
|
|
|
LLVM_CONFIG_OUTPUT ${LLVM_CONFIG_OUTPUT})
|
|
|
|
else()
|
|
|
|
string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
|
|
|
|
message(STATUS "${CONFIG_COMMAND_STR}")
|
|
|
|
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
|
|
|
endif()
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
list(GET LLVM_CONFIG_OUTPUT 0 MAIN_INCLUDE_DIR)
|
|
|
|
list(GET LLVM_CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
|
|
|
|
list(GET LLVM_CONFIG_OUTPUT 2 MAIN_SRC_DIR)
|
|
|
|
list(GET LLVM_CONFIG_OUTPUT 3 LLVM_CONFIG_CMAKE_DIR)
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
# Normalize LLVM_CMAKE_DIR. --cmakedir might contain backslashes.
|
|
|
|
# CMake assumes slashes as PATH.
|
|
|
|
file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_DIR} LLVM_CMAKE_DIR)
|
|
|
|
endif()
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
# We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
|
|
|
|
# LLVM_CONFIG.
|
|
|
|
if (NOT LLVM_CONFIG_FOUND)
|
|
|
|
# Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
|
|
|
|
# path is removed.
|
|
|
|
set(MAIN_INCLUDE_DIR ${LLVM_INCLUDE_DIR})
|
|
|
|
set(LLVM_OBJ_DIR ${LLVM_BINARY_DIR})
|
2016-12-12 13:47:40 +08:00
|
|
|
endif()
|
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
|
|
|
set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
|
|
|
|
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
|
|
|
NO_DEFAULT_PATH)
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
# They are used as destination of target generators.
|
2016-12-12 13:47:40 +08:00
|
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
|
2022-01-02 14:29:26 +08:00
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
2016-12-12 13:47:40 +08:00
|
|
|
|
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
|
|
|
include(HandleLLVMOptions)
|
2021-03-16 03:56:08 +08:00
|
|
|
include(GetErrcMessages)
|
2020-08-18 06:31:32 +08:00
|
|
|
include(CheckAtomic)
|
2017-01-31 22:10:20 +08:00
|
|
|
|
2022-01-02 14:29:26 +08:00
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
|
|
|
|
|
|
include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS})
|
|
|
|
link_directories(${LLVM_LIBRARY_DIRS})
|
|
|
|
|
2017-01-31 22:10:20 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2021-03-16 00:33:31 +08:00
|
|
|
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
|
|
|
|
COMPONENTS Interpreter)
|
2017-01-31 22:10:20 +08:00
|
|
|
|
|
|
|
# Check prebuilt llvm/utils.
|
|
|
|
if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
|
|
|
|
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
|
|
|
|
set(LLVM_UTILS_PROVIDED ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
|
|
# Note: path not really used, except for checking if lit was found
|
|
|
|
set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
|
|
if(NOT LLVM_UTILS_PROVIDED)
|
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
|
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
|
|
|
|
set(LLVM_UTILS_PROVIDED ON)
|
|
|
|
set(LLD_TEST_DEPS FileCheck not)
|
|
|
|
endif()
|
|
|
|
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
|
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
|
|
|
AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
|
|
|
AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
|
|
|
add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Seek installed Lit.
|
|
|
|
find_program(LLVM_LIT
|
|
|
|
NAMES llvm-lit lit.py lit
|
|
|
|
PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
|
|
|
|
DOC "Path to lit.py")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(LLVM_LIT)
|
|
|
|
# Define the default arguments to use with 'lit', and an option for the user
|
|
|
|
# to override.
|
|
|
|
set(LIT_ARGS_DEFAULT "-sv")
|
|
|
|
if (MSVC OR XCODE)
|
|
|
|
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
|
|
endif()
|
|
|
|
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
|
|
|
2021-03-16 03:56:08 +08:00
|
|
|
get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
|
|
|
|
|
2017-01-31 22:10:20 +08:00
|
|
|
# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
|
|
|
|
if(WIN32 AND NOT CYGWIN)
|
|
|
|
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(LLVM_INCLUDE_TESTS OFF)
|
|
|
|
endif()
|
|
|
|
endif()
|
2021-05-19 23:07:39 +08:00
|
|
|
|
|
|
|
if(LLVM_HAVE_LIBXAR)
|
|
|
|
set(XAR_LIB xar)
|
|
|
|
endif()
|
2022-01-02 14:29:26 +08:00
|
|
|
endif() # standalone
|
2016-12-12 13:47:40 +08:00
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2016-01-07 08:14:09 +08:00
|
|
|
set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
|
2011-12-18 16:27:59 +08:00
|
|
|
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2020-05-12 06:33:55 +08:00
|
|
|
set(LLD_VENDOR ${PACKAGE_VENDOR} CACHE STRING
|
|
|
|
"Vendor-specific text for showing with version information.")
|
|
|
|
|
|
|
|
if(LLD_VENDOR)
|
|
|
|
add_definitions(-DLLD_VENDOR="${LLD_VENDOR}")
|
|
|
|
endif()
|
|
|
|
|
2014-10-08 11:47:51 +08:00
|
|
|
# Compute the LLD version from the LLVM version.
|
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
|
|
|
|
${PACKAGE_VERSION})
|
|
|
|
message(STATUS "LLD version: ${LLD_VERSION}")
|
|
|
|
|
|
|
|
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
|
|
|
|
${LLD_VERSION})
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
|
|
|
|
${LLD_VERSION})
|
|
|
|
|
2020-01-16 23:12:06 +08:00
|
|
|
# Configure the Version.inc file.
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc)
|
|
|
|
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
|
|
|
|
"the makefiles distributed with LLVM. Please create a directory and run cmake "
|
|
|
|
"from there, passing the path to this source directory as the last argument. "
|
|
|
|
"This process created the file `CMakeCache.txt' and the directory "
|
|
|
|
"`CMakeFiles'. Please delete them.")
|
|
|
|
endif()
|
|
|
|
|
2022-01-02 01:51:16 +08:00
|
|
|
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
|
|
|
|
set(LLVM_COMMON_CMAKE_UTILS ${LLD_SOURCE_DIR}/../cmake)
|
|
|
|
endif()
|
|
|
|
|
2021-12-30 14:22:48 +08:00
|
|
|
# Add path for custom modules.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${LLD_SOURCE_DIR}/cmake/modules"
|
2022-01-02 01:51:16 +08:00
|
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
2021-12-30 14:22:48 +08:00
|
|
|
)
|
2013-04-06 08:56:40 +08:00
|
|
|
|
2016-12-23 08:22:47 +08:00
|
|
|
include(AddLLD)
|
|
|
|
|
2013-04-06 08:56:40 +08:00
|
|
|
option(LLD_USE_VTUNE
|
|
|
|
"Enable VTune user task tracking."
|
|
|
|
OFF)
|
|
|
|
if (LLD_USE_VTUNE)
|
|
|
|
find_package(VTune)
|
|
|
|
if (VTUNE_FOUND)
|
|
|
|
include_directories(${VTune_INCLUDE_DIRS})
|
|
|
|
list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
|
|
|
|
add_definitions(-DLLD_HAS_VTUNE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-12-23 08:22:47 +08:00
|
|
|
option(LLD_BUILD_TOOLS
|
|
|
|
"Build the lld tools. If OFF, just generate build targets." ON)
|
2012-03-08 08:18:30 +08:00
|
|
|
|
2020-09-15 13:39:15 +08:00
|
|
|
option(LLD_DEFAULT_LD_LLD_IS_MINGW
|
|
|
|
"Use MinGW as the default backend for ld.lld. If OFF, ELF will be used." OFF)
|
|
|
|
if (LLD_DEFAULT_LD_LLD_IS_MINGW)
|
|
|
|
add_definitions("-DLLD_DEFAULT_LD_LLD_IS_MINGW=1")
|
|
|
|
endif()
|
|
|
|
|
2014-12-03 01:57:54 +08:00
|
|
|
if (MSVC)
|
|
|
|
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
|
2015-02-25 09:30:13 +08:00
|
|
|
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
|
2014-12-03 01:57:54 +08:00
|
|
|
endif()
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
include_directories(BEFORE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
2013-08-24 08:24:15 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
install(DIRECTORY include/
|
2021-12-30 14:22:48 +08:00
|
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
2013-08-24 08:24:15 +08:00
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
)
|
|
|
|
endif()
|
2011-12-18 16:27:59 +08:00
|
|
|
|
2017-10-03 05:00:41 +08:00
|
|
|
add_subdirectory(Common)
|
2016-03-03 09:56:23 +08:00
|
|
|
add_subdirectory(tools/lld)
|
2011-12-18 16:27:59 +08:00
|
|
|
|
2015-01-13 05:41:10 +08:00
|
|
|
if (LLVM_INCLUDE_TESTS)
|
2015-10-02 02:17:47 +08:00
|
|
|
add_subdirectory(test)
|
2012-12-19 08:51:07 +08:00
|
|
|
endif()
|
2014-04-19 05:59:05 +08:00
|
|
|
|
|
|
|
add_subdirectory(docs)
|
2015-05-29 03:09:30 +08:00
|
|
|
add_subdirectory(COFF)
|
2015-07-25 05:03:07 +08:00
|
|
|
add_subdirectory(ELF)
|
2020-04-03 02:54:05 +08:00
|
|
|
add_subdirectory(MachO)
|
2017-09-12 01:02:59 +08:00
|
|
|
add_subdirectory(MinGW)
|
2017-11-18 02:14:09 +08:00
|
|
|
add_subdirectory(wasm)
|
2020-05-03 06:32:40 +08:00
|
|
|
|
|
|
|
add_subdirectory(cmake/modules)
|