Project build configuration in CMake

后端 未结 2 805
野性不改
野性不改 2021-01-03 07:49

My question is very similar to CMake : Changing name of Visual Studio and Xcode exectuables depending on configuration in a project generated by CMake. In that post the outp

相关标签:
2条回答
  • 2021-01-03 08:06

    There is always another way:

      if(CMAKE_BUILD_TYPE MATCHES "release")
    
        SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE})
    
      else(CMAKE_BUILD_TYPE MATCHES "debug")
    
         SET(CMAKE_BUILD_TYPE "debug")
    
       endif(CMAKE_BUILD_TYPE MATCHES "release")
    

    We can use the variable CMAKE_BUILD_TYPE. We can also change this variable at the beginning of invoking CMAKE:

    cmake .. -DCMAKE_BUILD_TYPE:STRING=debug
    

    Then we can use this variable as an indicator of build configuration.

    0 讨论(0)
  • 2021-01-03 08:17

    According to http://cmake.org/cmake/help/v2.8.8/cmake.html#command:target_link_libraries, you can specify libraries according to the configurations, for example:

    target_link_libraries(mytarget
      debug      mydebuglibrary
      optimized  myreleaselibrary
    )
    

    Be careful that the optimized mode means every configuration that is not debug.

    Following is a more complicated but more controllable solution:

    Assuming you are linking to an imported library (not compiled in your cmake project), you can add it using:

    add_library(foo STATIC IMPORTED)
    set_property(TARGET foo PROPERTY IMPORTED_LOCATION_RELEASE c:/path/to/foo.lib)
    set_property(TARGET foo PROPERTY IMPORTED_LOCATION_DEBUG   c:/path/to/foo_d.lib)
    add_executable(myexe src1.c src2.c)
    target_link_libraries(myexe foo)
    

    See http://www.cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets for more details.

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