【问题标题】:How to create a new configuration with CMake如何使用 CMake 创建新配置
【发布时间】:2011-05-11 21:47:07
【问题描述】:

我正在尝试为我的项目创建一个 NewConfiguration:

set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug;NewConfiguration" CACHE STRING "Configurations" FORCE)

但是当我运行 CMake 时,我有多个错误:

CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_SHARED_LINKER_FLAGS_NEWCONFIGURATION
CMake Error: Error required internal CMake variable not set, cmake may be not be
 built correctly.
Missing variable is:
CMAKE_CXX_FLAGS_NEWCONFIGURATION

我想我错过了什么......

我还关注了 CMake 常见问题解答:

 if(CMAKE_CONFIGURATION_TYPES)
   set(CMAKE_CONFIGURATION_TYPES Release RelWithDebInfo Debug NewConfiguration)
   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
     "Reset the configurations to what we need"
     FORCE)
 endif()

但同样的错误...

编辑:

如果我这样做:

    SET( CMAKE_CXX_FLAGS_PLAYERVIEWER "-Wall -Wabi" CACHE STRING "Flags used by the C++ compiler during maintainer builds." FORCE )
SET( CMAKE_C_FLAGS_PLAYERVIEWER "-Wall -pedantic" CACHE STRING "Flags used by the C compiler during maintainer builds." FORCE )
SET( CMAKE_EXE_LINKER_FLAGS_PLAYERVIEWER "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING "Flags used for linking binaries during maintainer builds." FORCE )
SET( CMAKE_SHARED_LINKER_FLAGS_PLAYERVIEWER "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING "Flags used by the shared libraries linker during maintainer builds." FORCE )


set (CMAKE_CONFIGURATION_TYPES "Release;RelWithDebInfo;Debug;PlayerViewer" CACHE STRING "Configurations" FORCE)

它创建了新配置,但我无法编译。我认为标志不正确。我正在使用 Visual Studio 2008。

谢谢你:)

【问题讨论】:

    标签: visual-studio visual-studio-2008 visual-c++ cmake


    【解决方案1】:

    我刚刚为简单的 hello world 项目使用 cmake 2.8.4(现在距离 2.8.5 发布几天甚至几小时)为 VS2008 创建了 6 或 7 个新配置。

    The reason why your attemps failed what flags are  inccorect e.g. they must be /MDd no -MDd
    You notation will work for GCC based compilers, not for VS.
    

    我建议你设置最接近的标志然后修改它

    set(CMAKE_CXX_FLAGS_FOO ${CMAKE_CXX_FLAGS_DEBUG})
    # .. modifiy it - add or remove flags
    

    我还注意到 cmake 有时实际上并没有写入 .sln 或者它并不总是重新加载(好吧,我在 VirualBox 上运行 win7 可能是问题的根源)。

    我所做的是以下 -

    file(GLOB WILL_REMOVE "${CMAKE_CURRENT_BINARY_DIR}/*.vcproj")
    execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${WILL_REMOVE})
    
    file(GLOB WILL_REMOVE "${CMAKE_CURRENT_BINARY_DIR}/*.sln")
    execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${WILL_REMOVE})
    
    file(GLOB WILL_REMOVE "${CMAKE_CURRENT_BINARY_DIR}/*.user")
    execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${WILL_REMOVE})
    

    至少它会重新加载文件:)

    但是,有时我需要运行 cmake 2 或 3 次才能在 Visual Studio 中看到新配置(可以是虚拟框、cmake 或 Visual Studio 错误 - 不知道)。

    但是,无论如何,在 2 或 3 之后

    cmake ..
    

    它工作!!!!

    【讨论】:

    • “运行多次...”可能是 Visual Studio 的问题,而不是 CMake 的问题。基本上我的经验是,在 VS2005 和 2008(还没有使用 2010)中重新加载项目通常不起作用,所以我总是关闭解决方案并重新打开它。
    【解决方案2】:

    尽管有 CMake 常见问题解答,但对于此功能请求,似乎仍有一些未实现的内容。它甚至还有一个未解决的问题:

    http://www.cmake.org/Bug/view.php?id=5811

    在 CMake 错误跟踪器中监控该错误,以便在更新时收到通知。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2017-01-04
      相关资源
      最近更新 更多