CMAKE_C_LINK_EXECUTABLE not considered for MINGW32


I am trying to specify the CMAKE_C_LINK_EXECUTABLE and the CMAKE_CXX_LINK_EXECUTABLE variables in one of my toolchain files targetting MINGW32.

Any value specified for these two variables gets overwritten and therefore not considered at some point in the CMake config phase. It is even not considered when determining if my toolchain works.

I suspected that the problem resides somewhere in the share directory of my CMake installation (Version 3.15), but none of my search results for the two aforementioned variables looks as if the values would be overwritten there. In all cases they concern other toolchains than the ones for Windows/MINGW32 builds.

Thanks for your help!

These variables are set by Compiler/<id>-<lang>.cmake and Platform/<os>-<id>-<lang>.cmake modules, where <id> is the compiler id CMake detects. For example, it is set for MinGW tools (GNU on Windows) in the builtin Modules/Platform/Windows-GNU.cmake that comes with CMake.

If you’re creating a new platform (e.g. with CMAKE_SYSTEM_NAME set to “MyPlatform”) then you should create a MyPlatform-GNU-{C,CXX}.cmake module in your project and add the root location to CMAKE_MODULE_PATH in the toolchain file.

Why do you want to override CMAKE_{C,CXX}_LINK_EXECUTABLE?

Hi Brad,

thanks a lot for your quick and helpful response! Looking into the Windows-GNU.cmake file revealed that the value of CMAKE_${lang}_LINK_EXECUTABLE is changed there. I was just searching for CMAKE_C_LINK_EXECUTABLE, that’s the reason I did not find it.

For us the solution seems to be to define our own platform that is copied from the Windows platform.

The reason we need to modify CMAKE_C_LINK_EXECUTABLE is that we want to run a coverage (CTC++) tool on our source base. In order to get that running, one needs to place it in front of the actual compiler/linker invocation, e. g.

ctc -i -m gcc.exe -c -o file.obj file.c
ctc gcc.exe -o file.exe file.obj

In case there is a better approach to this problem, please just let me know!

Best regards and thanks again,

Did you have a look at : <LANG>_COMPILER_LAUNCHER variable:<LANG>_COMPILER_LAUNCHER

it can be used for your purpose I think.
I use it for ccache but I guess your use case is similar.