Browse Source

Merge pull request #6 from c6burns/c6burns_dev

autodetect VS version / output unity plugins
Coburn 6 years ago
parent
commit
9d237ed4cd
4 changed files with 63 additions and 15 deletions
  1. 2 0
      .gitignore
  2. 21 5
      CMakeLists.txt
  3. 38 9
      MSBuild/CMake/CMake.Build.targets
  4. 2 1
      MSBuild/ENetTests/ENetTests.csproj

+ 2 - 0
.gitignore

@@ -6,3 +6,5 @@ build*
 **/obj
 .vs
 Directory.Build.rsp
+Unity
+

+ 21 - 5
CMakeLists.txt

@@ -20,11 +20,13 @@
 # SOFTWARE.
 #
 
+set(ENET_LIB_NAME enet)
 cmake_minimum_required(VERSION 3.1)
-project(enet LANGUAGES C)
+project(${ENET_LIB_NAME} LANGUAGES C)
 
 set(ENET_DEBUG OFF CACHE BOOL "Do debug things")
-
+set(ENET_PLUGIN_DIR_BASE "${CMAKE_CURRENT_SOURCE_DIR}/Unity/Plugins")
+set(ENET_PLUGIN_DIR_ARCH "x86_64")
 set(ENET_DEFINES -DENET_NO_PRAGMA_LINK -DENET_DLL)
 set(ENET_DEPS "")
 set(ENET_SRCDIR "Source/Native")
@@ -53,6 +55,20 @@ if(MSVC)
 endif()
 
 include_directories(${ENET_SRCDIR})
-add_library(enet SHARED ${ENET_SRCS})
-target_link_libraries(enet ${ENET_DEPS})
-target_compile_definitions(enet PRIVATE ${ENET_DEFINES})
+add_library(${ENET_LIB_NAME} SHARED ${ENET_SRCS})
+target_link_libraries(${ENET_LIB_NAME} ${ENET_DEPS})
+target_compile_definitions(${ENET_LIB_NAME} PRIVATE ${ENET_DEFINES})
+
+set(ENET_PLUGIN_DIR ${ENET_PLUGIN_DIR_BASE}/${ENET_PLUGIN_DIR_ARCH})
+set(ENET_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
+string(REPLACE ".dylib" ".bundle" ENET_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
+set(ENET_PLUGIN_NAME ${ENET_LIB_PREFIX}${ENET_LIB_NAME}${ENET_LIB_SUFFIX})
+
+file(MAKE_DIRECTORY ${ENET_PLUGIN_DIR})
+add_custom_command(
+    TARGET ${ENET_LIB_NAME}
+    POST_BUILD
+    COMMAND ${CMAKE_COMMAND} -E copy
+        $<TARGET_FILE:${ENET_LIB_NAME}>
+        ${ENET_PLUGIN_DIR}/${ENET_PLUGIN_NAME}
+)

+ 38 - 9
MSBuild/CMake/CMake.Build.targets

@@ -25,10 +25,11 @@ All key properties are overridable from CLI (-p:PropName=PropVal) or PropertyGro
 CMakeProjName - project name outputted to build log
 CMakeSourceDir - path to CMakeList.txt
 CMakeBinaryDir - path to drop all the outputs
-CMakeBuildType - Debug or Release (or RelWithDeb or any valid value of DCMAKE_BUILD_TYPE)
+CMakeBuildType - any valid value of DCMAKE_BUILD_TYPE (applies to both config and build for VS)
+CMakeConfigBuildType - any valid value of DCMAKE_BUILD_TYPE (for posix CLI)
 CMakeVSArch - force an arch for VS generators (eg. -AWin32)
+CMakeVSToolset = force an msvc platform toolset (eg. -Tv141)
 CMakeGenerator - override the CMake generator
-CMakeConfigBuildType - override the configuration build type (for non IDE systems that can switch)
 CMakeHelpLink - link to repo or other magical site when error occurs
 
 -->
@@ -41,19 +42,13 @@ CMakeHelpLink - link to repo or other magical site when error occurs
         <CMakeBuildType Condition="'$(CMakeBuildType)' == '' AND '$(Configuration)' == 'Debug'">Debug</CMakeBuildType>
         <CMakeBuildType Condition="'$(CMakeBuildType)' == '' AND '$(Configuration)' == 'Release'">Release</CMakeBuildType>
         <CMakeHelpLink Condition="'$(CMakeHelpLink)' == ''">https://github.com/SoftwareGuy/ENet-CSharp</CMakeHelpLink>
-
         <CMakeOpts Condition="'$(CMakeBuildType)' == 'Debug'">$(CMakeOpts) -DENET_DEBUG=ON</CMakeOpts>
     </PropertyGroup>
 
-    <PropertyGroup Condition="'$(OSPlatformWindows)' == 'true'">
-        <CMakeVSArch Condition="'$(CMakeVSArch)' == '' AND '$(Platform)' == 'x86'">-AWin32</CMakeVSArch>
-        <CMakeGenerator Condition="'$(CMakeVSArch)' == ''">-G"Visual Studio 16 2019" $(CMakeVSArch) $(CMakeVSToolset)</CMakeGenerator>
-    </PropertyGroup>
-
     <PropertyGroup Condition="'$(OSPlatformWindows)' != 'true'">
         <CMakeConfigBuildType Condition="'$(CMakeConfigBuildType)' == ''">-DCMAKE_BUILD_TYPE=$(CMakeBuildType)</CMakeConfigBuildType>
     </PropertyGroup>
-
+  
     <Target Name="CMakeBuildClean" BeforeTargets="Clean">
         <Message Text="CMake -- cleaning project: $(CMakeProjName)" Importance="high" />
         <RemoveDir Directories="$(CMakeBinaryDir)"/>
@@ -61,6 +56,40 @@ CMakeHelpLink - link to repo or other magical site when error occurs
         <OnError ExecuteTargets="CMakeCleanFailed" />
     </Target>
 
+    <Target Name="CMakeCheckVSVersion" BeforeTargets="Build;VSTest" Condition="'$(OSPlatformWindows)' == 'true'">
+        <Error Text="CMake -- Unidentified Visual Studio Version" Condition="'$(VisualStudioVersion)' == ''" />
+        <PropertyGroup>
+            <VisualStudioVersionMajor>$(VisualStudioVersion.Substring(0, 2))</VisualStudioVersionMajor>
+        </PropertyGroup>
+      
+        <Error Text="CMake -- Unsupported Visual Studio Version: $(VisualStudioVersion)" Condition="'$(VisualStudioVersionMajor)' != '15' AND '$(VisualStudioVersionMajor)' != '16'" />
+        <PropertyGroup Condition="'$(OSPlatformWindows)' == 'true'">
+            <VCToolsVersion Condition="'$(VCToolsVersion)' == '' AND '$(VisualStudioVersionMajor)' == '15'">14.1</VCToolsVersion>
+            <VCToolsVersion Condition="'$(VCToolsVersion)' == '' AND '$(VisualStudioVersionMajor)' == '16'">14.2</VCToolsVersion>
+            <VCToolsVersionMajor>$(VCToolsVersion.Substring(0, 2))</VCToolsVersionMajor>
+            <VCToolsVersionMinor>$(VCToolsVersion.Substring(3, 1))</VCToolsVersionMinor>
+            <CMakeVSYear Condition="'$(VisualStudioVersionMajor)' == '15'">2017</CMakeVSYear>
+            <CMakeVSYear Condition="'$(VisualStudioVersionMajor)' == '16'">2019</CMakeVSYear>
+            <CMakeVSGenVer>$(VisualStudioVersionMajor) $(CMakeVSYear)</CMakeVSGenVer>
+            <CMakeVSToolset Condition="'$(CMakeVSToolset)' == ''">-Tv$(VCToolsVersionMajor)$(VCToolsVersionMinor)</CMakeVSToolset>
+            <CMakeVSToolset Condition="'$(CMakeVSToolset)' != ''"> $(CMakeVSToolset)</CMakeVSToolset>
+            <CMakePlatform Condition="'$(CMakePlatform)' == ''">$(Platform)</CMakePlatform>
+            <CMakePlatform Condition="'$(CMakePlatform)' == 'AnyCPU'">x64</CMakePlatform>
+        </PropertyGroup>
+
+        <PropertyGroup Condition="'$(CMakeVSYear)' == '2017'">
+            <CMakeVSArch Condition="'$(CMakeVSArch)' == '' AND '$(CMakePlatform)' == 'x64'">Win64</CMakeVSArch>
+            <CMakeVSArch Condition="'$(CMakeVSArch)' != ''"> $(CMakeVSArch)</CMakeVSArch>
+            <CMakeGenerator Condition="'$(CMakeGenerator)' == ''">-G"Visual Studio $(CMakeVSGenVer)$(CMakeVSArch)"$(CMakeVSToolset)</CMakeGenerator>
+        </PropertyGroup>
+
+        <PropertyGroup Condition="'$(CMakeVSYear)' == '2019'">
+            <CMakeVSArch Condition="'$(CMakeVSArch)' == '' AND '$(CMakePlatform)' == 'x86'">-AWin32</CMakeVSArch>
+            <CMakeVSArch Condition="'$(CMakeVSArch)' != ''"> $(CMakeVSArch)</CMakeVSArch>
+            <CMakeGenerator Condition="'$(CMakeGenerator)' == ''">-G"Visual Studio $(CMakeVSGenVer)"$(CMakeVSArch)$(CMakeVSToolset)</CMakeGenerator>
+        </PropertyGroup>
+    </Target>
+
     <Target Name="CMakeConfigTarget" BeforeTargets="Build;VSTest">
         <Message Text="CMake -- configuring $(CMakeBuildType) $(Platform): $(CMakeProjName)" Importance="high" />
         <MakeDir Directories="$(CMakeBinaryDir)" />

+ 2 - 1
MSBuild/ENetTests/ENetTests.csproj

@@ -22,7 +22,8 @@ SOFTWARE.
 <Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <TargetFramework>netcoreapp2.2</TargetFramework>
+    <langversion>7.1</langversion>
     <IsPackable>false</IsPackable>
   </PropertyGroup>