Linker configuration: enhance usability
The linker configuration file is now optional: It is loaded only if variable CMAKE_<LANG>_USE_LINKER_CONFIGURATION is set to TRUE. The file CMakeAddNewLanguage.txt is updated to take into account the linker configuration. Fixes: #26393
This commit is contained in:
parent
5b2351fb39
commit
0619c064ff
@ -96,5 +96,6 @@ if(NOT CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG)
|
||||
set(CMAKE_EXECUTABLE_RPATH_LINK_ASM${ASM_DIALECT}_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_ASM${ASM_DIALECT}_FLAG})
|
||||
endif()
|
||||
|
||||
set(CMAKE_ASM${ASM_DIALECT}_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_ASM${ASM_DIALECT}_INFOMATION_LOADED 1)
|
||||
|
@ -20,12 +20,20 @@ CMake(LANG)Compiler.cmake.in -> used by CMakeDetermine(LANG)Compiler.cmake
|
||||
This file is used to store compiler information and is copied down into try
|
||||
compile directories so that try compiles do not need to re-determine and test the LANG
|
||||
|
||||
CMakeTest(LANG)Compiler.cmake -> test the compiler and set:
|
||||
SET(CMAKE_(LANG)_COMPILER_WORKS 1 CACHE INTERNAL "")
|
||||
|
||||
CMake(LANG)Information.cmake -> set up rule variables for LANG :
|
||||
CMake(LANG)Information.cmake => set compiler configuration:
|
||||
CMAKE_(LANG)_CREATE_SHARED_LIBRARY
|
||||
CMAKE_(LANG)_CREATE_SHARED_MODULE
|
||||
CMAKE_(LANG)_CREATE_STATIC_LIBRARY
|
||||
CMAKE_(LANG)_COMPILE_OBJECT
|
||||
CMAKE_(LANG)_LINK_EXECUTABLE
|
||||
|
||||
CMAKE_(LANG)_USE_LINKER_INFORMATION
|
||||
|
||||
CMakeTest(LANG)Compiler.cmake -> test the compiler and set:
|
||||
SET(CMAKE_(LANG)_COMPILER_WORKS 1 CACHE INTERNAL "")
|
||||
|
||||
|
||||
If the variable CMAKE_(LANG)_USE_LINKER_INFORMATION has value TRUE, the file CMake(LANG)LinkerInformation.cmake
|
||||
should be defined.
|
||||
|
||||
CMake(LANG)LinkerInformation.cmake -> set up linker configuration for LANG.
|
||||
|
@ -175,4 +175,6 @@ if(NOT CMAKE_C_LINK_EXECUTABLE)
|
||||
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_C_INFORMATION_LOADED 1)
|
||||
|
@ -64,4 +64,7 @@ set(CMAKE_CSharp_CREATE_SHARED_MODULE "CSharp_NO_CREATE_SHARED_MODULE")
|
||||
set(CMAKE_CSharp_LINK_EXECUTABLE "CSharp_NO_LINK_EXECUTABLE")
|
||||
|
||||
set(CMAKE_CSharp_USE_RESPONSE_FILE_FOR_OBJECTS 1)
|
||||
|
||||
set(CMAKE_CSharp_USE_LINKER_INFORMATION FALSE)
|
||||
|
||||
set(CMAKE_CSharp_INFORMATION_LOADED 1)
|
||||
|
@ -150,4 +150,6 @@ endif()
|
||||
|
||||
unset(__IMPLICIT_DLINK_FLAGS)
|
||||
|
||||
set(CMAKE_CUDA_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_CUDA_INFORMATION_LOADED 1)
|
||||
|
@ -183,4 +183,6 @@ mark_as_advanced(
|
||||
CMAKE_VERBOSE_MAKEFILE
|
||||
)
|
||||
|
||||
set(CMAKE_CXX_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_CXX_INFORMATION_LOADED 1)
|
||||
|
@ -129,5 +129,7 @@ if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
|
||||
mark_as_advanced(CMAKE_Fortran_STANDARD_LIBRARIES)
|
||||
endif()
|
||||
|
||||
set(CMAKE_Fortran_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
# set this variable so we can avoid loading this more than once.
|
||||
set(CMAKE_Fortran_INFORMATION_LOADED 1)
|
||||
|
@ -98,6 +98,8 @@ if(NOT CMAKE_HIP_LINK_EXECUTABLE)
|
||||
"<CMAKE_HIP_COMPILER> <FLAGS> <CMAKE_HIP_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||
endif()
|
||||
|
||||
set(CMAKE_HIP_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_HIP_INFORMATION_LOADED 1)
|
||||
|
||||
# Load the file and find the relevant HIP runtime.
|
||||
|
@ -62,4 +62,6 @@ if(NOT CMAKE_ISPC_COMPILE_OBJECT)
|
||||
"<CMAKE_ISPC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> --emit-obj <SOURCE> -h <ISPC_HEADER>")
|
||||
endif()
|
||||
|
||||
set(CMAKE_ISPC_USE_LINKER_INFORMATION FALSE)
|
||||
|
||||
set(CMAKE_ISPC_INFORMATION_LOADED 1)
|
||||
|
@ -47,3 +47,5 @@ if(WIN32 AND NOT CYGWIN)
|
||||
else()
|
||||
set(CMAKE_INCLUDE_FLAG_SEP_Java ":")
|
||||
endif()
|
||||
|
||||
set(CMAKE_Java_USE_LINKER_INFORMATION FALSE)
|
||||
|
@ -187,4 +187,6 @@ if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG)
|
||||
set(CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
|
||||
endif()
|
||||
|
||||
set(CMAKE_OBJC_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_OBJC_INFORMATION_LOADED 1)
|
||||
|
@ -179,4 +179,6 @@ mark_as_advanced(
|
||||
CMAKE_VERBOSE_MAKEFILE
|
||||
)
|
||||
|
||||
set(CMAKE_OBJCXX_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_OBJCXX_INFORMATION_LOADED 1)
|
||||
|
@ -46,5 +46,7 @@ if(NOT CMAKE_RC_COMPILE_OBJECT)
|
||||
"<CMAKE_RC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> /fo <OBJECT> <SOURCE>")
|
||||
endif()
|
||||
|
||||
set(CMAKE_RC_USE_LINKER_INFORMATION FALSE)
|
||||
|
||||
# set this variable so we can avoid loading this more than once.
|
||||
set(CMAKE_RC_INFORMATION_LOADED 1)
|
||||
|
@ -172,4 +172,6 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_Swift_USE_LINKER_INFORMATION TRUE)
|
||||
|
||||
set(CMAKE_Swift_INFORMATION_LOADED 1)
|
||||
|
@ -1,8 +0,0 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
|
||||
# This file sets the basic flags for the linker used by the CSharp compiler in CMake.
|
||||
# For now, nothing to define
|
||||
|
||||
set(CMAKE_CSharp_LINKER_INFORMATION_LOADED 1)
|
@ -1,8 +0,0 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
|
||||
# This file sets the basic flags for the linker used by the ISPC compiler in CMake.
|
||||
# For now, ISPC is not able to handle the link step
|
||||
|
||||
set(CMAKE_ISPC_LINKER_INFORMATION_LOADED 1)
|
@ -1,5 +0,0 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
|
||||
# Java language does not have a concept of linker, so nothing to configure.
|
@ -1,17 +0,0 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
|
||||
# This file sets the basic flags for the linker used by the C compiler in CMake.
|
||||
# It also loads the available platform file for the system-linker
|
||||
# if it exists.
|
||||
# It also loads a system - linker - processor (or target hardware)
|
||||
# specific file, which is mainly useful for crosscompiling and embedded systems.
|
||||
|
||||
include(Internal/CMakeCommonLinkerInformation)
|
||||
|
||||
set(_INCLUDED_FILE 0)
|
||||
|
||||
# Foe now, no linker associated with RC language
|
||||
|
||||
set(CMAKE_RC_LINKER_INFORMATION_LOADED 1)
|
@ -963,18 +963,24 @@ void cmGlobalGenerator::EnableLanguage(
|
||||
} // end if in try compile
|
||||
} // end need test language
|
||||
|
||||
// load linker configuration
|
||||
std::string langLinkerLoadedVar =
|
||||
cmStrCat("CMAKE_", lang, "_LINKER_INFORMATION_LOADED");
|
||||
if (!mf->GetDefinition(langLinkerLoadedVar)) {
|
||||
fpath = cmStrCat("Internal/CMake", lang, "LinkerInformation.cmake");
|
||||
std::string informationFile = mf->GetModulesFile(fpath);
|
||||
if (informationFile.empty()) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("Could not find cmake module file: ", fpath));
|
||||
} else if (!mf->ReadListFile(informationFile)) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("Could not process cmake module file: ", informationFile));
|
||||
// load linker configuration, if required
|
||||
if (mf->GetDefinition(cmStrCat("CMAKE_", lang, "_USE_LINKER_INFORMATION"))
|
||||
.IsOn()) {
|
||||
std::string langLinkerLoadedVar =
|
||||
cmStrCat("CMAKE_", lang, "_LINKER_INFORMATION_LOADED");
|
||||
if (!mf->GetDefinition(langLinkerLoadedVar)) {
|
||||
fpath = cmStrCat("CMake", lang, "LinkerInformation.cmake");
|
||||
std::string informationFile = mf->GetModulesFile(fpath);
|
||||
if (informationFile.empty()) {
|
||||
informationFile = mf->GetModulesFile(cmStrCat("Internal/", fpath));
|
||||
}
|
||||
if (informationFile.empty()) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("Could not find cmake module file: ", fpath));
|
||||
} else if (!mf->ReadListFile(informationFile)) {
|
||||
cmSystemTools::Error(cmStrCat(
|
||||
"Could not process cmake module file: ", informationFile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user