Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: module cpp (migrate Position to modules) #2922

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
os: [ubuntu-24.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-22.04
- os: ubuntu-24.04
triplet: x64-linux

steps:
Expand All @@ -47,15 +47,17 @@
uses: actions/checkout@main

- name: Install Linux Dependencies
run: >

Check failure on line 50 in .github/workflows/build-ubuntu.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-ubuntu.yml#L50

shellcheck reported issue in this script: SC2046:warning:1:66: Quote this to prevent word splitting [shellcheck]
Raw output
.github/workflows/build-ubuntu.yml:50:9: shellcheck reported issue in this script: SC2046:warning:1:66: Quote this to prevent word splitting [shellcheck]
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)

- name: Switch to gcc-11
if: matrix.os == 'ubuntu-20.04'
- name: Switch to gcc-14
if: matrix.os == 'ubuntu-24.04'
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo apt update
sudo apt install gcc-14 g++-14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
sudo update-alternatives --set gcc /usr/bin/gcc-14


- name: CCache
uses: hendrikmuhs/ccache-action@main
Expand All @@ -67,7 +69,7 @@

- name: Restore artifacts and install vcpkg
id: vcpkg-step
run: |

Check failure on line 72 in .github/workflows/build-ubuntu.yml

View workflow job for this annotation

GitHub Actions / actionlint

[actionlint] .github/workflows/build-ubuntu.yml#L72

shellcheck reported issue in this script: SC2086:info:3:46: Double quote to prevent globbing and word splitting [shellcheck]
Raw output
.github/workflows/build-ubuntu.yml:72:9: shellcheck reported issue in this script: SC2086:info:3:46: Double quote to prevent globbing and word splitting [shellcheck]
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> $GITHUB_ENV
Expand Down
11 changes: 4 additions & 7 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.29)

# CMAKE
# apt install build-essential git
Expand All @@ -9,10 +9,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
# cmake -DCMAKE_TOOLCHAIN_FILE=/opt/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake ..
# Needed libs is in file vcpkg.json
# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil bshoshany-thread-pool
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
# cmake -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake .. --preset PresetNameHere

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
Expand All @@ -28,9 +25,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
50 changes: 40 additions & 10 deletions cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
cmake_minimum_required(VERSION 3.29)

# *****************************************************************************
# 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(THREADS_PREFER_PTHREAD_FLAG ON)
if (MSVC)
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")
endif()

# Make will print more details
set(CMAKE_VERBOSE_MAKEFILE OFF)
Expand Down Expand Up @@ -63,6 +72,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 All @@ -72,7 +89,7 @@ option(DEBUG_LOG "Enable Debug Log" OFF)
option(ASAN_ENABLED "Build this target with AddressSanitizer" OFF)
option(BUILD_STATIC_LIBRARY "Build using static libraries" OFF)
option(SPEED_UP_BUILD_UNITY "Compile using build unity for speed up build" ON)
option(USE_PRECOMPILED_HEADER "Compile using precompiled header" ON)
option(USE_PRECOMPILED_HEADERS "Compile using precompiled header" ON)

# === TOGGLE_BIN_FOLDER ===
if(TOGGLE_BIN_FOLDER)
Expand Down Expand Up @@ -132,12 +149,12 @@ else()
log_option_disabled("SPEED_UP_BUILD_UNITY")
endif(SPEED_UP_BUILD_UNITY)

# === USE_PRECOMPILED_HEADER ===
if(USE_PRECOMPILED_HEADER)
log_option_enabled("USE_PRECOMPILED_HEADER")
# === USE_PRECOMPILED_HEADERS ===
if(USE_PRECOMPILED_HEADERS)
log_option_enabled("USE_PRECOMPILED_HEADERS")
else()
log_option_disabled("USE_PRECOMPILED_HEADER")
endif(USE_PRECOMPILED_HEADER)
log_option_disabled("USE_PRECOMPILED_HEADERS")
endif(USE_PRECOMPILED_HEADERS)

# *****************************************************************************
# Compiler Options
Expand Down Expand Up @@ -175,6 +192,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
39 changes: 18 additions & 21 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_subdirectory(lib)
add_subdirectory(kv)
add_subdirectory(lua)
add_subdirectory(map)
add_subdirectory(modules)
add_subdirectory(protobuf)
add_subdirectory(security)
add_subdirectory(server)
Expand All @@ -23,11 +24,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 +37,10 @@ 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>)
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 All @@ -50,19 +53,20 @@ target_compile_definitions(${PROJECT_NAME}_lib PUBLIC
if(MSVC)
target_compile_options(${PROJECT_NAME}_lib PRIVATE "/GL")
set_target_properties(${PROJECT_NAME}_lib PROPERTIES
STATIC_LINKER_FLAGS "/LTCG"
SHARED_LINKER_FLAGS "/LTCG"
MODULE_LINKER_FLAGS "/LTCG"
EXE_LINKER_FLAGS "/LTCG")
STATIC_LINKER_FLAGS "/LTCG"
SHARED_LINKER_FLAGS "/LTCG"
MODULE_LINKER_FLAGS "/LTCG"
EXE_LINKER_FLAGS "/LTCG")
else()
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
check_ipo_supported(RESULT result LANGUAGES CXX OUTPUT output)
if(result)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=auto")
message(STATUS "IPO/LTO enabled with -flto=auto for non-MSVC compiler.")
message(STATUS "IPO/LTO enabled for non-MSVC C++ compiler with -flto=auto.")
set_property(TARGET ${PROJECT_NAME}_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO/LTO is not supported: ${output}")
message(WARNING "IPO/LTO is not supported for the C++ compiler: ${output}")
set_property(TARGET ${PROJECT_NAME}_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION FALSE)
endif()
endif()

Expand Down Expand Up @@ -106,6 +110,7 @@ target_link_libraries(${PROJECT_NAME}_lib
unofficial::libmariadb
unofficial::mariadbclient
protobuf
ModuleLib
)

if(FEATURE_METRICS)
Expand Down Expand Up @@ -139,16 +144,8 @@ if (MSVC)

target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_CLIENT_LIBS})
else()
target_link_libraries(${PROJECT_NAME}_lib PUBLIC Threads::Threads)
target_link_libraries(${PROJECT_NAME}_lib PRIVATE Threads::Threads)
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)
14 changes: 13 additions & 1 deletion qodana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@ bootstrap: |
set -e
sudo apt-get update && sudo apt-get -y dist-upgrade
sudo apt-get purge -y libclang*
sudo apt-get install -y cmake git unzip build-essential ca-certificates curl zip unzip tar pkg-config ninja-build autoconf automake libtool python3
sudo apt-get install -y git unzip build-essential ca-certificates curl zip tar pkg-config ninja-build autoconf automake libtool python3

CMAKE_VERSION=3.29.2
cd ~
wget https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION.tar.gz
tar -xzvf cmake-$CMAKE_VERSION.tar.gz
cd cmake-$CMAKE_VERSION
./bootstrap -- -DCMAKE_USE_OPENSSL=OFF
make -j$(nproc)
sudo make install

cd ~
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh

cd /data/project
rm -rf build
mkdir -p build
cd build
export CC=/usr/bin/cc
export CXX=/usr/bin/c++
cmake -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake .. --preset linux-debug || true

sudo apt-get install -y clang-16 clang-format-16 clang-tidy-16 clang-tools-16 libclang-common-16-dev libclang-cpp16 libclang-rt-16-dev libclang1-16 llvm-16-dev


Expand Down
3 changes: 1 addition & 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.29)

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

# Define main executable target, set it up and link to main library
add_executable(${PROJECT_NAME} main.cpp)

if(MSVC)
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 @@ -14,6 +14,8 @@
#include "declarations.hpp"
#include "map/map.hpp"

import game_movement;

class Condition;
class Creature;
class Item;
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 @@ -13,6 +13,8 @@

#include "enums/player_icons.hpp"

import game_movement;

class Creature;
class Player;
class PropStream;
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
Loading
Loading