CMake.Build.targets 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!--
  2. Copyright (c) 2019 Chris Burns <[email protected]>
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. CMake build driver
  19. All key properties are overridable from CLI (-p:PropName=PropVal) or PropertyGroup
  20. CMakeProjName - project name outputted to build log
  21. CMakeSourceDir - path to CMakeList.txt
  22. CMakeBinaryDir - path to drop all the outputs
  23. CMakeBuildType - any valid value of DCMAKE_BUILD_TYPE (applies to both config and build for VS)
  24. CMakeConfigBuildType - any valid value of DCMAKE_BUILD_TYPE (for posix CLI)
  25. CMakeVSArch - force an arch for VS generators (eg. -AWin32)
  26. CMakeVSToolset = force an msvc platform toolset (eg. -Tv141)
  27. CMakeGenerator - override the CMake generator
  28. CMakeHelpLink - link to repo or other magical site when error occurs
  29. -->
  30. <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  31. <PropertyGroup>
  32. <CMakeProjName Condition="'$(CMakeProjName)' == ''">enet</CMakeProjName>
  33. <CMakeSourceDir Condition="'$(CMakeSourceDir)' == ''">$(SlnDir)</CMakeSourceDir>
  34. <CMakeBinaryDir Condition="'$(CMakeBinaryDir)' == ''">$(SlnDir)build_cmake_enet</CMakeBinaryDir>
  35. <CMakeBuildType Condition="'$(CMakeBuildType)' == '' AND '$(Configuration)' == 'Debug'">Debug</CMakeBuildType>
  36. <CMakeBuildType Condition="'$(CMakeBuildType)' == '' AND '$(Configuration)' == 'Release'">Release</CMakeBuildType>
  37. <CMakeHelpLink Condition="'$(CMakeHelpLink)' == ''">https://github.com/SoftwareGuy/ENet-CSharp</CMakeHelpLink>
  38. <CMakeOpts Condition="'$(CMakeBuildType)' == 'Debug'">$(CMakeOpts) -DENET_DEBUG=ON</CMakeOpts>
  39. </PropertyGroup>
  40. <PropertyGroup Condition="'$(OSPlatformWindows)' != 'true'">
  41. <CMakeConfigBuildType Condition="'$(CMakeConfigBuildType)' == ''">-DCMAKE_BUILD_TYPE=$(CMakeBuildType)</CMakeConfigBuildType>
  42. </PropertyGroup>
  43. <Target Name="CMakeBuildClean" BeforeTargets="Clean">
  44. <Message Text="CMake -- cleaning project: $(CMakeProjName)" Importance="high" />
  45. <RemoveDir Directories="$(CMakeBinaryDir)"/>
  46. <MakeDir Directories="$(CMakeBinaryDir)"/>
  47. <OnError ExecuteTargets="CMakeCleanFailed" />
  48. </Target>
  49. <Target Name="CMakeCheckVSVersion" BeforeTargets="Build;VSTest" Condition="'$(OSPlatformWindows)' == 'true'">
  50. <Error Text="CMake -- Unidentified Visual Studio Version" Condition="'$(VisualStudioVersion)' == ''" />
  51. <PropertyGroup>
  52. <VisualStudioVersionMajor>$(VisualStudioVersion.Substring(0, 2))</VisualStudioVersionMajor>
  53. </PropertyGroup>
  54. <Error Text="CMake -- Unsupported Visual Studio Version: $(VisualStudioVersion)" Condition="'$(VisualStudioVersionMajor)' != '15' AND '$(VisualStudioVersionMajor)' != '16'" />
  55. <PropertyGroup Condition="'$(OSPlatformWindows)' == 'true'">
  56. <VCToolsVersion Condition="'$(VCToolsVersion)' == '' AND '$(VisualStudioVersionMajor)' == '15'">14.1</VCToolsVersion>
  57. <VCToolsVersion Condition="'$(VCToolsVersion)' == '' AND '$(VisualStudioVersionMajor)' == '16'">14.2</VCToolsVersion>
  58. <VCToolsVersionMajor>$(VCToolsVersion.Substring(0, 2))</VCToolsVersionMajor>
  59. <VCToolsVersionMinor>$(VCToolsVersion.Substring(3, 1))</VCToolsVersionMinor>
  60. <CMakeVSYear Condition="'$(VisualStudioVersionMajor)' == '15'">2017</CMakeVSYear>
  61. <CMakeVSYear Condition="'$(VisualStudioVersionMajor)' == '16'">2019</CMakeVSYear>
  62. <CMakeVSGenVer>$(VisualStudioVersionMajor) $(CMakeVSYear)</CMakeVSGenVer>
  63. <CMakeVSToolset Condition="'$(CMakeVSToolset)' == ''">-Tv$(VCToolsVersionMajor)$(VCToolsVersionMinor)</CMakeVSToolset>
  64. <CMakeVSToolset Condition="'$(CMakeVSToolset)' != ''"> $(CMakeVSToolset)</CMakeVSToolset>
  65. <CMakePlatform Condition="'$(CMakePlatform)' == ''">$(Platform)</CMakePlatform>
  66. <CMakePlatform Condition="'$(CMakePlatform)' == 'AnyCPU'">x64</CMakePlatform>
  67. </PropertyGroup>
  68. <PropertyGroup Condition="'$(CMakeVSYear)' == '2017'">
  69. <CMakeVSArch Condition="'$(CMakeVSArch)' == '' AND '$(CMakePlatform)' == 'x64'">Win64</CMakeVSArch>
  70. <CMakeVSArch Condition="'$(CMakeVSArch)' != ''"> $(CMakeVSArch)</CMakeVSArch>
  71. <CMakeGenerator Condition="'$(CMakeGenerator)' == ''">-G"Visual Studio $(CMakeVSGenVer)$(CMakeVSArch)"$(CMakeVSToolset)</CMakeGenerator>
  72. </PropertyGroup>
  73. <PropertyGroup Condition="'$(CMakeVSYear)' == '2019'">
  74. <CMakeVSArch Condition="'$(CMakeVSArch)' == '' AND '$(CMakePlatform)' == 'x86'">-AWin32</CMakeVSArch>
  75. <CMakeVSArch Condition="'$(CMakeVSArch)' != ''"> $(CMakeVSArch)</CMakeVSArch>
  76. <CMakeGenerator Condition="'$(CMakeGenerator)' == ''">-G"Visual Studio $(CMakeVSGenVer)"$(CMakeVSArch)$(CMakeVSToolset)</CMakeGenerator>
  77. </PropertyGroup>
  78. </Target>
  79. <Target Name="CMakeConfigTarget" BeforeTargets="Build;VSTest">
  80. <Message Text="CMake -- configuring $(CMakeBuildType) $(Platform): $(CMakeProjName)" Importance="high" />
  81. <MakeDir Directories="$(CMakeBinaryDir)" />
  82. <Message Text="CMake -- cmake $(CMakeGenerator) $(CMakeConfigBuildType) $(CMakeOpts) $(CMakeSourceDir)" Importance="high" />
  83. <Exec Command="cmake $(CMakeGenerator) $(CMakeConfigBuildType) $(CMakeOpts) $(CMakeSourceDir)" WorkingDirectory="$(CMakeBinaryDir)" StandardOutputImportance="low" StandardErrorImportance="high" />
  84. <OnError ExecuteTargets="CMakeBuildFailed" />
  85. </Target>
  86. <Target Name="CMakeBuildTarget" BeforeTargets="Build;VSTest">
  87. <Message Text="CMake -- building $(CMakeBuildType) $(Platform): $(CMakeProjName)" Importance="high" />
  88. <Message Text="CMake -- cmake --build . --config $(CMakeBuildType)" Importance="high" />
  89. <Exec Command="cmake --build . --config $(CMakeBuildType)" WorkingDirectory="$(CMakeBinaryDir)" StandardOutputImportance="low" StandardErrorImportance="high" />
  90. <OnError ExecuteTargets="CMakeBuildFailed" />
  91. </Target>
  92. <Target Name="CMakeBuildSuccess" BeforeTargets="Build;VSTest">
  93. <Message Text="CMake -- build succeeded: $(CMakeProjName)" Importance="high" />
  94. </Target>
  95. <Target Name="CMakeCleanFailed">
  96. <Warning Text="CMake -- the most common cause of CMake clean errors is file locking (eg. windows console in the build dir)" />
  97. <Warning Text="CMake -- please unlock or reboot and try cleaning again before filing an issue on github:" />
  98. <Warning Text="CMake -- https://github.com/SoftwareGuy/ENet-CSharp" />
  99. <Error Text="CMake -- build failed: $(CMakeProjName)" />
  100. </Target>
  101. <Target Name="CMakeBuildFailed">
  102. <Warning Text="CMake -- the most common cause of CMake build errors is changing config without cleaning" />
  103. <Warning Text="CMake -- please try cleaning and building again before filing an issue on github:" />
  104. <Warning Text="CMake -- https://github.com/SoftwareGuy/ENet-CSharp" />
  105. <Error Text="CMake -- build failed: $(CMakeProjName)" />
  106. </Target>
  107. </Project>