CMAKE <LINK_LIBRARIES> separated by spaces not commas in linker command

I’m trying to get CMake to use a custom compiler to build some code. I’ve setup a cmake toolchain file that works great for everything besides linking in static libraries. The linker requires all libraries to be passed using a -library=example.lib,example2.lib. Cmake seems to default to using spaces to separate libraries but this linker won’t take it. Here is my linker call example from my toolchain file:

set(CMAKE_C_LINK_EXECUTABLE "${LINKER} <OBJECTS> -library=<LINK_LIBRARIES> <LINK_FLAGS> -output=<TARGET>")

This produces everything except the librarys are passed like this:

-library= example1.lib example2.lib

Not this:

-library=example1.lib,example2.lib

How can I get CMake to separate the <LINK_LIBRARIES> variable with commas not spaces? It even puts one between the -library= and the first lib.

I don’t recall seeing a variable that controls this. We may need to introduce a new toggle for it.

@brad.king

The <LINK_LIBRARIES> placeholder is meant to be replaced by a command-line fragment by the generators, so there is no way to control this currently.

Would -library=example1.lib -library=example2.lib be sufficient?

Hi Brad,

Yes that would work! I tried figuring it out but my lack of CMake knowledge stopped me. ‘
Is there a method where that would be possible? I figured it was since a lot of libraries are prefaced with “-l” and I would just need to swap that out with “-library=“.

Thanks for the response!

In your custom compiler cmake code, try this:

set(CMAKE_LINK_LIBRARY_FLAG "-library=")

Hi Brad,

I gave that a shot but nothing changed on my out put, is it something with the <LINK_LIBRARIES> variable?
My command is still:

set(CMAKE_STATIC_LIBRARY_SUFFIX_C .lib)
set(CMAKE_LINK_LIBRARY_FLAG "-library=")
set(CMAKE_C_LINK_EXECUTABLE     "\"${CMAKE_CCRH_LINKER}\" <OBJECTS> <LINK_FLAGS> <LINK_LIBRARIES> -output=<TARGET>")

With the output of:

../modules/system/libsystem.lib ../modules/system/libblank_2.lib

CMake prefers to name libraries by the path to the file on disk. This avoids risk of the linker’s search path containing a conflict. If the -library= flag supports that, try:

set(CMAKE_LINK_LIBRARY_FILE_FLAG "-library=")

Yay! Worked like a charm! Ugh so many options for similar things, I’m sure it makes sense if you understand deeply how CMake works. Looks like I need to do some more research so I can better help myself in the future.
Thank you so much for your help!