如何使用CMake创建新配置

时间:2010-11-18 08:38:55

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

我正在尝试为我的项目创建一个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 FAQ:

 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。

谢谢:)

2 个答案:

答案 0 :(得分:2)

我刚刚为简单的hello world项目创建了6或7个VS2008的新配置,其中包括cmake 2.8.4(现在是从2.8.5发布的几天甚至几小时)。

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 bug - 不知道它)。

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

cmake ..

它工作!!!!

答案 1 :(得分:1)

尽管有CMake常见问题解答,看起来这个功能请求仍然有点未实现。甚至有一个未解决的问题:

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

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

相关问题