Search code examples
ccmakeunix-artcc

How set CMAKE_STATIC_LINKER_FLAGS immediately after the executable file? [tcc -ar]


How set CMAKE_STATIC_LINKER_FLAGS in CMakeLists.txt immediately after the executable file?

for example: I need:

tcc.exe-arqc staticRun.lib CMakeFiles/staticRun.dir/utils/system.c.obj

but cmake after this settings:

set (CMAKE_AR C:/run/code/toolchains/c++/MinGW-tcc/bin/tcc.exe CACHE FILEPATH "" FORCE)

set (CMAKE_STATIC_LINKER_FLAGS -ar CACHE STRING "" FORCE)

add -ar key like this:

tcc.exe qc staticRun.lib CMakeFiles/staticRun.dir/utils/system.c.obj-ar

so, building the static library failed.

P.S.

tcc.exe -ar - mean

Tools: create library : tcc -ar [rcsv] lib.a files


Solution

  • The simplest is just to change the line that is used to run the static library with your custom semantics:

    set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -ar qc <TARGET> <LINK_FLAGS> <OBJECTS>")