Debug and Release Library Linking with CMAKE (VISUAL STUDIO)

后端 未结 5 1522
我在风中等你
我在风中等你 2020-12-02 23:23

There was already a Thread which did not help really. I want to be able to link for example Foo.lib for Release Config and Foo_d.l

5条回答
  •  星月不相逢
    2020-12-03 00:01

    If you have debug/release libs that follow a certain pattern, like _d on the debug ones, you can avoid repeating yourself with:

    set (MY_LIBS
        foo
        bar
        baz
    )
    
    # Generate the list of files to link, per flavor.
    set (LINK_LIST "")
    foreach(x ${MY_LIBS})
        list (APPEND LINK_LIST debug ${x}_d optimized ${x})
    endforeach()
    
    target_link_libraries (mytarget
        commonlib1
        commonlib2
        ${LINK_LIST}
        )
    

    This will generate the appropriate

    debug foo_d optimized foo
    debug bar_d optimized bar
    

    lines that target_link_libraries expects.

提交回复
热议问题