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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With