Skip to content

Commit

Permalink
refactor(cmake): Re-order, simplify and comment all cmake
Browse files Browse the repository at this point in the history
refactor the game folder building
  • Loading branch information
Peralban committed Oct 2, 2024
1 parent 74ae31a commit ea2b6f2
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 88 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
cmake_minimum_required(VERSION 3.5)

# Project name
project(R-Type)

option(BUILD_TESTS "Build the tests" ON)
# Set a directory path in a CMake variable
set(GAME_DIR "${CMAKE_SOURCE_DIR}/Game")

#R-Type Game
add_subdirectory(R-TypeGame)
# Define a preprocessor macro globally for all targets
add_compile_definitions(GAME_ROOT="${GAME_DIR}")

#Graphic Library
add_subdirectory(GraphicLibrary)
# Option to build tests
option(BUILD_TESTS "Build the tests" ON)

#Engine
add_subdirectory(Engine)
# Add subdirectories for different components of the project
add_subdirectory(R-TypeGame) # R-Type Game
add_subdirectory(GraphicLibrary) # Graphic Library
add_subdirectory(Engine) # Engine

# tests
# Add subdirectory for tests if the option is enabled
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
2 changes: 2 additions & 0 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Add subdirectories for different components of the Engine
add_subdirectory(Client)
add_subdirectory(Server)
add_subdirectory(Shared)
79 changes: 41 additions & 38 deletions Engine/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

# Set the executable name
set(EXE r-type_client)

# Set the output directory for the executable
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game)

# Define source and include paths
set(EXE_SRC_PATH "Src")
set(EXE_INCLUDE_PATH "Include")

# Define component source files
set(COMPONENT_SRC_FILE
./Src/Components/ShaderComponent/ShaderPathComponent.cpp
${EXE_SRC_PATH}/Components/ShaderComponent/ShaderPathComponent.cpp
../Shared/Component/FontPathComponent.cpp
../Shared/Component/ObjPathComponent.cpp
../Shared/Component/TexturePathComponent.cpp
Expand All @@ -25,51 +34,55 @@ set(COMPONENT_SRC_FILE
../Shared/Component/SoundPitchComponent.cpp
../Shared/Component/SoundVolumeComponent.cpp
)

# Define system source files
set(SYSTEM_SRC_FILE
Src/Systems/DrawOBJ/DrawOBJSystem.cpp
${EXE_SRC_PATH}/Systems/DrawOBJ/DrawOBJSystem.cpp
)

set(COMPONENT_INCLUDE_DIR ./Include/Components/ShaderComponent)

set(CMAKE_CXX_STANDARD 20)

# Define the main source files for the executable
set(SRC_EXE
Src/main.cpp
Src/Application/Application.cpp
Src/ClientSceneManager/ClientSceneManager.cpp
Src/GraphicalLibrary/GetGraphicalLibrary.cpp

../Shared/SceneManager/ASceneManager.cpp
${COMPONENT_SRC_FILE}
${SYSTEM_SRC_FILE}
${EXE_SRC_PATH}/main.cpp
${EXE_SRC_PATH}/Application/Application.cpp
${EXE_SRC_PATH}/ClientSceneManager/ClientSceneManager.cpp
${EXE_SRC_PATH}/GraphicalLibrary/GetGraphicalLibrary.cpp
../Shared/SceneManager/ASceneManager.cpp
${COMPONENT_SRC_FILE}
${SYSTEM_SRC_FILE}
)

# Include directories for header files
include_directories(
Src/Network
Src/Application
Src/ClientSceneManager
Src/GraphicalLibrary
Src/Errors
Src/Systems
../Shared/GraphicalLoad
../Shared/Component
../Shared/Ecs/Src
../Shared/Interface
../Shared/SceneManager
../Shared/DLLoader
${COMPONENT_INCLUDE_DIR}
${EXE_SRC_PATH}/Network
${EXE_SRC_PATH}/Application
${EXE_SRC_PATH}/ClientSceneManager
${EXE_SRC_PATH}/GraphicalLibrary
${EXE_SRC_PATH}/Errors
${EXE_SRC_PATH}/Systems
../Shared/GraphicalLoad
../Shared/Component
../Shared/Ecs/Src
../Shared/Interface
../Shared/SceneManager
../Shared/DLLoader
${EXE_INCLUDE_PATH}/Components/ShaderComponent
)

add_subdirectory(Src/Network)
# Add subdirectory for network sources
add_subdirectory(${EXE_SRC_PATH}/Network)

# Add the executable target
add_executable(${EXE} ${SRC_EXE})

# Include directories for the executable target
target_include_directories(${EXE} PUBLIC ${EXE_INCLUDE_PATH})

# Find required packages
find_package(asio REQUIRED)
find_package(jsoncpp REQUIRED)
find_package(raylib REQUIRED)

# Link libraries to the executable target
target_link_libraries(
${EXE}
PRIVATE asio::asio
Expand All @@ -78,13 +91,3 @@ target_link_libraries(
r-type_ecs
r-type_network_client
)

add_custom_command(TARGET ${EXE} PRE_BUILD
COMMAND mkdir ${CMAKE_SOURCE_DIR}/Game/GameData
)

add_custom_command(TARGET ${EXE}
POST_BUILD
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/Game/GameData
COMMAND cp -r ${CMAKE_SOURCE_DIR}/Engine/Server/Config/* ${CMAKE_SOURCE_DIR}/Game/GameData
)
51 changes: 29 additions & 22 deletions Engine/Server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

# Set the executable name
set(EXE r-type_server)

# Set the output directory for the executable
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game)

# Define source and include paths
set(EXE_SRC_PATH "Src")
set(EXE_INCLUDE_PATH
"Include"
Expand All @@ -11,12 +19,11 @@ set(EXE_INCLUDE_PATH
"Src/GameEngine/ServerSceneManager"
)

set(CMAKE_CXX_STANDARD 20)

# Define the main source files for the executable
set(SRC_EXE
./${EXE_SRC_PATH}/main.cpp
./${EXE_SRC_PATH}/GameEngine/Application/Application.cpp
./${EXE_SRC_PATH}/GameEngine/ServerSceneManager/ServerSceneManager.cpp
${EXE_SRC_PATH}/main.cpp
${EXE_SRC_PATH}/GameEngine/Application/Application.cpp
${EXE_SRC_PATH}/GameEngine/ServerSceneManager/ServerSceneManager.cpp
../Shared/SceneManager/ASceneManager.cpp
../Shared/Component/FontPathComponent.cpp
../Shared/Component/ObjPathComponent.cpp
Expand All @@ -36,37 +43,37 @@ set(SRC_EXE
../Shared/Component/SoundVolumeComponent.cpp
)

# Include directories for header files
include_directories(
src/Network
src/GameEngine/Errors
src/GameEngine/Application
src/GameEngine/ServerSceneManager
../Shared/Ecs/Src
../Shared/Interface
../Shared/SceneManager
../Shared/Network/Packet
../Shared/Component
${EXE_SRC_PATH}/Network
${EXE_SRC_PATH}/GameEngine/Errors
${EXE_SRC_PATH}/GameEngine/Application
${EXE_SRC_PATH}/GameEngine/ServerSceneManager
../Shared/Ecs/Src
../Shared/Interface
../Shared/SceneManager
../Shared/Network/Packet
../Shared/Component
)

add_subdirectory(Src/Network)
# Add subdirectory for network sources
add_subdirectory(${EXE_SRC_PATH}/Network)

# Add the executable target
add_executable(${EXE} ${SRC_EXE})

# Include directories for the executable target
target_include_directories(${EXE} PUBLIC ${EXE_INCLUDE_PATH})

# Find required packages
find_package(asio REQUIRED)
find_package(jsoncpp REQUIRED)

# Link libraries to the executable target
target_link_libraries(
${EXE}
PRIVATE asio::asio
JsonCpp::JsonCpp
r-type_ecs
r-type_network_server
)

add_custom_command(TARGET ${EXE} POST_BUILD
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/Game/GameData
COMMAND cp -r ${CMAKE_SOURCE_DIR}/Engine/Server/Config/* ${CMAKE_SOURCE_DIR}/Game/GameData
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/Game/Mods
)
)
2 changes: 2 additions & 0 deletions Engine/Server/Src/Network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10)

set(LIB r-type_network_server)

set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game/Libs/Network/)

set(LIB_SRC_PATH ".")

set(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 2 additions & 0 deletions Engine/Shared/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Add subdirectories for different components of the Engine
add_subdirectory(Ecs)
add_subdirectory(Network)
18 changes: 14 additions & 4 deletions Engine/Shared/Ecs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

# Set the library name
set(LIB r-type_ecs)

# Set the output directory for the library
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game/Libs/ECS/)

# Define source and include paths
set(LIB_SRC_PATH "Src")
set(LIB_INCLUDE_PATH "Include")

set(CMAKE_CXX_STANDARD 20)

# Define the main source files for the library
set(SRC_LIB
${LIB_SRC_PATH}/Registry.cpp
${LIB_SRC_PATH}/Registry.cpp
)

# Add the static library target
add_library(${LIB} STATIC ${SRC_LIB})

target_include_directories(${LIB} PUBLIC ${INCLUDE_EXE})
# Include directories for the library target
target_include_directories(${LIB} PUBLIC ${LIB_INCLUDE_PATH})
2 changes: 2 additions & 0 deletions Engine/Shared/Network/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Add subdirectory for Packet
add_subdirectory(Packet)
22 changes: 18 additions & 4 deletions Engine/Shared/Network/Packet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

# Set the library name
set(LIB r-type_packet)
set(LIB_INCLUDE_PATH "Include")

set(CMAKE_CXX_STANDARD 20)
# Set the output directory for the library
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Game/Libs/Network/)

# Define include paths
set(LIB_INCLUDE_PATH "Include")

# Define the main source files for the library
set(SRC_LIB
NetworkPacket.cpp
NetworkPacket.cpp
)

# Add the static library target
add_library(${LIB} STATIC ${SRC_LIB})

# Find required packages
find_package(asio CONFIG REQUIRED)

# Link libraries to the library target
target_link_libraries(
${LIB}
PRIVATE asio::asio
)

target_include_directories(${LIB} PUBLIC ${INCLUDE_EXE})
# Include directories for the library target
target_include_directories(${LIB} PUBLIC ${LIB_INCLUDE_PATH})
Empty file added Game/Assets/.gitkeep
Empty file.
8 changes: 7 additions & 1 deletion GraphicLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

# Set the output directory for the library
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Game/Config/GraphicLibrary/)

# Include directories for header files
include_directories(
../Engine/Shared/Interface/
${CMAKE_SOURCE_DIR}/Engine/Shared/Interface/
)

# Add a shared library target 'graphic_raylib'
add_library(graphic_raylib SHARED Src/GraphicLib.cpp)

# Link the 'raylib' library to 'graphic_raylib'
target_link_libraries(graphic_raylib PRIVATE raylib)
2 changes: 2 additions & 0 deletions R-TypeGame/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Add the 'Systems' subdirectory to the build
add_subdirectory(Systems)
18 changes: 12 additions & 6 deletions R-TypeGame/Systems/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Minimum required version of CMake
cmake_minimum_required(VERSION 3.5)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)

set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Game/Config/Systems/)
# Set the output directory for the library
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Game/Config/Systems/)

# Include directories for header files
include_directories(
../../Engine/Shared/Ecs/Include/
../../Engine/Shared/Interface/
../../Engine/Shared/Component/
${CMAKE_SOURCE_DIR}/Engine/Shared/Ecs/Include/
${CMAKE_SOURCE_DIR}/Engine/Shared/Interface/
${CMAKE_SOURCE_DIR}/Engine/Shared/Component/
)

# Add a shared library target 'system_initPlayer'
add_library(system_initPlayer SHARED
Players/PlayerInitSystem.cpp
../Components/Life/LifeComponent.cpp
../../Engine/Shared/Component/Position3DComponent.cpp
../../Engine/Shared/Component/ObjPathComponent.cpp)
${CMAKE_SOURCE_DIR}/Engine/Shared/Component/Position3DComponent.cpp
${CMAKE_SOURCE_DIR}/Engine/Shared/Component/ObjPathComponent.cpp
)
Loading

0 comments on commit ea2b6f2

Please sign in to comment.