Stu*_*etz 26 c++ 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)
Run Code Online (Sandbox Code Playgroud)
这工作得很好,但似乎不再有诀窍.请问有关类似但更新的解决方法是否可以与CMake 2.8.6和Visual Studio 2010一起使用?
And*_*dré 57
这取决于你想要什么,但我建议看看可用的目标属性,类似于这个问题.
这取决于你想要什么.对于每个目标,您可以手动设置library_output_directory或runtime_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 )
Run Code Online (Sandbox Code Playgroud)
您也可以使用以下内容对所有子项目进行全局操作:
# 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 )
Run Code Online (Sandbox Code Playgroud)
https://cmake.org/cmake/help/latest/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html解释说:
除非使用生成器表达式,否则多配置生成器(VS、Xcode)会将每个配置的子目录附加到指定目录。
因此,唯一的解决方法是使用生成器表达式。一种很酷的方法是在路径的末尾使用 $<0:> 。因此,如果您的路径是 /what/ever/,则需要将其替换为 /what/ever/$<0:>。
目标示例:Nuua 和路径:C:/Nuua/bin/
set_target_properties(nuua PROPERTIES RUNTIME_OUTPUT_DIRECTORY C:/Nuua/bin/$<0:>)
Run Code Online (Sandbox Code Playgroud)
在当前版本的 CMake 中,您可以使用生成器表达式LIBRARY_OUTPUT_DIRECTORY来避免配置特定的后缀。
我刚刚添加了$<$<CONFIG:Debug>:>,它总是扩展到没有,到我的。这看起来有点奇怪,但它确实有效,而且并没有那么奇怪,你无法用简短的评论来解释它:
# Use a generator expression so that the specified folder is used directly, without any
# configuration-dependent suffix.
#
# See https://cmake.org/cmake/help/v3.8/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html
set_target_properties(library PROPERTIES
LIBRARY_OUTPUT_DIRECTORY my/folder/$<$<CONFIG:Debug>:>)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21085 次 |
| 最近记录: |