Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

How to duplicate cmake target

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?

question from:https://stackoverflow.com/questions/65882591/how-to-duplicate-cmake-target

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...