Is there a CMAKE_CXX_COMPILER_LAUNCHER but for the linker?

I’m having some trouble finding this information, so sorry if I missed something in the documentation. But I have a project with a separate compiler and linker, and they both require certain environment variables to be set up beforehand, I managed to get around this for the compiler by using CMAKE_CXX_COMPILER_LAUNCHER with a batch script that set the relevant variables before invoking the compiler, but I’m having trouble with figuring out how to do the same for the linker.

The compiler is usually used as the linker as well, though I don’t know if the link rule ends up using the configured launcher. @brad.king?

@Matt_Rogers see CMake Issue 18351 and discussion in CMake Issue 18316.

@ben.boeckel I think the idea is that a different launcher should be used for the same compiler driver based on whether it is launching a compile step or a link step. ccache works for compiling, but some other tool could be used to wrap linking.

@ben.boeckel

I understand that this is usually true, but we have a bit of a weird setup where the linker and compiler that we use are different executables, and the CMAKE_CXX_COMPILER_LAUNCHER is not invoked when doing the link step. So to clarify we have different executables specified for CMAKE_CXX_COMPILER and CXX_LINKER.

Looking at the resulting build.ninja file the linker invocation is not invoked via the CMAKE_CXX_COMPILER_LAUNCHER variable.

@brad.king Is there any active development in the direction of those issues or is that dead in the water right now?

If you’re using gcc or clang (or other compatible compiler), you can set the linker it uses with the -fuse-ld= argument. Just add that to CMAKE_[C/CXX]_COMPILER_FLAGS and CMake doesn’t have to worry about the linker executable details.

See my stackoverflow answer on exactly this topic.

No one upstream is working on it currently, but I’d be happy to review proposed changes in a merge request.

Note for Readers from search machines:

CMAKE_LANG_LINKER_LAUNCHER and acording property was added in CMake 3.21