How to duplicate cmake target

Viewed 961

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:

  1. I create binary target that uses gtest. Set up all target_link_libraries and everything. Example name example-utests
  2. instead add generic add_test, I use custom add_borg_test
  3. now example-utests links with flag -s and is included in all target.
  4. 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?

0 Answers
Related