FEATURE: a new approach for linker configuration
With the recent evolutions ( !8861 (merged) and !8885 (merged)) regarding linker selection and identification, it seems judicious to make independent the linker configuration from the compiler one.
For a large part, various linkers, on a given platform, offers a good compatibility with each other, but this compatibility is not complete. For example, on Apple, to treat all warnings as errors (see #25343), the Apple linker has option -fatal_warnings
but the linkers LLVM LLD
or MOLD
have option --fatal-warnings
. So, today, there is no infrastructure to handle these differences.
For that purpose, I propose to introduce a set of files, dedicated to linker configuration, in a layout similar to the one used currently for the compiler configuration:
# directory for linker configuration independant from the platform
Modules/Linker
## GNU linker configuration
Modules/Linker/GNU.cmake
## GNU Linker used by C compiler
Modules/Linker/GNU-C.cmake
# directory for linker configuration dependant from the platform
Modules/Platform/Linker
## Linux GNU linker configuration
Modules/Platform/Linker/Linux-GNU.cmake
## Linux GNU Linker used by C compiler
Modules/Plaform/Linker/Linux-GNU-C.cmake
## Default platform linker used by C compiler
Modules/Plaform/Linker/Linux-C.cmake
And the ID
will be provided by the CMAKE_<LANG>_COMPILER_LINKER_ID
variable (see !8885 (merged)). When this variable is not defined, a fall-back to the default platform linker is managed (this the assumption used currently): in the example provided, the file Modules/Platform/Linker/Linux-C.cmake
will be used.
And we will have, for example, for the platform:
-
File
Modules/Platform/Linker/Linux-GNU.cmake
macro(__linux_linker_gnu lang) ... endmacro()
-
file
Modules/Platform/Linker/Linux-GNU-C.cmake
include(Platform/Linker/Linux-GNU) __linux_linker_gnu(C)
-
file
Modules/Platform/Linker/Linux-C.cmake
# default linker on Linux is GNU include(Platform/Linker/Linux-GNU-C)