Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy or move libs after build with cmake

Tags:

cmake

In my project there is a folder that contains third party libraries (google test, zlib, ...). I want to put the libraries in a common folder when all this libraries are built. I'm trying to do this with cmake but I'm having problems. I'm 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 could be that the target gtest main in not defined at this level but in a lower level

like image 755
Killrazor Avatar asked Mar 14 '13 09:03

Killrazor


1 Answers

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

Additionally like this the target in the subproject keeps their dependency to the output-file. Which wouldn't work with your copy - the target would be always out-of-date and thus rebuilt.

EDIT: I overlooked that your copy-command is copying .a-files and thanks to @Fraser's comment I learned as well that CMAKE_ARCHIVE_OUTPUT_DIRECTORY should to do the trick.

like image 97
Patrick B. Avatar answered Nov 08 '22 01:11

Patrick B.