CMake: Set different name for #cmakedefine variable

前端 未结 2 561
忘掉有多难
忘掉有多难 2021-01-28 20:25

I know you can use CMake\'s configure_file to make CMake variables available to your program. For example, I can use

#define ${CMAKE_BUILD_TYPE}
         


        
2条回答
  •  失恋的感觉
    2021-01-28 20:46

    Here is a fairly simple way to solve it:

    In CMakesLists.txt:

    if (NOT CMAKE_BUILD_TYPE)
        set (CMAKE_BUILD_TYPE Release)
    endif (NOT CMAKE_BUILD_TYPE)
    
    string (TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_NAME)
    
    configure_file (config.h.in config.h)
    

    And in config.h.in:

    #define BUILD_TYPE_${BUILD_TYPE_NAME}
    

    I am, however, still curious if there is a more elegant solution.

提交回复
热议问题