Skip to content

Commit

Permalink
more changes from otservb
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Aug 20, 2023
1 parent f30d0ec commit cd8c843
Show file tree
Hide file tree
Showing 138 changed files with 4,450 additions and 2,844 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ jobs:
with:
configurePreset: ${{ matrix.buildtype }}
buildPreset: ${{ matrix.buildtype }}
configurePresetAdditionalArgs: "['-DBUILD_TESTS=ON']"

- name: Create and Upload Artifact
uses: actions/upload-artifact@main
with:
name: otxserver-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }}
path: |
${{ github.workspace }}/build/${{ matrix.buildtype }}/bin/
- name: Unit tests
run: |
chmod +x ${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/canary_ut
${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/canary_ut
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ set(VCPKG_BUILD_TYPE "release")
# *****************************************************************************
# Project canary
# *****************************************************************************
project(otxserver)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
project(otxserver-debug)
else()
project(otxserver)
endif()


# *****************************************************************************
# Append cmake search path
# *****************************************************************************
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)

# *****************************************************************************
# Include cmake tools
# *****************************************************************************
include(MessageColors)
include(LoggingHelper)


# *****************************************************************************
# Options
# *****************************************************************************
option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF)
option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF)
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)



# *****************************************************************************
# Options Code
# *****************************************************************************
Expand Down Expand Up @@ -94,9 +94,14 @@ else()
log_option_disabled("ipo")
endif()

option(BUILD_TESTS "Build tests" OFF) # By default, tests will not be built

# *****************************************************************************
# Add project
# *****************************************************************************
add_subdirectory(src/protobuf)
add_subdirectory(src)

if(BUILD_TESTS)
add_subdirectory(tests)
endif()
2 changes: 2 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"BUILD_STATIC_LIBRARY": "ON",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"OPTIONS_ENABLE_CCACHE": "ON"
},
Expand Down Expand Up @@ -98,6 +99,7 @@
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"DEBUG_LOG": "ON",
"SPEED_UP_BUILD_UNITY": "OFF",
"ASAN_ENABLED": "ON"
}
}
Expand Down
151 changes: 151 additions & 0 deletions cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# *****************************************************************************
# CMake Features
# *****************************************************************************
set(CMAKE_CXX_STANDARD 20)
set(GNUCXX_MINIMUM_VERSION 11)
set(MSVC_MINIMUM_VERSION "19.32")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
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)

# Make will print more details
set(CMAKE_VERBOSE_MAKEFILE OFF)

# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# *****************************************************************************
# Packages / Libs
# *****************************************************************************
find_package(CURL CONFIG REQUIRED)
find_package(GMP REQUIRED)
find_package(LuaJIT REQUIRED)
find_package(MySQL REQUIRED)
find_package(Protobuf REQUIRED)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
find_package(absl CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(eventpp CONFIG REQUIRED)
find_package(jsoncpp CONFIG REQUIRED)
find_package(magic_enum CONFIG REQUIRED)
find_package(mio REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(spdlog REQUIRED)
find_package(unofficial-argon2 CONFIG REQUIRED)
find_package(unofficial-libmariadb CONFIG REQUIRED)

find_path(BOOST_DI_INCLUDE_DIRS "boost/di.hpp")

# *****************************************************************************
# Sanity Checks
# *****************************************************************************
# === GCC Minimum Version ===
if (CMAKE_COMPILER_IS_GNUCXX)
message("-- Compiler: GCC - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GNUCXX_MINIMUM_VERSION)
message(FATAL_ERROR "GCC version must be at least ${GNUCXX_MINIMUM_VERSION}!")
endif()
endif()

# === Minimum required version for visual studio ===
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message("-- Compiler: Visual Studio - Version: ${CMAKE_CXX_COMPILER_VERSION}")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MINIMUM_VERSION)
message(FATAL_ERROR "Visual Studio version must be at least ${MSVC_MINIMUM_VERSION}")
endif()
endif()

# *****************************************************************************
# Sanity Checks
# *****************************************************************************
option(TOGGLE_BIN_FOLDER "Use build/bin folder for generate compilation files" ON)
option(OPTIONS_ENABLE_OPENMP "Enable Open Multi-Processing support." ON)
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)

# === ASAN ===
if(ASAN_ENABLED)
log_option_enabled("asan")
if(MSVC)
add_compile_options(/fsanitize=address)
else()
add_compile_options(-fsanitize=address)
link_libraries(-fsanitize=address)
endif()
else()
log_option_disabled("asan")
endif()

# Build static libs
if(BUILD_STATIC_LIBRARY)
log_option_enabled("STATIC_LIBRARY")

if(MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
elseif(UNIX AND NOT APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
elseif(APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".dylib")
endif()
else()
log_option_disabled("STATIC_LIBRARY")
endif()

# === DEBUG LOG ===
# cmake -DDEBUG_LOG=ON ..
if(DEBUG_LOG)
add_definitions(-DDEBUG_LOG=ON)
log_option_enabled("DEBUG LOG")
else()
log_option_disabled("DEBUG LOG")
endif(DEBUG_LOG)

# *****************************************************************************
# Compiler Options
# *****************************************************************************
if (MSVC)
foreach(type RELEASE DEBUG RELWITHDEBINFO MINSIZEREL)
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_${type} "${CMAKE_CXX_FLAGS_${type}}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_${type} "${CMAKE_C_FLAGS_${type}}")
endforeach(type)

add_compile_options(/MP /FS /Zf /EHsc)
endif (MSVC)

## Link compilation files to build/bin folder, else link to the main dir
function(set_output_directory target_name)
if (TOGGLE_BIN_FOLDER)
set_target_properties(${target_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
else()
set_target_properties(${target_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/"
)
endif()
endfunction()

## Setup shared target basic configurations
function(setup_target TARGET_NAME)
set_output_directory(${TARGET_NAME})

if (MSVC AND BUILD_STATIC_LIBRARY)
set_property(TARGET ${TARGET_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endfunction()

# *****************************************************************************
# DEBUG: Print cmake variables
# *****************************************************************************
#get_cmake_property(_variableNames VARIABLES)
#list (SORT _variableNames)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
99 changes: 99 additions & 0 deletions cmake/modules/CanaryLib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Define and setup CanaryLib main library target
if(BUILD_STATIC_LIBRARY)
add_library(${PROJECT_NAME}_lib STATIC)
else()
add_library(${PROJECT_NAME}_lib SHARED)
endif()

setup_target(${PROJECT_NAME}_lib)

# Include sources cmake file to add source files to lib
include(Sources)

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

# *****************************************************************************
# Build flags - need to be set before the links and sources
# *****************************************************************************
if (CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(${PROJECT_NAME}_lib PRIVATE -Wno-deprecated-declarations)
endif()

# === IPO ===
check_ipo_supported(RESULT result OUTPUT output)
if(result)
set_property(TARGET ${PROJECT_NAME}_lib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${output}")
endif()

# === UNITY BUILD (compile time reducer) ===
if(SPEED_UP_BUILD_UNITY)
set_target_properties(${PROJECT_NAME}_lib PROPERTIES UNITY_BUILD ON)
log_option_enabled("Build unity for speed up compilation")
endif()

# *****************************************************************************
# Target include directories - to allow #include
# *****************************************************************************
target_include_directories(${PROJECT_NAME}_lib
PUBLIC
${BOOST_DI_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src
${GMP_INCLUDE_DIRS}
${LUAJIT_INCLUDE_DIRS}
${PARALLEL_HASHMAP_INCLUDE_DIRS}
)

# *****************************************************************************
# Target links to external dependencies
# *****************************************************************************
target_link_libraries(${PROJECT_NAME}_lib
PUBLIC
${GMP_LIBRARIES}
${LUAJIT_LIBRARIES}
CURL::libcurl
ZLIB::ZLIB
absl::any absl::log absl::base absl::bits
asio::asio
eventpp::eventpp
fmt::fmt
magic_enum::magic_enum
mio::mio
protobuf::libprotobuf
pugixml::pugixml
spdlog::spdlog
unofficial::argon2::libargon2
unofficial::libmariadb
unofficial::mariadbclient
)

if(CMAKE_BUILD_TYPE MATCHES Debug)
target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${ZLIB_LIBRARY_DEBUG})
else()
target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${ZLIB_LIBRARY_RELEASE})
endif()

if (MSVC)
if(BUILD_STATIC_LIBRARY)
target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_static)
else()
target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_lib)
endif()

target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_CLIENT_LIBS})
else()
target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_static 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()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit cd8c843

Please sign in to comment.