Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake add_library at a custom location

Tags:

cmake

I need to build a library that is to be placed at a custom location stored in the variable CUSTOM_OUTDIR. Currently, I am using the following code to make sure that the library is copied to its proper location.

ADD_LIBRARY(example MODULE example.c)

GET_TARGET_PROPERTY(FILEPATH example LOCATION)
ADD_CUSTOM_COMMAND(
    TARGET example POST_BUILD 
    COMMAND ${CMAKE_COMMAND} 
    ARGS -E copy ${FILEPATH} ${CUSTOM_OUTDIR}
)

However, this is not a good solution as the copying is done post_build, and I end up with two copies of the library. Is there a way to setup CMAKE_BINARY_DIR just for the example library so that only one copy of it is kept in the proper location?

like image 340
D R Avatar asked May 11 '10 20:05

D R


1 Answers

The command

set_target_properties(example PROPERTIES 
  LIBRARY_OUTPUT_DIRECTORY "${CUSTOM_OUTDIR}"
)

should do what you want. I'm not in front of a devel machine right now, checking later.

like image 116
Maik Beckmann Avatar answered Nov 15 '22 07:11

Maik Beckmann