Skip to content

Commit

Permalink
Switch project to CMake generation
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpup committed Jan 13, 2024
1 parent 9e19078 commit 4a8e237
Show file tree
Hide file tree
Showing 51 changed files with 184 additions and 83 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,32 @@ jobs:
variables:
runs-on: windows-latest
outputs:
version_suffix: ${{ steps.get_version_suffix.outputs.suffix }}
build_number: ${{ steps.get_build_num.outputs.build_number }}
steps:
- name: Generating version suffix
- name: Generating build number
uses: actions/github-script@v7
id: get_version_suffix
id: get_build_num
with:
script: |
core.setOutput('suffix', "${{ github.run_id }}".substr(-4, 4));
core.setOutput('build_number', "${{ github.run_id }}".substr(-4, 4));
build:
needs: [variables]
runs-on: windows-latest
env:
solution_path: Dota2GSI\Dota2GSI.sln
build_path: Dota2GSI\Dota2GSI\bin\Release\net8.0\
solution_path: build\Dota2GSI.sln
build_path: build\binaries\Release\
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Generate project
run: cmake -B build/ -A x64 -D BUILD_NUMBER=${{ needs.variables.outputs.build_number }} .
- name: Restore dependencies
run: dotnet restore $env:solution_path
- name: Build
run: dotnet build $env:solution_path --no-restore -c Release -p:VersionSuffix=.${{ needs.variables.outputs.version_suffix }}
run: dotnet build $env:solution_path --no-restore -c Release
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,18 @@ Dota2GSI/nuget.exe
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
*.nuget.targets

# Cmake files
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build/
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.26)

SET(REPOSITORY_URL "https://github.com/antonpup/Dota2GSI")

set(CMAKE_SUPPRESS_REGENERATION true)

PROJECT(Dota2GSI LANGUAGES CSharp CXX)

# Set global .NET Framework version.
SET(CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION "8.0")

# Set the C# language version for all projects.
SET(CMAKE_CSharp_FLAGS "/langversion:6")

# Explicitly set the `PlatformTarget` for C# projects, since AnyCPU can result in
# System.BadImageFormatException throws, when trying to load C++/CLI assemblies.
IF(CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
SET(CMAKE_CSharp_FLAGS "/platform:x64")
ELSEIF(CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
SET(CMAKE_CSharp_FLAGS "/platform:x86")
ELSE()
MESSAGE(WARNING "Generator platform is set to '${CMAKE_GENERATOR_PLATFORM}', which is not supported by managed projects. Defaulting to 'AnyCPU'...")
SET(CMAKE_CSharp_FLAGS "/platform:AnyCPU")
ENDIF()

# Define runtime intermediate build directory, so that debugging the Visual Studio solution works as expected.
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/binaries/")

# Set export directory for CMake config.
SET(CMAKE_INSTALL_BINARY_DIR "bin/")
SET(CMAKE_INSTALL_LIBRARY_DIR "bin/")
SET(CMAKE_INSTALL_INCLUDE_DIR "include/")
SET(CMAKE_INSTALL_EXPORT_DIR "cmake/")

# Include sub-projects.
ADD_SUBDIRECTORY(Dota2GSI)

set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Dota2GSI)
122 changes: 122 additions & 0 deletions Dota2GSI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Setup project.
SET(PRODUCT Dota2GSI)
SET(PRODUCT_NAME "${PRODUCT}")
SET(PRODUCT_VERSION 2.0.0)
SET(PRODUCT_DESCRIPTION "A C# library to interface the Game State Integration found in Dota 2.")
SET(PRODUCT_AUTHORS "Anton Pupkov")
SET(PRODUCT_COPYRIGHT "Copyright© 2024")

if(DEFINED BUILD_NUMBER)
SET(PRODUCT_VERSION "${PRODUCT_VERSION}.${BUILD_NUMBER}")
endif()

PROJECT(${PRODUCT} VERSION ${PRODUCT_VERSION} LANGUAGES CSharp)

# Setup project to use C# utilities.
INCLUDE(CSharpUtilities)

SET(SOURCES
GameState.cs
GameStateListener.cs
Nodes/Roshan.cs
Nodes/HeroProvider/HeroDetails.cs
Nodes/CouriersProvider/Courier.cs
Nodes/MinimapProvider/MinimapElement.cs
Nodes/Helpers/Vector2D.cs
Nodes/Helpers/FullTeamDetails.cs
Nodes/Helpers/FullPlayerDetails.cs
Nodes/RoshanProvider/ItemsDrop.cs
Nodes/League.cs
Nodes/LeagueProvider/Stream.cs
Nodes/Wearables.cs
Nodes/WearablesProvider/WearableItem.cs
Nodes/WearablesProvider/PlayerWearables.cs
Nodes/NeutralItemsProvider/NeutralTierInfo.cs
Nodes/NeutralItems.cs
Nodes/NeutralItemsProvider/TeamNeutralItems.cs
Nodes/NeutralItemsProvider/NeutralItem.cs
Nodes/Minimap.cs
Nodes/Hero.cs
Nodes/LeagueProvider/SelectionPriority.cs
Nodes/LeagueProvider/LeagueTeam.cs
Nodes/Items.cs
Nodes/ItemsProvider/Item.cs
Nodes/ItemsProvider/ItemDetails.cs
Nodes/Events.cs
Nodes/EventsProvider/Event.cs
Nodes/Draft.cs
Nodes/DraftProvider/DraftDetails.cs
Nodes/Couriers.cs
Nodes/CouriersProvider/CourierItem.cs
Nodes/Buildings.cs
Nodes/BuildingsProvider/BuildingLayout.cs
Nodes/BuildingsProvider/Building.cs
Nodes/Abilities.cs
Nodes/AbilitiesProvider/Ability.cs
Nodes/AbilitiesProvider/AbilityDetails.cs
Nodes/Player.cs
Nodes/PlayerProvider/PlayerDetails.cs
Nodes/Node.cs
Nodes/Provider.cs
Nodes/Map.cs
Nodes/Auth.cs
)

SET(README "${CMAKE_SOURCE_DIR}/README.md")

# Add shared library project.
ADD_LIBRARY(${PROJECT_NAME} SHARED
${README}
${SOURCES}
)

# Define dependencies.
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
PUBLIC CommonLib
)

SET(NET_REFERENCES
)

SET(NUGET_PACKAGES
"Microsoft.CSharp_4.7.0"
"System.Data.DataSetExtensions_4.5.0"
"Newtonsoft.Json_13.0.3"
)

# Set .Net
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
DOTNET_SDK "Microsoft.NET.Sdk"
DOTNET_TARGET_FRAMEWORK "net8.0"
VS_DOTNET_REFERENCES "${NET_REFERENCES}"
VS_GLOBAL_ROOTNAMESPACE ${PROJECT_NAME}
VS_PACKAGE_REFERENCES "${NUGET_PACKAGES}"
)

# Set readme file
SET_SOURCE_FILES_PROPERTIES(${README} PROPERTIES
VS_CSHARP_Pack "True"
VS_CSHARP_PackagePath "\\")

# Set project configuration
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VS_GLOBAL_GenerateAssemblyInfo "True"
VS_GLOBAL_GenerateDocumentationFile "True"
VS_GLOBAL_GeneratePackageOnBuild "True"
VS_GLOBAL_TreatWarningsAsErrors "True"
VS_GLOBAL_PackageProjectUrl ${REPOSITORY_URL}
VS_GLOBAL_RepositoryUrl ${REPOSITORY_URL}
VS_GLOBAL_PackageReadmeFile "README.md"
)

# Set Assembly information
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VS_GLOBAL_Authors "${PRODUCT_AUTHORS}"
VS_GLOBAL_Version "${PRODUCT_VERSION}"
VS_GLOBAL_Description "${PRODUCT_DESCRIPTION}"
VS_GLOBAL_Product "${PRODUCT_NAME}"
VS_GLOBAL_Copyright "${PRODUCT_COPYRIGHT}"
)

# Export config.
EXPORT(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}Config.cmake)
22 changes: 0 additions & 22 deletions Dota2GSI/Dota2GSI.sln

This file was deleted.

40 changes: 0 additions & 40 deletions Dota2GSI/Dota2GSI/Dota2GSI.csproj

This file was deleted.

13 changes: 0 additions & 13 deletions Dota2GSI/Dota2GSI/Properties/AssemblyInfo.cs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4a8e237

Please sign in to comment.