I try to create a cmake custom target to merge several .a files into a single one. Note that I cannot use the OBJECTSlib mode because I have a lot of 3rd party library (I'm in a complex environment, conan, cmake, etc...).
So I wrote the following
add_custom_target(combineall
COMMAND echo "extract all .o files from all lib*.a file in the static folder"
COMMAND for f in *.a ; do ar -x $f ; done
COMMAND echo "merge all .o files in the static folder"
COMMAND for f in *.o ; do ar -rs ${CMAKE_BINARY_DIR}/libmerged.a $f ; done
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/static
DEPENDS MyLib
)
but when cmake run the combineall custom target I get the following error message:
extract all .o files from all lib*.a file in the static folder /bin/sh: -c: line 1: syntax error: unexpected end of file
I suppose that it come from the $f. I know that I could wrote a completely different cmake script iterating others the .a files using the cmake for_eachsyntax but It's not my goal here !
Regards, Alex