cmake: add “d” suffix for debug build of static library

后端 未结 1 941
南旧
南旧 2020-12-31 17:59

I would like to implement a naming scheme for libraries similar to the one mentioned here: Library name for x32 vs x64

The CMakeLists.txt file is setup to create a s

相关标签:
1条回答
  • 2020-12-31 18:17

    CMAKE_DEBUG_POSTFIX is used for appending the d for debug libraries:

    set(CMAKE_DEBUG_POSTFIX d)
    

    If you do not want to set this globally, you can also use the DEBUG_POSTFIX target property instead on selected libraries.

    There is no corresponding feature for distinguishing 32/64 bit builds, but since it is impossible to mix those two in the same CMake configuration, you can easily distinguish those cases manually, e.g.

    if(CMAKE_SIZEOF_VOID_P EQUAL 4)
        set(ARCH_POSTFIX "")
    else()
        set(ARCH_POSTFIX 64)
    endif()
    
    add_library(my_lib${ARCH_POSTFIX} [...])
    

    Or, if you want to use the same target name on the different architectures, set a variable like CMAKE_STATIC_LIBRARY_SUFFIX (there exist a whole bunch of them, so you can select the correct one for your target type and based on which output files you want to append a suffix to).

    And since you also mentioned this answer for finding such libraries: Prefer using imported targets instead of the coarse-grained legacy debug and optimized qualifiers for target_link_libraries. Config file packages provide a convenient way of exposing such imported targets to your clients, and they also handle any suffix shenanigans automatically for you.

    0 讨论(0)
提交回复
热议问题