Skip to content

Commit

Permalink
Create new preset to be able to build GameServer only build
Browse files Browse the repository at this point in the history
Make it possible to build GameServer on platforms not having graphic dependencies easy available (e.g. rapberrypi).
  • Loading branch information
mwthinker committed Sep 15, 2024
1 parent bb77f2f commit f101f69
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 143 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
matrix:
include:
- os: windows-latest
preset: 'windows'
preset: windows
- os: ubuntu-latest
preset: 'unix'
preset: unix

steps:
- name: Check out repository code
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
files: lcov.info
if: runner.os == 'Linux'

# Release build
# Release build all
- name: Run CMake Release with manifest mode vcpkg
shell: bash
run: cmake --preset=${{ matrix.preset }} -B build_release -DTetrisEngine_Test=1 -DUSE_WIX_GENERATOR=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=1
Expand Down Expand Up @@ -119,6 +119,11 @@ jobs:
run: ./build_release/TetrisEngine/Release/TetrisEngine -p
if: runner.os == 'Windows'

# Release build network only (just to make sure it compiles)
- name: Run CMake Release with manifest mode vcpkg
shell: bash
run: cmake --preset=${{ matrix.preset }}-game-server-only -B build_release_server -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=1

# Create installer
- name: Run cpack
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/linux_build
/vcpkg_installed/
.vscode/
/build_server/
/linux_build_server/

#################
## Eclipse
Expand Down
154 changes: 43 additions & 111 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
cmake_minimum_required(VERSION 3.24)
project(MWetris
cmake_minimum_required(VERSION 3.29)
project(MWetrisProject
DESCRIPTION
"A C++ Tetris Game"
"A C++ Tetris Game project"
VERSION
${PROJECT_VERSION}
LANGUAGES
CXX
)

set(SOURCES
src/logger.cpp
src/logger.h
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
#set_property(GLOBAL PROPERTY USE_FOLDERS On)
#set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT MWetris)

ExternalFetchContent.cmake
CPack.cmake
vcpkg.json
)

if (MSVC)
configure_file(properties.rc ${CMAKE_CURRENT_BINARY_DIR}/properties.rc)
endif ()

set_property(GLOBAL PROPERTY USE_FOLDERS On)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT MWetris)

source_group(TREE
${CMAKE_CURRENT_SOURCE_DIR}
FILES
${SOURCES}
)
#source_group(TREE
# ${CMAKE_CURRENT_SOURCE_DIR}
# FILES
# ${SOURCES}
#)

option(GAME_SERVER_ONLY "Game Server only" OFF)
include(ExternalFetchContent.cmake)

find_package(argparse CONFIG REQUIRED)
find_package(Threads REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)

find_package(CppSdl2 REQUIRED)
find_package(Signal REQUIRED)
find_package(Calculator REQUIRED)

extract_git_hash(
${CMAKE_CURRENT_SOURCE_DIR}
GIT_HASH
Expand All @@ -64,15 +40,29 @@ message(STATUS "GIT_HASH: ${GIT_HASH} ${GIT_DATE}")
message(STATUS "CMAKE_PROJECT_VERSION: ${CMAKE_PROJECT_VERSION}")
message(STATUS "GUID: ${GUID}")

set(ExternalDependencies
CppSdl2
Calculator
ImGui
)
if (CppSdl2_Test)
if (GAME_SERVER_ONLY)
set(ExternalDependencies
Calculator
)
else ()
set(ExternalDependencies
CppSdl2
Calculator
ImGui
)
endif ()

# Copy data to build folder.
file(COPY ${MWetrisData_SOURCE_DIR}/package DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${MWetrisData_SOURCE_DIR}/images DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${MWetrisData_SOURCE_DIR}/fonts DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY data/. DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${SDL_GameControllerDB_SOURCE_DIR}/gamecontrollerdb.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if (CppSdl2_Test AND NOT GAME_SERVER_ONLY)
set(ExternalDependencieTests "${ExternalDependencieTests};CppSdl2_Test")
endif ()
if (CppSdl2_Example)
if (CppSdl2_Example AND NOT GAME_SERVER_ONLY)
set(ExternalDependencieTests "${ExternalDependencieTests};CppSdl2_Example")
endif ()
if (Calculator_Test)
Expand All @@ -82,6 +72,17 @@ if (Signal_Test)
set(ExternalDependencieTests "${ExternalDependencieTests};Signal_Test")
endif ()

add_subdirectory(Protocol)
add_subdirectory(Network_Lib)
add_subdirectory(GameServer)
add_subdirectory(TetrisEngine)

if (NOT GAME_SERVER_ONLY)
add_subdirectory(MWetris_Lib)
add_subdirectory(MWetris_Test)
add_subdirectory(MWetris)
endif ()

set_target_properties(
${ExternalDependencies}
${ExternalDependencieTests}
Expand All @@ -90,73 +91,4 @@ set_target_properties(
ExternalDependencies
)

add_subdirectory(TetrisEngine)
add_subdirectory(Protocol)
add_subdirectory(MWetris_Lib)
add_subdirectory(MWetris_Test)
add_subdirectory(GameServer)
add_subdirectory(Network_Lib)

# Copy data to build folder.
file(COPY ${MWetrisData_SOURCE_DIR}/package DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${MWetrisData_SOURCE_DIR}/images DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${MWetrisData_SOURCE_DIR}/fonts DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY data/. DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${SDL_GameControllerDB_SOURCE_DIR}/gamecontrollerdb.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

if (MSVC)
add_executable(MWetris
${SOURCES}
${MWetrisData_SOURCE_DIR}/package/mwetris_icon.rc
${CMAKE_CURRENT_BINARY_DIR}/properties.rc
)
else ()
add_executable(MWetris
${SOURCES}
)
endif ()

option(CODE_COVERAGE "Enable coverage reporting" OFF)

target_include_directories(MWetris
PRIVATE
src
)

if (MSVC)
target_compile_options(MWetris
PUBLIC
/W3 /WX /permissive-
/MP
)
else ()
target_compile_options(MWetris
PRIVATE
-Wall -pedantic -Wcast-align -Woverloaded-virtual -Wno-unused-parameter -Wno-sign-compare -Wno-unused-function
)
endif ()

target_link_libraries(MWetris
PRIVATE
argparse::argparse
fmt::fmt
MWetris_Lib
)

target_compile_definitions(MWetris
PRIVATE
GIT_VERSION="${GIT_HASH}"
GIT_DATE="${GIT_DATE}"
PROJECT_VERSION="${PROJECT_VERSION}"
VCPKG_HASH="${VCPKG_HASH}"
VCPKG_DATE="${VCPKG_DATE}"
)

set_target_properties(MWetris
PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)

include(${CMAKE_CURRENT_SOURCE_DIR}/CPack.cmake)
26 changes: 25 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@
"X_VCPKG_APPLOCAL_DEPS_INSTALL": {
"value": "true",
"type": "BOOL"
}
},
"VCPKG_MANIFEST_DIR": "${sourceDir}/Mwetris"
}
},
{
"name": "windows-game-server-only",
"inherits": "windows",
"cacheVariables": {
"VCPKG_MANIFEST_DIR": "${sourceDir}/GameServer",
"GAME_SERVER_ONLY": "ON"
}
},
{
Expand All @@ -57,6 +66,21 @@
"type": "inList",
"string": "${hostSystemName}",
"list": ["Linux", "Darwin"]
},
"cacheVariables": {
"X_VCPKG_APPLOCAL_DEPS_INSTALL": {
"value": "true",
"type": "BOOL"
},
"VCPKG_MANIFEST_DIR": "${sourceDir}/Mwetris"
}
},
{
"name": "unix-game-server-only",
"inherits": "unix",
"cacheVariables": {
"VCPKG_MANIFEST_DIR": "${sourceDir}/GameServer",
"GAME_SERVER_ONLY": "ON"
}
}
]
Expand Down
28 changes: 15 additions & 13 deletions ExternalFetchContent.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
include(FetchContent)
# Load external github projects
FetchContent_Declare(CppSdl2
GIT_REPOSITORY
https://github.com/mwthinker/CppSdl2.git
GIT_TAG
f2dabd127ac92b0c69d435940e716a8bfdec2656
OVERRIDE_FIND_PACKAGE
)
if (NOT GAME_SERVER_ONLY)
FetchContent_Declare(CppSdl2
GIT_REPOSITORY
https://github.com/mwthinker/CppSdl2.git
GIT_TAG
f2dabd127ac92b0c69d435940e716a8bfdec2656
OVERRIDE_FIND_PACKAGE
)
endif()

FetchContent_Declare(SDL_GameControllerDB
GIT_REPOSITORY
https://github.com/gabomdq/SDL_GameControllerDB.git
GIT_TAG
99c8ec90ac72eac926aab3a6ce8488d50f0226e0
)
FetchContent_MakeAvailable(SDL_GameControllerDB)
FetchContent_GetProperties(SDL_GameControllerDB
)
FetchContent_MakeAvailable(SDL_GameControllerDB)
FetchContent_GetProperties(SDL_GameControllerDB
SOURCE_DIR
SDL_GameControllerDB_SOURCE_DIR
)
Expand All @@ -25,9 +27,9 @@ FetchContent_Declare(IconFontCppHeaders
https://github.com/juliettef/IconFontCppHeaders.git
GIT_TAG
173c9b99be9a9980d2eeaf4b627d8c14b344bc68
)
FetchContent_Populate(IconFontCppHeaders)
FetchContent_GetProperties(IconFontCppHeaders
)
FetchContent_Populate(IconFontCppHeaders)
FetchContent_GetProperties(IconFontCppHeaders
SOURCE_DIR
IconFontCppHeaders_SOURCE_DIR
)
Expand Down
2 changes: 2 additions & 0 deletions GameServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ find_package(spdlog CONFIG REQUIRED)

add_executable(GameServer
src/main.cpp

vcpkg.json
)

target_link_libraries(GameServer
Expand Down
15 changes: 15 additions & 0 deletions GameServer/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "mwetris",
"version-string": "0.3.0",
"port-version": 0,
"homepage": "https://github.com/mwthinker/MWetris",
"description": "Simple Tetris like game",
"license": "MIT",
"dependencies": [
"spdlog",
"fmt",
"protobuf",
"asio",
"argparse"
]
}
Loading

0 comments on commit f101f69

Please sign in to comment.