Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6.
Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.
d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 reverted the reviews
D144509 [CMake] Bumps minimum version to 3.20.0.
This partly undoes D137724.
This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193
Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.
D150532 [OpenMP] Compile assembly files as ASM, not C
Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.
Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.
Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.
D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump
The build uses other mechanism to select the runtime.
Fixes #62719
Reviewed By: #libc, Mordante
Differential Revision: https://reviews.llvm.org/D151344
2023-05-24 18:12:32 +02:00
|
|
|
cmake_minimum_required(VERSION 3.20.0)
|
2024-06-04 01:31:36 +02:00
|
|
|
set(LLVM_SUBPROJECT_TITLE "LLD")
|
2022-01-02 06:29:26 +00:00
|
|
|
|
2022-10-24 06:31:37 +02:00
|
|
|
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
|
|
|
|
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
|
|
|
|
endif()
|
|
|
|
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
|
|
|
|
NO_POLICY_SCOPE)
|
|
|
|
|
2022-01-02 06:29:26 +00:00
|
|
|
# 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 05:47:40 +00:00
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
project(lld)
|
2022-01-19 06:45:07 +00:00
|
|
|
set(LLD_BUILT_STANDALONE TRUE)
|
|
|
|
endif()
|
2016-12-12 05:47:40 +00:00
|
|
|
|
2022-01-19 06:45:07 +00:00
|
|
|
# Must go below project(..)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
if(LLD_BUILT_STANDALONE)
|
2022-08-05 21:45:55 +02:00
|
|
|
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
|
2022-02-22 18:14:47 -05:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS NO)
|
|
|
|
|
2016-12-12 05:47:40 +00:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
|
2022-01-02 06:29:26 +00:00
|
|
|
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
|
2022-02-02 15:37:13 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
|
2016-12-12 05:47:40 +00:00
|
|
|
|
2023-01-10 10:20:39 -05:00
|
|
|
# Turn into CACHE PATHs for overwriting
|
2022-08-06 09:22:19 -04:00
|
|
|
set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
|
|
|
|
set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
|
|
|
|
set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
|
2016-12-12 05:47:40 +00:00
|
|
|
|
2022-01-02 06:29:26 +00:00
|
|
|
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
|
|
|
NO_DEFAULT_PATH)
|
2016-12-12 05:47:40 +00:00
|
|
|
|
2022-01-02 06:29:26 +00:00
|
|
|
# They are used as destination of target generators.
|
2016-12-12 05:47:40 +00:00
|
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
|
2022-08-18 22:44:46 -04:00
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
2016-12-12 05:47:40 +00:00
|
|
|
|
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
|
|
|
include(HandleLLVMOptions)
|
2021-03-15 20:56:08 +01:00
|
|
|
include(GetErrcMessages)
|
2020-08-17 15:31:32 -07:00
|
|
|
include(CheckAtomic)
|
2017-01-31 14:10:20 +00:00
|
|
|
|
2022-01-02 06:29:26 +00:00
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
|
|
|
2022-07-26 07:17:30 +00:00
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
2022-01-02 06:29:26 +00:00
|
|
|
link_directories(${LLVM_LIBRARY_DIRS})
|
|
|
|
|
2017-01-31 14:10:20 +00:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2021-03-15 09:33:31 -07:00
|
|
|
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
|
|
|
|
COMPONENTS Interpreter)
|
2017-01-31 14:10:20 +00: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
|
2023-07-06 14:05:02 +02:00
|
|
|
set(LLVM_EXTERNAL_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
2017-01-31 14:10:20 +00:00
|
|
|
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()
|
2023-03-13 18:22:31 +01:00
|
|
|
|
|
|
|
if (NOT TARGET llvm_gtest)
|
|
|
|
message(FATAL_ERROR "llvm-gtest not found. Please install llvm-gtest or disable tests with -DLLVM_INCLUDE_TESTS=OFF")
|
2017-01-31 14:10:20 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Seek installed Lit.
|
2023-07-06 14:05:02 +02:00
|
|
|
find_program(LLVM_EXTERNAL_LIT
|
2017-01-31 14:10:20 +00:00
|
|
|
NAMES llvm-lit lit.py lit
|
|
|
|
PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
|
|
|
|
DOC "Path to lit.py")
|
|
|
|
endif()
|
|
|
|
|
2023-07-06 14:05:02 +02:00
|
|
|
if(LLVM_EXTERNAL_LIT)
|
2017-01-31 14:10:20 +00:00
|
|
|
# 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-15 20:56:08 +01:00
|
|
|
get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
|
|
|
|
|
2017-01-31 14:10:20 +00: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()
|
2022-01-02 06:29:26 +00:00
|
|
|
endif() # standalone
|
2016-12-12 05:47:40 +00:00
|
|
|
|
[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS
builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as
`CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when
downstream projects try to install there too this breaks because our
builds always install to fresh directories for isolation's sake.
Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the
other specially crafted `LLVM_CONFIG_*` variables substituted in
`llvm/cmake/modules/LLVMConfig.cmake.in`.
@beanz added it in d0e1c2a550ef348aae036d0fe78cab6f038c420c to fix a
dangling reference in `AddLLVM`, but I am suspicious of how this
variable doesn't follow the pattern.
Those other ones are carefully made to be build-time vs install-time
variables depending on which `LLVMConfig.cmake` is being generated, are
carefully made relative as appropriate, etc. etc. For my NixOS use-case
they are also fine because they are never used as downstream install
variables, only for reading not writing.
To avoid the problems I face, and restore symmetry, I deleted the
exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s.
`AddLLVM` now instead expects each project to define its own, and they
do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports
`LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in
the usual way, matching the other remaining exported variables.
For the `AddLLVM` changes, I tried to copy the existing pattern of
internal vs non-internal or for LLVM vs for downstream function/macro
names, but it would good to confirm I did that correctly.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D117977
2022-06-11 06:11:59 +00:00
|
|
|
set(LLD_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
|
|
|
|
"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
|
|
|
|
mark_as_advanced(LLD_TOOLS_INSTALL_DIR)
|
|
|
|
|
2011-12-18 08:27:59 +00:00
|
|
|
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2016-01-07 00:14:09 +00:00
|
|
|
set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
|
2011-12-18 08:27:59 +00:00
|
|
|
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2020-05-11 18:33:55 -04: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 03:47:51 +00: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 10:12:06 -05: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 08:27:59 +00: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()
|
|
|
|
|
2021-12-30 06:22:48 +00:00
|
|
|
# Add path for custom modules.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${LLD_SOURCE_DIR}/cmake/modules"
|
2022-01-01 17:51:16 +00:00
|
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
2021-12-30 06:22:48 +00:00
|
|
|
)
|
2013-04-06 00:56:40 +00:00
|
|
|
|
2016-12-23 00:22:47 +00:00
|
|
|
include(AddLLD)
|
|
|
|
|
2013-04-06 00:56:40 +00: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 00:22:47 +00:00
|
|
|
option(LLD_BUILD_TOOLS
|
|
|
|
"Build the lld tools. If OFF, just generate build targets." ON)
|
2012-03-08 00:18:30 +00:00
|
|
|
|
2020-09-15 08:39:15 +03: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-02 17:57:54 +00:00
|
|
|
if (MSVC)
|
|
|
|
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
|
2015-02-25 01:30:13 +00:00
|
|
|
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
|
2014-12-02 17:57:54 +00:00
|
|
|
endif()
|
|
|
|
|
2011-12-18 08:27:59 +00:00
|
|
|
include_directories(BEFORE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
2017-10-02 21:00:41 +00:00
|
|
|
add_subdirectory(Common)
|
2016-03-03 01:56:23 +00:00
|
|
|
add_subdirectory(tools/lld)
|
2011-12-18 08:27:59 +00:00
|
|
|
|
2015-01-12 21:41:10 +00:00
|
|
|
if (LLVM_INCLUDE_TESTS)
|
2023-06-19 07:32:34 -04:00
|
|
|
add_custom_target(LLDUnitTests)
|
2024-06-04 01:31:36 +02:00
|
|
|
set_target_properties(LLDUnitTests PROPERTIES FOLDER "LLD/Tests")
|
2024-03-02 20:08:44 +01:00
|
|
|
if (TARGET llvm_gtest)
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
endif()
|
2015-10-01 18:17:47 +00:00
|
|
|
add_subdirectory(test)
|
2012-12-19 00:51:07 +00:00
|
|
|
endif()
|
2014-04-18 21:59:05 +00:00
|
|
|
|
|
|
|
add_subdirectory(docs)
|
2015-05-28 19:09:30 +00:00
|
|
|
add_subdirectory(COFF)
|
2015-07-24 21:03:07 +00:00
|
|
|
add_subdirectory(ELF)
|
2020-04-02 11:54:05 -07:00
|
|
|
add_subdirectory(MachO)
|
2017-09-11 17:02:59 +00:00
|
|
|
add_subdirectory(MinGW)
|
2017-11-17 18:14:09 +00:00
|
|
|
add_subdirectory(wasm)
|
2020-05-02 18:32:40 -04:00
|
|
|
|
2025-02-16 14:18:09 -06:00
|
|
|
add_custom_target(lld-headers)
|
|
|
|
set_target_properties(lld-headers PROPERTIES FOLDER "Misc")
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
install(DIRECTORY include/lld
|
|
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
|
|
COMPONENT lld-headers
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
2025-02-21 11:06:33 -06:00
|
|
|
PATTERN "*.inc"
|
2025-02-16 14:18:09 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT LLVM_ENABLE_IDE)
|
|
|
|
add_llvm_install_targets(install-lld-headers
|
|
|
|
DEPENDS lld-headers
|
|
|
|
COMPONENT lld-headers)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Custom target to install all lld libraries
|
|
|
|
add_custom_target(lld-libraries)
|
|
|
|
if (NOT LLVM_ENABLE_IDE)
|
|
|
|
add_llvm_install_targets(install-lld-libraries
|
|
|
|
DEPENDS lld-libraries
|
|
|
|
COMPONENT lld-libraries)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_property(LLD_LIBS GLOBAL PROPERTY LLD_ALL_LIBS)
|
|
|
|
if(LLD_LIBS)
|
|
|
|
list(REMOVE_DUPLICATES LLD_LIBS)
|
|
|
|
foreach(lib ${LLD_LIBS})
|
|
|
|
add_dependencies(lld-libraries ${lib})
|
|
|
|
if(NOT LLVM_ENABLE_IDE)
|
|
|
|
add_dependencies(install-lld-libraries install-${lib})
|
|
|
|
add_dependencies(install-lld-libraries-stripped install-${lib}-stripped)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
2020-05-02 18:32:40 -04:00
|
|
|
add_subdirectory(cmake/modules)
|