Skip to content

Commit

Permalink
feat: module cpp (migrate Position to modules)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 28, 2024
1 parent 11bd3a6 commit aecbc20
Show file tree
Hide file tree
Showing 222 changed files with 348 additions and 447 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
cmake_minimum_required(VERSION 3.30)

# CMAKE
# apt install build-essential git
Expand Down Expand Up @@ -28,9 +28,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Project canary
# *****************************************************************************
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
project(canary-debug)
project(canary-debug LANGUAGES CXX)
else()
project(canary)
project(canary LANGUAGES CXX)
endif()


Expand Down
37 changes: 32 additions & 5 deletions cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
cmake_minimum_required(VERSION 3.30)

# *****************************************************************************
# CMake Features
# *****************************************************************************
set(CMAKE_CXX_STANDARD 20)
set(GNUCXX_MINIMUM_VERSION 11)
set(MSVC_MINIMUM_VERSION "19.32")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS NO)
set(GNUCXX_MINIMUM_VERSION 14)
set(CLANG_MINIMUM_VERSION 18)
set(MSVC_MINIMUM_VERSION "19.32")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(Boost_NO_WARN_NEW_VERSIONS ON)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDYNAPI ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /external:W0 /external:anglebrackets /external:templates-")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")

# Make will print more details
set(CMAKE_VERBOSE_MAKEFILE OFF)
Expand Down Expand Up @@ -63,6 +69,14 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif()
endif()

# === Minimum required version for clang ===
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message("-- Compiler: Clang - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_MINIMUM_VERSION)
message(FATAL_ERROR "Clang version must be at least ${CLANG_MINIMUM_VERSION}!")
endif()
endif()

# *****************************************************************************
# Sanity Checks
# *****************************************************************************
Expand Down Expand Up @@ -150,7 +164,7 @@ if (MSVC)

add_compile_options(/MP /FS /Zf /EHsc)
else()
add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra)
add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra -fmodules-ts)
endif()

## Link compilation files to build/bin folder, else link to the main dir
Expand All @@ -175,6 +189,19 @@ function(setup_target TARGET_NAME)
endif()
endfunction()

# === OpenMP ===
function(setup_open_mp target_name)
if(OPTIONS_ENABLE_OPENMP)
log_option_enabled("openmp")
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(${target_name} PUBLIC OpenMP::OpenMP_CXX)
endif()
else()
log_option_disabled("openmp")
endif()
endfunction()

# *****************************************************************************
# DEBUG: Print cmake variables
# *****************************************************************************
Expand Down
38 changes: 25 additions & 13 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
add_library(${PROJECT_NAME}_lib)
setup_target(${PROJECT_NAME}_lib)


# Define module sources
set(MODULE_SOURCES
test.cppm
position.cppm
)

# Create a static library for the module sources
add_library(my_module_lib STATIC)
target_sources(my_module_lib
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES FILES ${MODULE_SOURCES}
)

set_target_properties(my_module_lib PROPERTIES UNITY_BUILD ON)

# Add subdirectories
add_subdirectory(account)
add_subdirectory(config)
Expand All @@ -23,11 +39,9 @@ add_subdirectory(utils)
target_sources(${PROJECT_NAME}_lib PRIVATE canary_server.cpp)

# Add public pre compiler header to lib, to pass down to related targets
if (NOT SPEED_UP_BUILD_UNITY)
target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp)
endif()
target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp)

if(NOT SPEED_UP_BUILD_UNITY AND USE_PRECOMPILED_HEADERS)
if(USE_PRECOMPILED_HEADERS)
target_compile_definitions(${PROJECT_NAME}_lib PUBLIC -DUSE_PRECOMPILED_HEADERS)
endif()

Expand All @@ -38,6 +52,11 @@ if (CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(${PROJECT_NAME}_lib PRIVATE -Wno-deprecated-declarations)
endif()

if (MSVC)
target_compile_options(${PROJECT_NAME}_lib PRIVATE /MT$<$<CONFIG:Debug>:d>)
target_compile_options(my_module_lib PRIVATE /MT$<$<CONFIG:Debug>:d>)
endif()

# Sets the NDEBUG macro for RelWithDebInfo and Release configurations.
# This disables assertions in these configurations, optimizing the code for performance
# and reducing debugging overhead, while keeping debug information available for diagnostics.
Expand Down Expand Up @@ -106,6 +125,7 @@ target_link_libraries(${PROJECT_NAME}_lib
unofficial::libmariadb
unofficial::mariadbclient
protobuf
my_module_lib
)

if(FEATURE_METRICS)
Expand Down Expand Up @@ -143,12 +163,4 @@ else()
endif (MSVC)

# === OpenMP ===
if(OPTIONS_ENABLE_OPENMP)
log_option_enabled("openmp")
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(${PROJECT_NAME}_lib PUBLIC OpenMP::OpenMP_CXX)
endif()
else()
log_option_disabled("openmp")
endif()
setup_open_mp(${PROJECT_NAME}_lib)
17 changes: 15 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
cmake_minimum_required(VERSION 3.30)

# Base configurations and settings for the project
include(BaseConfig)
Expand All @@ -7,9 +7,22 @@ include(GNUInstallDirs)
# Import configurations, source definitions, and linker settings
include(CanaryLib)

# Define main executable target, set it up and link to main library
if(MSVC)
add_compile_options(/experimental:module)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "TRUE") # Habilita suporte experimental a módulos no CMake para MSVC
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options(-std=c++23 -fmodules-ts)
endif()

add_executable(${PROJECT_NAME} main.cpp)

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /experimental:module)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(${PROJECT_NAME} PRIVATE -fmodules-ts)
endif()


if(MSVC)
# Add executable icon for Windows
target_sources(${PROJECT_NAME} PRIVATE ../cmake/canary.rc)
Expand Down
2 changes: 0 additions & 2 deletions src/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account.hpp"

#include "account/account_repository_db.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/account/account_repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account_repository.hpp"

#include "lib/di/container.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/account/account_repository_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "account/account_repository_db.hpp"

#include "database/database.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "canary_server.hpp"

#include "declarations.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "config/configmanager.hpp"
#include "lib/di/container.hpp"
#include "game/game.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/appearance/mounts/mounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/appearance/mounts/mounts.hpp"
#include "game/game.hpp"
#include "utils/pugicast.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/appearance/outfit/outfit.hpp"
#include "utils/pugicast.hpp"
#include "utils/tools.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "declarations.hpp"
#include "creatures/combat/combat.hpp"
#include "lua/creature/events.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "lua/global/baseevents.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/combat/condition.hpp"
#include "game/game.hpp"
#include "game/scheduling/dispatcher.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/combat/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "declarations.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/combat/combat.hpp"
#include "creatures/combat/spells.hpp"
#include "creatures/monsters/monster.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "lua/scripts/luascript.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"
import game_movement;

#include "creatures/creature.hpp"
#include "declarations.hpp"
Expand Down
4 changes: 3 additions & 1 deletion src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "declarations.hpp"
#include "creatures/combat/condition.hpp"
#include "utils/utils_definitions.hpp"
#include "lua/creature/creatureevent.hpp"
#include "map/map.hpp"
#include "game/movement/position.hpp"
#include "enums/direction.hpp"
#include "items/tile.hpp"

using ConditionList = std::list<std::shared_ptr<Condition>>;
Expand Down
3 changes: 0 additions & 3 deletions src/creatures/creatures_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,6 @@ struct CreatureIcon {
}
};

// Structs
struct Position;

struct VIPEntry {
VIPEntry(uint32_t initGuid, const std::string &initName, const std::string &initDescription, uint32_t initIcon, bool initNotify) :
guid(initGuid),
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/interactions/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/interactions/chat.hpp"
#include "game/game.hpp"
#include "utils/pugicast.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/monster.hpp"
#include "creatures/combat/spells.hpp"
#include "creatures/players/wheel/player_wheel.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "creatures/monsters/monsters.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/monsters.hpp"

#include "creatures/combat/spells.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/creatures/monsters/monsters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* Website: https://docs.opentibiabr.com/
*/

import game_movement;

#pragma once

#include "io/io_bosstiary.hpp"
Expand Down
2 changes: 0 additions & 2 deletions src/creatures/monsters/spawns/spawn_monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* Website: https://docs.opentibiabr.com/
*/

#include "pch.hpp"

#include "creatures/monsters/spawns/spawn_monster.hpp"
#include "game/game.hpp"
#include "creatures/monsters/monster.hpp"
Expand Down
Loading

0 comments on commit aecbc20

Please sign in to comment.