問題描述
幾年前,我正在嘗試使用 Visual Studio 2010 構建我的一個基于 CMake 的項目,但我遇到了與項目的輸出目錄有關的問題.Visual Studio 一直非常熱衷于在輸出二進制文件時添加 Debug/和 Release/子目錄,出于各種原因,我一直非常熱衷于刪除它們 - 現在我正在使用新版本的 CMake 和新版本的Visual Studio,CMake 中的舊解決方法似乎不再有效,我正在尋找新"的方法.
I'm trying to build one of my CMake-based projects from a couple of years ago with Visual Studio 2010 and I'm running into problems to do with the output directory for a project. Visual Studio has always been very keen on adding Debug/ and Release/ subdirectories when outputting binaries, and for various reasons I've always been very keen on removing them - now that I'm using a new version of CMake and a new version of Visual Studio, the old workaround in CMake no longer seems to work, and I'm looking to find out the "new" way of doing it.
對于以前版本的 CMake (2.6) 和以前版本的 Visual Studio (2008),我使用了以下內容:
With a previous version of CMake (2.6) and a previous version of Visual Studio (2008), I used the following:
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 一起使用嗎?
This worked fine, but no longer seems to do the trick. Please does anyone know of a similar but more up-to-date workaround that will work with CMake 2.8.6 and Visual Studio 2010?
推薦答案
這在一定程度上取決于您想要什么,但我建議您查看可用的 目標屬性,類似于這個問題.
It depends a bit on what you want precisely, but I would recommend to take a look at the available target properties, similar to this question.
這在一定程度上取決于您究竟想要什么.對于每個目標,您可以手動設置 library_output_directory 或runtime_output_directory 屬性.
It depends a bit on what you want exactly. For each target, you could manually set the library_output_directory or runtime_output_directory properties.
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 )
您也可以使用以下方法對所有子項目全局執行此操作:
You could also do this globally for all sub-projects, using something like this:
# 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 )
這篇關于在 CMake 中,如何解決 Visual Studio 2010 嘗試添加的 Debug 和 Release 目錄?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!