-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
138 changed files
with
4,450 additions
and
2,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.