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?
The command
should do what you want. I’m not in front of a devel machine right now, checking later.