Search code examples
c++visual-studiolinkercmakebullseye

cmake add prefix to linker


I know how to add a prefix to linker. I need this because I need to add bullseye compiler and linker prefixes before compiling and linking.

SET(CMAKE_CXX_COMPILER "${BULLSEYE_PREFIX_CC} --no-banner ${CMAKE_CXX_COMPILER}")
SET(CMAKE_C_COMPILER "${BULLSEYE_PREFIX_CC} --no-banner ${CMAKE_C_COMPILER}")

I cant seem to find similar ones for linker. Any pointers?

Thanks, Nick

These are the values to my compiler and linker prefixes. The compiler works fine and generates the cov file. However, the linker does not seem to be generating the executable. It compiles files and build executable but then it says its linking and fails. Not sure whats happening :(

C:/src/sw/tools/Bullseye/win32/8.7.33/BullseyeCoverage/bin/covc.exe C:/src/sw/to
ols/win32/msvc110/VC/bin/cl.exe
C:/src/sw/tools/Bullseye/win32/8.7.33/BullseyeCoverage/bin/covlink.exe <CMAKE_CO
MMAND> -E vs_link_exe <CMAKE_CXX_COMPILER> /nologo <OBJECTS> @<<
 <FLAGS> /Fe<TARGET> /Fd<TARGET_PDB> -link /implib:<TARGET_IMPLIB> /version:<TAR
GET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <L
INK_LIBRARIES>
<<

Solution

  • Use CMAKE_CXX_LINK_EXECUTABLE:

    set(CMAKE_CXX_LINK_EXECUTABLE "${BULLSEYE_PREFIX_CC} ${CMAKE_CXX_LINK_EXECUTABLE}")
    

    Note that it's not just path to linker but also flags and variables, e.g. for cygwin CMAKE_CXX_LINK_EXECUTABLE is:

    <CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> -Wl,--out-implib,<TARGET_IMPLIB> -Wl,--major-image-version,<TARGET_VERSION_MAJOR>,--minor-image-version,<TARGET_VERSION_MINOR> <LINK_LIBRARIES>
    

    Note

    This will add prefix but you should use caution. I would suggest to print using message command and see that the result is what you want. This variable is not easily customizable, so you might have to do some string processing in cmake.