如何最好地设置由Visual Studio 2017构建的CMake C ++项目的输出目录? [英] How best to set output directory for a CMake C++ project built by Visual Studio 2017?

查看:448
本文介绍了如何最好地设置由Visual Studio 2017构建的CMake C ++项目的输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用Visual Studio 2017使用.vcxproj文件构建C ++桌面项目。我喜欢默认行为,其中输出目录是项目下面的子目录。例如:

I have used Visual Studio 2017 to build C++ desktop projects using .vcxproj files. I like the default behavior where the output directory is a subdirectory below the project. For example:

|-myproj.sln
|-myproj.vcxproj
|-----------------|--x64 --|-- myproj_release --|-- myproj.exe

我现在想使用CMake而不是.vcxproj定义构建,以便我可以使用Visual Studio Code进行构建,以替代Visual Studio 2017。

I now want to define the build using CMake instead of .vcxproj, so that I can build with Visual Studio Code as an alternative to Visual Studio 2017.

我使用cmake-converter将.vcxproj转换为CMake项目。生成的CMakeLists.txt包含:

I converted my .vcxproj to a CMake project using cmake-converter. The resulting CMakeLists.txt contains:

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
  set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_DEBUG}")
else()
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
  set(CMAKE_EXECUTABLE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${OUTPUT_REL}")
endif()

当我打开此文件时CMakeLists.txt并使用Visual Studio 2017进行构建,它将可执行文件放入用户目录的CMakeBuilds子目录中。我猜这是因为Visual Studio 2017正在确定CMAKE_BINARY_DIR。

When I open this CMakeLists.txt with Visual Studio 2017 and build it, it puts the executable in subdirectory CMakeBuilds of my user directory. I guess this is because Visual Studio 2017 is determining CMAKE_BINARY_DIR.

使输出目录位于源目录中的最佳方法是什么,就像我的.vcxproj文件一样? ?

What is the best way of getting the output directory to be in the source directory as happens with my .vcxproj file?

推荐答案

我认为我的问题的答案是修改CmakeSettings.json中的buildRoot:

I think the answer for my question is to modify buildRoot in CmakeSettings.json:

"buildRoot": "${workspaceRoot}\\build\\${name}"

这篇关于如何最好地设置由Visual Studio 2017构建的CMake C ++项目的输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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