如何在Visual Studio中将Linux编译添加到Cmake项目 [英] How to Add Linux Compilation to Cmake Project in Visual Studio

查看:489
本文介绍了如何在Visual Studio中将Linux编译添加到Cmake项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio在过去的一年中为C ++添加了许多新功能.

Visual Studio has added lots of new features for C++ in the past year.

CMake 有了CMake支持,我可以执行打开文件夹"并选择一个包含CMakeLists.txt文件的文件夹. Visual Studio在自动发现和构建它方面做了很多出色的工作.

CMake With the CMake support, I can do "Open Folder" and select a folder with a CMakeLists.txt file in it. Visual Studio does a lot of nice work in discovering and building it automatically.

Linux编译 Visual Studio现在支持通过SSH在Linux上进行远程编译.一些教程显示了用户如何在Visual Studio中创建新的"Linux控制台应用程序",并且它将自动要求设置用于构建它的SSH连接.在现有的任何项目上,我都没有看到有关如何执行此操作的任何说明.

Linux Compilation Visual studio now supports remote compilation on Linux over SSH. Several tutorials show how users can create a new "Linux Console Application" in Visual Studio, and it will automatically ask to setup an SSH connection to be used for building it. I don't see any instructions for how to do this on an existing project of any kind.

尤其对于CMake项目,是否可以在Visual Studio 2017中打开CMake文件夹并将其构建在远程Linux机器上?如果怎么办?

Particularly with a CMake project, is it possible to open a CMake folder in Visual Studio 2017 and have it built over on a remote Linux machine? IfSoHow?

推荐答案

CMake尚不支持VS"Linux控制台应用程序"的内置支持(与CMake 3.9版一样).

There is no build-in support for a VS "Linux Console Application" in CMake yet (as for CMake version 3.9).

编辑:Visual Studio 2017 15.4现在具有类似的内容,但不会生成实际的.vcxproj文件.请参阅 Visual C ++使用CMake进行Linux开发

Visual Studio 2017 15.4 now comes with something similar without generating actual .vcxproj files. See Visual C++ for Linux Development with CMake

除了在此处使用现有的.vcxproj文件作为模板,您只能欺骗CMake生成那些项目类型:

With a standard CMake version besides the possibilities described here using existing .vcxproj files as a template, you can only trick CMake into generating those project types:

cmake_minimum_required(VERSION 3.7)

project(HelloLinux)

file(WRITE main.cpp [=[
#include <iostream>

int main()
{
    std::cout << "Hello from Linux Console!" << std::endl;
}
]=])

add_executable(HelloLinux "main.cpp")

set_target_properties(
    HelloLinux
    PROPERTIES
        VS_GLOBAL_KEYWORD "Linux"
        VS_GLOBAL_ApplicationType "Linux"
        VS_GLOBAL_ApplicationTypeRevision "1.0"
        VS_GLOBAL_TargetLinuxPlatform "Generic"
        VS_GLOBAL_LinuxProjectType "{D51BCBC9-82E9-4017-911E-C93873C4EA2B}"
)

这实际上可以工作,并产生一个被VS接受的Linux .vcxproj项目.但是,由于我们在这里避开了CMake,因此不会分配您在CMake脚本中定义的其他编译器/链接器选项.

This actually works and produces a Linux .vcxproj project that is accepted by VS. But since we sidestepped CMake here, none of the other compiler/linker options you define in your CMake script will be assigned.

因此,我的建议是提出功能请求,以便CMake本身直接支持(例如通过平台工具集选项Remote_GCC_1_0).

So my recommendation is to raise a feature request for CMake itself to directly support this (e.g. via platform toolset option Remote_GCC_1_0).

这篇关于如何在Visual Studio中将Linux编译添加到Cmake项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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