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]
에 대한
선택한 컴파일 옵션에 따라 하나의 템플릿이 필요합니다. 그러나 템플리트를 사용하면이 접근 방식이 다소 유연 해집니다.
WSL이란 무엇입니까? MSVC 컴파일러를 사용하여 Windows 바이너리를 빌드하는 VS 솔루션을 생성해야하는 경우에는 cmake-gui를 사용하면됩니다. 나는 적당한 대답을 할 수 있었지만, 나는 더 많은 정보가 필요하다. – dragn
WSL은 Windows 용 Linux 바이너리를 실행할 수있는 Linux 용 새 Windows 하위 시스템입니다. 또한 ssh를 실행 한 다음 크로스 플랫폼 작업 부하를 통해 Windows의 VS에서 대상을 지정할 수 있습니다. 그러므로 내 질문. – Felix