visual-studio - 如何使用 CMake 创建新配置

标签 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 常见问题解答:
 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。

谢谢 :)

最佳答案

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

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 创建新配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4212945/

相关文章:

c# - 当前上下文中不存在名称 'DependencyProperty' (Visual Studio)

visual-studio - 如何在 Visual Studio 2010 中启用 CUDA .cu 文件的语法高亮显示?

visual-studio - 如果我是个人开发者,我应该打扰 VS Team System 吗?

c++ - 是否可以从 CMFCRibbonCategory 中删除 CMFCRibbonPanel?

visual-studio-2010 - 使用 Microsoft Visual Studio C++ 2010 Express(免费版)创建 map 文件时出错

c++ - 放置外部虚拟表

windows - 如何在Windows上使用clang从命令行传递链接描述文件?

visual-studio - 未找到 Visual Studio 2017 和 Windows 10 SDK 10.0.15063 _scale-100.appx

c# - Debug.Assert 出现在 Release模式

visual-studio-2008 - 如何持续更新 VS2008 Watch Window(不停止执行)?