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
  • 59
  • 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
  • @KamilCuk no it does not, as it limits the solution to UNIX-like systems, and using CMAKE_CXX_ARCHIVE_CREATE seems like a cross-platform way. Why are they not replaced? What if the custom target is intending to create a static library? – Dávid Tóth Sep 27 '22 at 18:53
  • `Why are they not replaced?` It's hard to reason why something does not happen. It doesn't happen because it's not meant to happen. There is nothing that would "replace" `` for anything else inside `add_custom_target` command. `What if the custom target is intending to create a static library?` Then _you_ need to write a command yourself. – KamilCuk Sep 27 '22 at 20:51

0 Answers0