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_librariesand everything. Example nameexample-utests - instead add generic
add_test, I use customadd_borg_test - now
example-utestslinks with flag-sand is included inalltarget. example-utests_debugis NOT included inalltarget but when requested explicitly, it links without-s.
How to implement duplicate_target from above code snippet?