6

CMake Project에서 크로스 플랫폼 Linux 프로젝트 용 Visual Studio 솔루션을 생성하고 싶습니다.Visual Studio 용 CMake Generator Linux 크로스 플랫폼

특히 디버깅과 관련하여 Visual Studio 2017 크로스 플랫폼 작업 부하가 제대로 작동합니다. 나는 그것을 WSL을 목표로 삼는다. 이제 Windows 및 Visual Studio에서 개발하고 WSL로 빌드하려는 기존의 Linux CMake 프로젝트가 있습니다. Visual Studio에 적합한 솔루션을 생성하는 방법을 알 수없는 것 같습니다. 누구나 나를 계몽시킬 수 있습니까?

+0

WSL이란 무엇입니까? MSVC 컴파일러를 사용하여 Windows 바이너리를 빌드하는 VS 솔루션을 생성해야하는 경우에는 cmake-gui를 사용하면됩니다. 나는 적당한 대답을 할 수 있었지만, 나는 더 많은 정보가 필요하다. – dragn

+0

WSL은 Windows 용 Linux 바이너리를 실행할 수있는 Linux 용 새 Windows 하위 시스템입니다. 또한 ssh를 실행 한 다음 크로스 플랫폼 작업 부하를 통해 Windows의 VS에서 대상을 지정할 수 있습니다. 그러므로 내 질문. – Felix

답변

2

CMake가 "Linux"프로젝트 유형을 지원하기 위해 이미 some queries이 있었지만, there is something implemented yet (코드를보고 필요한 프로젝트 설정을 생성 할 수 없음)이라고 생각하지 않습니다.

이러한 경우에는 include_external_msproject() 명령 호출 만 사용할 수 있습니다.

include_external_msproject(
    MyProject 
    ${CMAKE_CURRENT_SOURCE_DIR}/MyProject/MyProject.vcproj 
) 

그래서

의이 같은 기존 리눅스 .vcxproj 파일의 템플릿을 만들어 보자 :

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="@[email protected]" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <ItemGroup Label="ProjectConfigurations"> 
    <ProjectConfiguration Include="Debug|x86"> 
     <Configuration>Debug</Configuration> 
     <Platform>x86</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Release|x86"> 
     <Configuration>Release</Configuration> 
     <Platform>x86</Platform> 
    </ProjectConfiguration> 
    </ItemGroup> 
    <PropertyGroup Label="Globals"> 
    <ProjectGuid>@[email protected]</ProjectGuid> 
    <Keyword>Linux</Keyword> 
    <RootNamespace>@[email protected]</RootNamespace> 
    <MinimumVisualStudioVersion>@[email protected]</MinimumVisualStudioVersion> 
    <ApplicationType>Linux</ApplicationType> 
    <ApplicationTypeRevision>1.0</ApplicationTypeRevision> 
    <TargetLinuxPlatform>Generic</TargetLinuxPlatform> 
    <LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType> 
    </PropertyGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration"> 
    <UseDebugLibraries>true</UseDebugLibraries> 
    </PropertyGroup> 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration"> 
    <UseDebugLibraries>false</UseDebugLibraries> 
    </PropertyGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 
    <ImportGroup Label="ExtensionSettings" /> 
    <ImportGroup Label="Shared" /> 
    <ImportGroup Label="PropertySheets" /> 
    <PropertyGroup Label="UserMacros" /> 
    <ItemGroup> 
    <ClCompile Include="@[email protected]" /> 
    </ItemGroup> 
    <ItemGroup> 
    </ItemGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 
    <ImportGroup Label="ExtensionTargets" /> 
</Project> 

을 그리고

이것은 당신의 CMake에 기존 .vcproj 파일을 포함 할 것 같은 솔루션을 생성 다음을 사용하여 새 add_linux_executable() 명령을 만드십시오.

,210
cmake_minimum_required(VERSION 2.8) 

project(ConfigureVCXProjForLinux) 

function(add_linux_executable _target) 
    if (CMAKE_GENERATOR MATCHES "Visual Studio ([0-9]*)") 
     foreach(_source IN LISTS ARGN) 
      get_filename_component(_source_abs "${_source}" ABSOLUTE) 
      file(TO_NATIVE_PATH "${_source_abs}" _source_native) 
      list(APPEND _sources "${_source_native}") 
     endforeach() 
     file(TO_NATIVE_PATH "${CMAKE_CURRENT_LIST_FILE}" _list_file_native) 
     list(APPEND _sources "${_list_file_native}") 

     string(
      UUID _guid 
      NAMESPACE "2e4779e9-c831-47b0-b138-3745b2ed6ba9" 
      NAME ${_target} 
      TYPE SHA1 
      UPPER 
     ) 

     configure_file(
      "LinuxTemplate.vcxproj.in" 
      "${CMAKE_CURRENT_BINARY_DIR}/${_target}.vcxproj" 
      @ONLY 
     ) 

     include_external_msproject(
      ${_target} 
      "${CMAKE_CURRENT_BINARY_DIR}/${_target}.vcxproj" 
      TYPE "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" 
      GUID "${_guid}" 
     ) 
    endif() 
endfunction() 

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

    int main() 
    { 
     std::cout << "Hello Linux !" << std::endl; 
    } 
]=]) 
add_linux_executable(${PROJECT_NAME} "main.cpp") 

참고 템플릿 교체 : 당신이`준 적 소스 파일`add_linux_executable (대한 프로젝트 RootNamespace

  • @[email protected]을위한 비주얼 스튜디오 버전 번호
  • @[email protected]에 대한

    선택한 컴파일 옵션에 따라 하나의 템플릿이 필요합니다. 그러나 템플리트를 사용하면이 접근 방식이 다소 유연 해집니다.

  • +0

    'include_external_msproject()는 어떻게 개념적으로 작동합니까? – Felix

    +0

    @Felix 예를 추가했습니다. 하지만 include_external_msproject()가 기존 VS 프로젝트 파일을 포함해야하기 때문에 실제로 도움이되지 않을 수 있음을 인정해야합니다. – Florian

    +0

    @Felix 더 구체적으로 말하면 : 내 프로젝트에는 프로젝트의 Windows 버전을 빌드하는 CMake 생성 Visual Studio 솔루션이 있습니다. 이러한 솔루션에는 크로스 컴파일 (CMake 다시 ​​사용)을위한 외부 스크립트를 호출하는 단일 Linux "외부"프로젝트가 포함되어 있으며 주로 Visual Studio에서 (원격) 디버깅에 사용됩니다. 그러나 저는 아직 Linux VS 프로젝트를 사용하지 않았습니다. 저는''VisualGDB' (https://visualgdb.com/)라는 외부 상용 도구를 사용하고 있습니다. – Florian

    관련 문제