在CMake中,如何解决Visual Studio 2010尝试添加的调试和发布目录? [英] In CMake, how do I work around the Debug and Release directories Visual Studio 2010 tries to add?

查看:144
本文介绍了在CMake中,如何解决Visual Studio 2010尝试添加的调试和发布目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在几年前使用Visual Studio 2010构建我的基于CMake的项目之一,并且遇到了一个项目的输出目录的问题。 Visual Studio一直非常热衷于在输出二进制文件时添加Debug /和Release / subdirectory,并且出于各种原因,我一直非常热衷于删除它们 - 现在我正在使用新版本的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尝试添加的调试和发布目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆