From 195e17b997bd5ab697b999031bb2419d8d9e2f07 Mon Sep 17 00:00:00 2001 From: mingkuang Date: Wed, 17 May 2023 00:24:54 +0800 Subject: [PATCH] =?UTF-8?q?Fea=EF=BC=8CMacOS=E6=B7=BB=E5=8A=A0=E4=BA=A4?= =?UTF-8?q?=E5=8F=89=E7=BC=96=E8=AF=91=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 72 +++++++++++-------- Samples/ReadMe.md | 69 ++++++------------ .../Platforms/ARM64/Platform.Default.props | 2 +- .../1.0/Platforms/x64/Platform.Default.props | 2 +- .../1.0/Platforms/x86/Platform.Default.props | 2 +- .../YY_Cross_Clang_1_0/Toolset.props | 3 +- .../Platforms/YY_Cross_GCC_1_0/Toolset.props | 11 ++- .../YY_Cross_GCC_1_0/Toolset.targets | 2 +- .../Targets/OSX/YY.OSX.Cross.targets | 6 +- 9 files changed, 77 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index a1b763d..7139d40 100644 --- a/README.md +++ b/README.md @@ -50,23 +50,15 @@ export VCTargetsPath=/home/john/Desktop/VCTargets/v170/ ## 2.3. 编译vcxproj项目 我们也提供了示例项目,点击查看[Samples](Samples) -一般来说,Platform拥有以下几种可能: -* ARM -* ARM64 -* MIPS -* x64 -* x86(注意:对于Windows系统下的vcxproj来说叫Win32) - - 假设项目位置: `/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj`。并且编译 Release版的x86版本,那么可以输入如下命令: ``` -; Linux下编译 x86 -dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj' '-p:Configuration=Release;Platform=x86' - -; Linux下编译 x64 +; Linux、MacOS下编译 x64 dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj' '-p:Configuration=Release;Platform=x64' +; Linux、MacOS下编译小端 ARM64 +dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj' '-p:Configuration=Release;Platform=ARM64' + ; Windows下编译 x86。新人特别注意了,vcxproj里没有x86,只有Win32!!! msbuild "D:\ConsoleApplication2\ConsoleApplication2.vcxproj" -p:Configuration=Release;Platform=Win32 @@ -77,46 +69,66 @@ msbuild "D:\ConsoleApplication2\ConsoleApplication2.vcxproj" -p:Configuration=Re ``` ## 2.4. 全局支持的属性 ### 2.4.1. PlatformToolset 全局属性 -工具集,目前支持`YY_Cross_Clang_1_0`、`YY_Cross_GCC_1_0`。 +工具集,目前支持以下工具集: + +| 工具集 | 说明 +| ------------------ | ----------------- +| YY_Cross_GCC_1_0 | GCC工具集,Linux系统默认的工具集,MacOS暂时对YY_Cross_GCC_1_0支持不好。 +| YY_Cross_Clang_1_0 | CLang工具集,MacOS系统默认的工具集。 示例: ```xml - YY_Cross_GCC_1_0 + YY_Cross_GCC_1_0 ``` ### 2.4.2. Platform 全局属性 一般来说,Platform拥有以下几种可能: -* ARM -* ARM64 -* MIPS -* x64 -* x86 + +| 目标系统 | 支持的 Platform +| -------- | --------- +| Linux | x86、x64、ARM、ARM64、MIPS +| MacOS | x86、x64、ARM64 > 注意:Platform是在调用msbuild时传入的,一般不应该直接设置到工程。 +示例: +``` +dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj' '-p:Configuration=Release;Platform=x64' +``` + +> 特别提醒:特别是Linux系统。编译时,必须安装Platform对应的Triplet,否则将找不到g++而失败!比如对于一个x64的Ubuntu,使用GCC编译ARM64小端的Linux程序,则先安装 `g++-aarch64-linux-gun`,命令如下所示: +``` +sudo apt-get install g++-aarch64-linux-gun +``` + + ### 2.4.3. PlatformTriplet 全局属性 平台的Triplet值,比如说:i686-linux-gnu。一般无需设置,框架会根据Platform属性自动调整。 -其默认对照关系如下: +各个平台Platform的PlatformTriplet默认值如下表所示: -| Platform | Linux PlatformTriplet 默认值 | MacOS PlatformTriplet 默认值 | +| Platform | Linux | MacOS | | --------- | ---------------------------- | ---------------------------- | -| x86 | i686-linux-gnu | 尚未就绪 -| x64 | x86_64-linux-gnu | 尚未就绪 -| ARM | arm-linux-gnueabihf | 尚未就绪 -| ARM64 | aarch64-linux-gnu | 尚未就绪 +| x86 | i686-linux-gnu | i686-apple-darwin +| x64 | x86_64-linux-gnu | x86_64-apple-darwin +| ARM | arm-linux-gnueabihf | 不支持 +| ARM64 | aarch64-linux-gnu | aarch64-apple-darwin | MIPS | mips-linux-gnu | 不支持 -示例: +如果对默认的`PlatformTriplet`值不满意,可以考虑手工调整,示例: ```xml - - i686-linux-gnu + + x86_64-linux-gnu ``` ### 2.4.4. Sysroot 全局属性 -用于自定义库目录以及头文件位置。此路径会通过`--sysroot`传递给编译器以及链接器。 - +用于自定义库目录以及头文件位置。此路径会通过`--sysroot`传递给编译器以及链接器。示例: +```xml + + urs/opt/mysysroot + +``` # 3. 支持的属性以及元素参数映射情况 diff --git a/Samples/ReadMe.md b/Samples/ReadMe.md index 09063ff..62ad474 100644 --- a/Samples/ReadMe.md +++ b/Samples/ReadMe.md @@ -1,43 +1,20 @@ # MSBuildCppCrossToolset 示例项目 -## 使用方法 - -### 配置工具链 - +## 示例列表 首先,我们从 [GitHub Release](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/releases) 下载 MSBuildCppCrossToolset 并解压。 -假设最终解压目录是 `/home/mouri/Workspace/MSBuildCppCrossToolsetRelease/`。我们执行下面这条命令: - -``` -export VCTargetsPath=/home/mouri/Workspace/MSBuildCppCrossToolsetRelease/VCTargets/v170/ -``` - -### 编译项目 -一般来说,Platform拥有以下几种可能: - -| Platform | Linux PlatformTriplet 默认值 | MacOS PlatformTriplet 默认值 | 备注 -| --------- | ---------------------------- | --------------------- | --- -| x86 | i686-linux-gnu | 尚未就绪 | (注意:对于Windows系统下的vcxproj来说叫Win32) -| x64 | x86_64-linux-gnu | 尚未就绪 -| ARM | arm-linux-gnueabihf | 尚未就绪 -| ARM64 | aarch64-linux-gnu | 尚未就绪 -| MIPS | mips-linux-gnu | 不支持 +假设最终解压目录是:`/home/mouri/Workspace/MSBuildCppCrossToolset/`。 -> 温馨提示:Windows下Platform搞不懂x86还是Win32的可以先尝试Win32,如果报错那么尝试一下x86。 - -如果对默认的PlatformTriplet不满意,可以在Configuration区域覆盖PlatformTriplet属性实现自定义。Configuration区域亦可自定义Sysroot属性。 - - -交叉编译时,必须安装对应的Triplet,比如对于一个x64的Ubuntu,使用GCC编译ARM64小端的Linux程序,则先安装`g++-aarch64-linux-gun`。 +### [HelloWorld----C++](HelloWorld----C++/HelloWorldApplication.vcxproj) +一个简单的向控制台输出一段文本的应用,支持Windows、Linux以及MacOS。 +* 假设项目位置为: `/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples`。 +* MSBuildCppCrossToolset二进制产物解压到: `/home/mouri/Workspace/MSBuildCppCrossToolset/`。 ``` -sudo apt-get install g++-aarch64-linux-gun -``` - -; 假设项目位置为 `/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples`。并且编译一些 Release,那么可以输入如下命令: +; 设置 MSBuildCppCrossToolset 目录 +export VCTargetsPath=/home/mouri/Workspace/MSBuildCppCrossToolset/VCTargets/v170/ -``` -; Linux、MacOS下编译 x86 +; Linux下编译 x86 dotnet msbuild '/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples/HelloWorld----C++/HelloWorldApplication.vcxproj' '-p:Configuration=Release;Platform=x86' ; Linux、MacOS下编译 x64 @@ -48,26 +25,20 @@ dotnet msbuild '/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples/He ``` -我们也可以在Windows平台编译`HelloWorldApplication.vcxproj`,命令如下: -``` -; Windows下编译 x86,注意它叫 Win32! -msbuild "D:\MSBuildCppCrossToolsetWorkspace\Samples\HelloWorld----C++\HelloWorldApplication.vcxproj" -p:Configuration=Release;Platform=Win32 - -; Windows下编译 x64 -msbuild "D:\MSBuildCppCrossToolsetWorkspace\Samples\HelloWorld----C++\HelloWorldApplication.vcxproj" -p:Configuration=Release;Platform=x64 -; Windows下编译 ARM64 -msbuild "D:\MSBuildCppCrossToolsetWorkspace\Samples\HelloWorld----C++\HelloWorldApplication.vcxproj" -p:Configuration=Release;Platform=ARM64 +### [HelloWorld----ObjectC++](HelloWorld----ObjectC++/HelloWorldApplication.vcxproj) +使用`ObjectC++`输出一段文本的应用,注意这个示例仅支持MacOS。 +* 假设项目位置为: `/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples/`。 +* MSBuildCppCrossToolset二进制产物解压到: `/home/mouri/Workspace/MSBuildCppCrossToolset/`。 ``` +; 设置 MSBuildCppCrossToolset 目录 +export VCTargetsPath=/home/mouri/Workspace/MSBuildCppCrossToolset/VCTargets/v170/ -## 示例列表 - -### [HelloWorld----C++](HelloWorld----C++/HelloWorldApplication.vcxproj) - -一个简单的向控制台输出一段文本的应用,支持Windows、Linux以及MacOS。 +; MacOS下编译 x64 +dotnet msbuild '/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples/HelloWorld----ObjectC++/HelloWorldApplication.vcxproj' '-p:Configuration=Release;Platform=x64' +; MacOS下编译 ARM64 +dotnet msbuild '/home/mouri/Workspace/MSBuildCppCrossToolsetWorkspace/Samples/HelloWorld----ObjectC++/HelloWorldApplication.vcxproj' '-p:Configuration=Release;Platform=ARM64' -### [HelloWorld----ObjectC++](HelloWorld----ObjectC++/HelloWorldApplication.vcxproj) - -使用`ObjectC++`输出一段文本的应用,注意这个示例仅支持MacOS。 +``` diff --git a/VCTargets/v170/Application Type/OSX/1.0/Platforms/ARM64/Platform.Default.props b/VCTargets/v170/Application Type/OSX/1.0/Platforms/ARM64/Platform.Default.props index b587d25..6eaf6c8 100644 --- a/VCTargets/v170/Application Type/OSX/1.0/Platforms/ARM64/Platform.Default.props +++ b/VCTargets/v170/Application Type/OSX/1.0/Platforms/ARM64/Platform.Default.props @@ -20,7 +20,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. ARM64 ARM64 armv7 - aarch64-linux-gnu + aarch64-apple-darwin diff --git a/VCTargets/v170/Application Type/OSX/1.0/Platforms/x64/Platform.Default.props b/VCTargets/v170/Application Type/OSX/1.0/Platforms/x64/Platform.Default.props index 2b2fa06..56b61d2 100644 --- a/VCTargets/v170/Application Type/OSX/1.0/Platforms/x64/Platform.Default.props +++ b/VCTargets/v170/Application Type/OSX/1.0/Platforms/x64/Platform.Default.props @@ -21,7 +21,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. x64 x86_64 Disabled - x86_64-linux-gnu + x86_64-apple-darwin diff --git a/VCTargets/v170/Application Type/OSX/1.0/Platforms/x86/Platform.Default.props b/VCTargets/v170/Application Type/OSX/1.0/Platforms/x86/Platform.Default.props index ef27a7a..be82258 100644 --- a/VCTargets/v170/Application Type/OSX/1.0/Platforms/x86/Platform.Default.props +++ b/VCTargets/v170/Application Type/OSX/1.0/Platforms/x86/Platform.Default.props @@ -21,7 +21,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. x86 i386 Disabled - i686-linux-gnu + i686-apple-darwin diff --git a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_Clang_1_0/Toolset.props b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_Clang_1_0/Toolset.props index c920c71..fceb5f9 100644 --- a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_Clang_1_0/Toolset.props +++ b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_Clang_1_0/Toolset.props @@ -16,8 +16,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. - - + $(PlatformTriplet) clang++ clang++ clang++ diff --git a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.props b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.props index e59ad2a..ba84562 100644 --- a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.props +++ b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.props @@ -13,16 +13,15 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + - g++ - g++ - g++ - g++ - ar + $(PlatformTriplet)-g++ + $(PlatformTriplet)-g++ + $(PlatformTriplet)-g++ + $(PlatformTriplet)-ar gdbserver gdb diff --git a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.targets b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.targets index 2bbdf75..282ab03 100644 --- a/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.targets +++ b/YY.Build.Cross.Tasks/Targets/OSX/Platforms/YY_Cross_GCC_1_0/Toolset.targets @@ -33,7 +33,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. - + diff --git a/YY.Build.Cross.Tasks/Targets/OSX/YY.OSX.Cross.targets b/YY.Build.Cross.Tasks/Targets/OSX/YY.OSX.Cross.targets index fd73936..0b579a6 100644 --- a/YY.Build.Cross.Tasks/Targets/OSX/YY.OSX.Cross.targets +++ b/YY.Build.Cross.Tasks/Targets/OSX/YY.OSX.Cross.targets @@ -76,6 +76,8 @@ Copyright (C) Microsoft Corporation. All rights reserved. CompileAsC true Fast + $(Sysroot) + $(ClangTarget) @@ -166,6 +168,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. ObjCAutomaticRefCountingExceptionHandlingSafe="%(ClCompile.ObjCAutomaticRefCountingExceptionHandlingSafe)" ObjCExceptionHandling="%(ClCompile.ObjCExceptionHandling)" Sysroot="%(ClCompile.Sysroot)" + TargetArch="%(ClCompile.TargetArch)" TrackerLogDirectory="$(TLogLocation)" TLogReadFiles="$(TLogLocation)\compile.read.1.tlog" TLogWriteFiles="$(TLogLocation)\compile.write.1.tlog" @@ -212,7 +215,8 @@ Copyright (C) Microsoft Corporation. All rights reserved. BuildingInIde="%(Link.BuildingInIde)" EnableASAN="%(Link.EnableASAN)" UseOfStl="%(Link.UseOfStl)" - Sysroot="%(ClCompile.Sysroot)" + Sysroot="$(Sysroot)" + TargetArch="$(ClangTarget)" Frameworks="%(Link.Frameworks)" TrackerLogDirectory="$(TLogLocation)" TLogReadFiles="$(TLogLocation)\link.read.1.tlog"