I am writing function in my cmake project that needs to make two targets from one, and alter slightly one of them:
option(BORG_STRIP_TEST_BINARIES OFF "Strip symbols from test binaries to reduce disk space usage" )
function(add_borg_test target)
add_test(${target} ${target} --gtest_color=yes)
if(BORG_STRIP_TEST_BINARIES)
# copy target, but make it optional
duplicate_target(FROM ${target} TO ${target}_debug )
set_target_properties(${target}_debug PROPERTIES EXCLUDE_FROM_ALL TRUE)
# alter
target_link_options(${target} PRIVATE -s)
endif()
endfunction()
So this is supposed to work like this:
- I create binary target that uses gtest. Set up all
target_link_libraries
and everything. Example name example-utests
- instead add generic
add_test
, I use custom add_borg_test
- now
example-utests
links with flag -s
and is included in all
target.
example-utests_debug
is NOT included in all
target but when requested explicitly, it links without -s
.
How to implement duplicate_target
from above code snippet?
question from:
https://stackoverflow.com/questions/65882591/how-to-duplicate-cmake-target 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…