在 CMake 中,如何解决 Visual Studio 2010 尝试添加的调试和发布目录?

新手上路,请多包涵

我正在尝试使用 Visual Studio 2010 从几年前构建我的一个基于 CMake 的项目,但我遇到了与项目的输出目录有关的问题。 Visual Studio 一直非常热衷于在输出二进制文件时添加 Debug/ 和 Release/ 子目录,并且由于各种原因我一直非常热衷于删除它们 - 现在我正在使用新版本的 CMake 和新版本的Visual Studio,CMake 中的旧解决方法似乎不再有效,我正在寻找“新”的方法。

使用以前版本的 CMake (2.6) 和以前版本的 Visual Studio (2008),我使用了以下内容:

 IF(MSVC_IDE)
    # A hack to get around the "Debug" and "Release" directories Visual Studio tries to add
    SET_TARGET_PROPERTIES(${targetname} PROPERTIES PREFIX "../")
    SET_TARGET_PROPERTIES(${targetname} PROPERTIES IMPORT_PREFIX "../")
ENDIF(MSVC_IDE)

这工作得很好,但似乎不再奏效了。请问有谁知道类似但更新的解决方法可以与 CMake 2.8.6 和 Visual Studio 2010 一起使用?

原文由 Stuart Golodetz 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 431
1 个回答

这有点取决于你想要什么,但我建议你看看可用的 目标属性,类似于 这个问题

这有点取决于你到底想要什么。对于每个目标,您可以手动设置 library_output_directoryruntime_output_directory 属性。

 if ( MSVC )
    set_target_properties( ${targetname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${youroutputdirectory} )
    set_target_properties( ${targetname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${youroutputdirectory} )
    set_target_properties( ${targetname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${youroutputdirectory} )
    # etc for the other available configuration types (MinSizeRel, RelWithDebInfo)
endif ( MSVC )

您也可以使用以下方式对所有子项目全局执行此操作:

 # First for the generic no-config case (e.g. with mingw)
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${youroutputdirectory} )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${youroutputdirectory} )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${youroutputdirectory} )
# Second, for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
    string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
    set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${youroutputdirectory} )
    set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${youroutputdirectory} )
    set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${youroutputdirectory} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

原文由 André 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题