1

Im using

add_custom_target(combined ALL
    DEPENDS ${PROJECT_NAME}
    COMMAND ${CMAKE_CXX_ARCHIVE_CREATE} 
    ${PROJECT_NAME}Full${CMAKE_STATIC_LIBRARY_SUFFIX} 
    $<TARGET_FILE:${PROJECT_NAME}> ${LIB_A} ${LIB_B})

as described in https://stackoverflow.com/a/14200728/4434064.

The variable ${CMAKE_CXX_ARCHIVE_CREATE} is defined as

set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")

The resulting Makefile states:

"<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>" ProjectFull.a Project.a LibA.a LibB.a

The variables CMAKE_AR, TARGET, ... will not be replaced by CMake and "make combined" is not executable. What am I doing wrong?

kenomo
  • 49
  • 6
  • `What am I doing wrong?` Well, you are wrongly expecting them to be replaced. They will not be replaced. The are replaced when cmake creates a static library, not in a custom target. Is it a XY question? What do you want to do? Do you want to combine multiple static libraries together? – KamilCuk Aug 07 '20 at 10:29
  • Yes, I want to combine multiple static libraries. – kenomo Aug 07 '20 at 10:58
  • 1
    Does this answer your question? [Combining several static libraries into one using CMake](https://stackoverflow.com/questions/37924383/combining-several-static-libraries-into-one-using-cmake) – KamilCuk Aug 07 '20 at 11:15

0 Answers0