Copy or move libs after build with cmake

My project has a folder containing third-party libraries (google test, zlib, ...). I want to put the libraries in a shared folder when all these libraries are created. I am trying to do this with cmake, but I am having problems. I am trying this code:

add_subdirectory(gtest-1.6.0) add_custom_command( TARGET gtest_main POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SRC_LIB_DIR}/*.a ${DST_LIB_DIR}) 

I think the problem may be that the target main goal is not defined at this level, but at a lower level

+8
cmake
source share
1 answer

If you set the CMAKE_LIBRARY_OUTPUT_DIRECTORY variable to your CMakeLists.txt before calling add_subdirectory (and the subproject does not override it), the libraries should go to the right place.

In addition, the same target in the subproject remains dependent on the output file. What will not work with your copy is that the goal will always be obsolete and therefore rebuilt.

EDIT: I forgot that your copy-command copies .a files and thanks to @Fraser comment, I also found out that CMAKE_ARCHIVE_OUTPUT_DIRECTORY should do the trick.

+8
source share

All Articles