2024-03-18 01:48:09 +00:00
cmake_minimum_required ( VERSION 3.25 )
2021-12-05 17:54:36 +00:00
project ( Darkflame )
2024-05-16 13:05:57 +00:00
# check if the path to the source directory contains a space
if ( "${CMAKE_SOURCE_DIR}" MATCHES " " )
message ( FATAL_ERROR "The server cannot build in the path (" ${ CMAKE_SOURCE_DIR } ") because it contains a space. Please move the server to a path without spaces." )
endif ( )
2022-01-03 15:00:21 +00:00
include ( CTest )
2021-12-05 17:54:36 +00:00
2024-01-02 07:53:00 +00:00
set ( CMAKE_CXX_STANDARD 20 )
2024-01-30 03:45:50 +00:00
set ( CXX_STANDARD_REQUIRED ON )
2024-03-27 05:10:39 +00:00
set ( CMAKE_EXPORT_COMPILE_COMMANDS ON ) # Export the compile commands for debugging
set ( CMAKE_POLICY_DEFAULT_CMP0063 NEW ) # Set CMAKE visibility policy to NEW on project and subprojects
set ( CMAKE_VISIBILITY_INLINES_HIDDEN ON ) # Set C and C++ symbol visibility to hide inlined functions
2024-01-03 00:25:57 +00:00
set ( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" )
2022-07-10 19:40:26 +00:00
2021-12-05 17:54:36 +00:00
# Read variables from file
FILE ( READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables )
string ( REPLACE "\\\n" "" variables ${ variables } )
string ( REPLACE "\n" ";" variables ${ variables } )
# Set the cmake variables, formatted as "VARIABLE #" in variables
foreach ( variable ${ variables } )
2022-07-16 23:24:16 +00:00
# If the string contains a #, skip it
if ( NOT "${variable}" MATCHES "#" )
2022-07-18 09:01:43 +00:00
# Split the variable into name and value
2022-07-16 23:24:16 +00:00
string ( REPLACE "=" ";" variable ${ variable } )
2021-12-05 17:54:36 +00:00
2022-07-18 09:01:43 +00:00
# Check that the length of the variable is 2 (name and value)
2022-07-16 23:24:16 +00:00
list ( LENGTH variable length )
2021-12-05 17:54:36 +00:00
2024-01-03 00:25:57 +00:00
if ( ${ length } EQUAL 2 )
2022-07-16 23:24:16 +00:00
list ( GET variable 0 variable_name )
list ( GET variable 1 variable_value )
2021-12-05 17:54:36 +00:00
2022-07-16 23:24:16 +00:00
# Set the variable
set ( ${ variable_name } ${ variable_value } )
2021-12-05 17:54:36 +00:00
2022-07-16 23:24:16 +00:00
message ( STATUS "Variable: ${variable_name} = ${variable_value}" )
2022-07-04 08:30:11 +00:00
endif ( )
endif ( )
2021-12-05 17:54:36 +00:00
endforeach ( )
# Set the version
2023-12-31 06:26:49 +00:00
set ( PROJECT_VERSION "\" ${ PROJECT_VERSION_MAJOR } . ${ PROJECT_VERSION_MINOR } . ${ PROJECT_VERSION_PATCH } \"")
2021-12-05 17:54:36 +00:00
# Echo the version
message ( STATUS "Version: ${PROJECT_VERSION}" )
2022-08-19 02:23:42 +00:00
# Disable demo, tests and examples for recastNavigation. Turn these to ON if you want to use them
# This has to be done here to prevent a rare build error due to missing dependencies on the initial generations.
set ( RECASTNAVIGATION_DEMO OFF CACHE BOOL "" FORCE )
set ( RECASTNAVIGATION_TESTS OFF CACHE BOOL "" FORCE )
set ( RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "" FORCE )
2022-07-16 23:24:16 +00:00
# Compiler flags:
2022-08-02 05:30:19 +00:00
# Disabled deprecated warnings as the MySQL includes have deprecated code in them.
2022-07-16 23:24:16 +00:00
# Disabled misleading indentation as DL_LinkedList from RakNet has a weird indent.
# Disabled no-register
# Disabled unknown pragmas because Linux doesn't understand Windows pragmas.
if ( UNIX )
2024-01-08 23:32:09 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wuninitialized -fPIC" )
2023-12-31 06:26:49 +00:00
add_compile_definitions ( _GLIBCXX_USE_CXX11_ABI=0 _GLIBCXX_USE_CXX17_ABI=0 )
2024-01-03 00:25:57 +00:00
2023-12-31 06:26:49 +00:00
if ( NOT APPLE )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -lstdc++fs" )
2022-07-16 23:24:16 +00:00
endif ( )
2023-12-31 06:26:49 +00:00
2024-01-03 00:25:57 +00:00
if ( ${ DYNAMIC } AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
2022-07-16 23:24:16 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic" )
endif ( )
2023-12-31 06:26:49 +00:00
2024-01-03 00:25:57 +00:00
if ( ${ GGDB } )
2022-07-16 23:24:16 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb" )
endif ( )
2023-12-31 06:26:49 +00:00
2022-07-16 23:24:16 +00:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC" )
elseif ( MSVC )
# Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
2024-04-05 17:56:23 +00:00
# Also disable non-portable MSVC volatile behavior
add_compile_options ( "/wd4267" "/utf-8" "/volatile:iso" )
2022-07-16 23:24:16 +00:00
elseif ( WIN32 )
add_compile_definitions ( _CRT_SECURE_NO_WARNINGS )
endif ( )
2021-12-05 17:54:36 +00:00
# Our output dir
set ( CMAKE_BINARY_DIR ${ PROJECT_BINARY_DIR } )
2024-03-06 02:13:24 +00:00
#set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) # unfortunately, forces all libraries to be built in series, which will slow down the build process
2022-11-07 08:12:35 +00:00
# TODO make this not have to override the build type directories
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${ CMAKE_BINARY_DIR } )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${ CMAKE_BINARY_DIR } )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${ CMAKE_BINARY_DIR } )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${ CMAKE_BINARY_DIR } )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${ CMAKE_BINARY_DIR } )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${ CMAKE_BINARY_DIR } )
2022-07-16 23:24:16 +00:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ CMAKE_BINARY_DIR } )
2021-12-05 17:54:36 +00:00
2024-03-06 02:13:24 +00:00
find_package ( MariaDB )
2022-12-22 06:34:11 +00:00
# Create a /resServer directory
make_directory ( ${ CMAKE_BINARY_DIR } /resServer )
2021-12-05 17:54:36 +00:00
2021-12-13 15:57:43 +00:00
# Create a /logs directory
make_directory ( ${ CMAKE_BINARY_DIR } /logs )
2022-07-18 09:01:43 +00:00
# Copy resource files on first build
2024-04-05 05:51:40 +00:00
set ( RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf" )
2023-07-23 19:09:07 +00:00
message ( STATUS "Checking resource file integrity" )
2024-01-03 00:25:57 +00:00
include ( Utils )
2024-01-03 08:36:17 +00:00
UpdateConfigOption ( ${ PROJECT_BINARY_DIR } /authconfig.ini "port" "auth_server_port" )
UpdateConfigOption ( ${ PROJECT_BINARY_DIR } /chatconfig.ini "port" "chat_server_port" )
UpdateConfigOption ( ${ PROJECT_BINARY_DIR } /masterconfig.ini "port" "master_server_port" )
2024-01-03 00:25:57 +00:00
foreach ( resource_file ${ RESOURCE_FILES } )
2023-07-23 19:09:07 +00:00
set ( file_size 0 )
2024-01-03 00:25:57 +00:00
if ( EXISTS ${ PROJECT_BINARY_DIR } / ${ resource_file } )
2023-07-23 19:09:07 +00:00
file ( SIZE ${ PROJECT_BINARY_DIR } / ${ resource_file } file_size )
endif ( )
2024-01-03 00:25:57 +00:00
if ( ${ file_size } EQUAL 0 )
2022-07-16 23:24:16 +00:00
configure_file (
2022-07-17 06:54:36 +00:00
$ { C M A K E _ S O U R C E _ D I R } / r e s o u r c e s / $ { r e s o u r c e _ f i l e } $ { P R O J E C T _ B I N A R Y _ D I R } / $ { r e s o u r c e _ f i l e }
2022-07-16 23:24:16 +00:00
C O P Y O N L Y
)
2023-07-23 19:09:07 +00:00
message ( STATUS "Moved " ${ resource_file } " to project binary directory" )
2024-01-03 00:25:57 +00:00
elseif ( resource_file MATCHES ".ini" )
2023-07-23 19:09:07 +00:00
message ( STATUS "Checking " ${ resource_file } " for missing config options" )
file ( READ ${ PROJECT_BINARY_DIR } / ${ resource_file } current_file_contents )
string ( REPLACE "\\\n" "" current_file_contents ${ current_file_contents } )
string ( REPLACE "\n" ";" current_file_contents ${ current_file_contents } )
set ( parsed_current_file_contents "" )
2024-01-03 00:25:57 +00:00
2023-07-23 19:09:07 +00:00
# Remove comment lines so they do not interfere with the variable parsing
2024-01-03 00:25:57 +00:00
foreach ( line ${ current_file_contents } )
2023-07-23 19:09:07 +00:00
string ( FIND ${ line } "#" is_comment )
2024-01-03 00:25:57 +00:00
if ( NOT ${ is_comment } EQUAL 0 )
2023-07-23 19:09:07 +00:00
string ( APPEND parsed_current_file_contents ${ line } )
endif ( )
endforeach ( )
2024-01-03 00:25:57 +00:00
2023-07-23 19:09:07 +00:00
file ( READ ${ CMAKE_SOURCE_DIR } /resources/ ${ resource_file } depot_file_contents )
string ( REPLACE "\\\n" "" depot_file_contents ${ depot_file_contents } )
string ( REPLACE "\n" ";" depot_file_contents ${ depot_file_contents } )
set ( line_to_add "" )
2024-01-03 00:25:57 +00:00
foreach ( line ${ depot_file_contents } )
2023-07-23 19:09:07 +00:00
string ( FIND ${ line } "#" is_comment )
2024-01-03 00:25:57 +00:00
if ( NOT ${ is_comment } EQUAL 0 )
2023-07-23 19:09:07 +00:00
string ( REPLACE "=" ";" line_split ${ line } )
list ( GET line_split 0 variable_name )
2024-01-03 00:25:57 +00:00
if ( NOT ${ parsed_current_file_contents } MATCHES ${ variable_name } )
2023-07-23 19:09:07 +00:00
message ( STATUS "Adding missing config option " ${ variable_name } " to " ${ resource_file } )
set ( line_to_add ${ line_to_add } ${ line } )
2024-01-03 00:25:57 +00:00
foreach ( line_to_append ${ line_to_add } )
2023-07-23 19:09:07 +00:00
file ( APPEND ${ PROJECT_BINARY_DIR } / ${ resource_file } "\n" ${ line_to_append } )
endforeach ( )
2024-01-03 00:25:57 +00:00
2023-07-23 19:09:07 +00:00
file ( APPEND ${ PROJECT_BINARY_DIR } / ${ resource_file } "\n" )
endif ( )
2024-01-03 00:25:57 +00:00
2023-07-23 19:09:07 +00:00
set ( line_to_add "" )
else ( )
set ( line_to_add ${ line_to_add } ${ line } )
endif ( )
endforeach ( )
2022-07-16 23:24:16 +00:00
endif ( )
endforeach ( )
2024-01-03 00:25:57 +00:00
2023-07-23 19:09:07 +00:00
message ( STATUS "Resource file integrity check complete" )
2021-12-05 17:54:36 +00:00
2023-10-28 04:19:43 +00:00
# if navmeshes directory does not exist, create it
2024-01-03 00:25:57 +00:00
if ( NOT EXISTS ${ PROJECT_BINARY_DIR } /navmeshes )
2023-10-28 04:19:43 +00:00
file ( MAKE_DIRECTORY ${ PROJECT_BINARY_DIR } /navmeshes )
2022-11-01 18:21:26 +00:00
endif ( )
2023-10-28 04:19:43 +00:00
# Copy navmesh data on first build and extract it
2023-12-31 06:26:49 +00:00
configure_file ( ${ CMAKE_SOURCE_DIR } /resources/navmeshes.zip ${ PROJECT_BINARY_DIR } /navmeshes.zip COPYONLY )
2023-10-28 04:19:43 +00:00
file ( ARCHIVE_EXTRACT INPUT ${ PROJECT_BINARY_DIR } /navmeshes.zip DESTINATION ${ PROJECT_BINARY_DIR } /navmeshes )
file ( REMOVE ${ PROJECT_BINARY_DIR } /navmeshes.zip )
2022-07-16 23:24:16 +00:00
# Copy vanity files on first build
2024-02-28 23:16:47 +00:00
set ( VANITY_FILES "CREDITS.md" "INFO.md" "TESTAMENT.md" "root.xml" "dev-tribute.xml" "atm.xml" "demo.xml" )
2024-01-03 00:25:57 +00:00
2022-07-16 23:24:16 +00:00
foreach ( file ${ VANITY_FILES } )
configure_file ( "${CMAKE_SOURCE_DIR}/vanity/${file}" "${CMAKE_BINARY_DIR}/vanity/${file}" COPYONLY )
endforeach ( )
2021-12-05 17:54:36 +00:00
2022-07-10 19:40:26 +00:00
# Move our migrations for MasterServer to run
2022-10-30 07:38:43 +00:00
file ( MAKE_DIRECTORY ${ PROJECT_BINARY_DIR } /migrations/dlu/ )
2022-07-10 19:40:26 +00:00
file ( GLOB SQL_FILES ${ CMAKE_SOURCE_DIR } /migrations/dlu/*.sql )
2024-01-03 00:25:57 +00:00
2022-07-16 23:24:16 +00:00
foreach ( file ${ SQL_FILES } )
get_filename_component ( file ${ file } NAME )
2023-12-31 06:26:49 +00:00
configure_file ( ${ CMAKE_SOURCE_DIR } /migrations/dlu/ ${ file } ${ PROJECT_BINARY_DIR } /migrations/dlu/ ${ file } )
2022-10-30 07:38:43 +00:00
endforeach ( )
file ( MAKE_DIRECTORY ${ PROJECT_BINARY_DIR } /migrations/cdserver/ )
file ( GLOB SQL_FILES ${ CMAKE_SOURCE_DIR } /migrations/cdserver/*.sql )
2024-01-03 00:25:57 +00:00
2022-10-30 07:38:43 +00:00
foreach ( file ${ SQL_FILES } )
get_filename_component ( file ${ file } NAME )
2023-12-31 06:26:49 +00:00
configure_file ( ${ CMAKE_SOURCE_DIR } /migrations/cdserver/ ${ file } ${ PROJECT_BINARY_DIR } /migrations/cdserver/ ${ file } )
2022-07-10 19:40:26 +00:00
endforeach ( )
2024-03-06 02:13:24 +00:00
# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)
if ( APPLE )
include_directories ( "/usr/local/include/" )
endif ( )
# Load all of our third party directories
2024-03-18 01:48:09 +00:00
add_subdirectory ( thirdparty SYSTEM )
2024-03-06 02:13:24 +00:00
2022-07-16 23:24:16 +00:00
# Create our list of include directories
2024-03-18 01:48:09 +00:00
include_directories (
2022-08-02 05:30:19 +00:00
" d P h y s i c s "
2023-12-31 06:26:49 +00:00
2022-08-02 05:30:19 +00:00
" d N a v i g a t i o n "
2023-12-31 06:26:49 +00:00
2022-07-16 23:24:16 +00:00
" d N e t "
2023-12-31 06:26:49 +00:00
2022-11-07 08:12:35 +00:00
" t e s t s "
" t e s t s / d C o m m o n T e s t s "
" t e s t s / d G a m e T e s t s "
" t e s t s / d G a m e T e s t s / d C o m p o n e n t s T e s t s "
2024-03-18 01:48:09 +00:00
S Y S T E M " t h i r d p a r t y / m a g i c _ e n u m / i n c l u d e / m a g i c _ e n u m "
S Y S T E M " t h i r d p a r t y / r a k n e t / S o u r c e "
S Y S T E M " t h i r d p a r t y / t i n y x m l 2 "
S Y S T E M " t h i r d p a r t y / r e c a s t n a v i g a t i o n "
S Y S T E M " t h i r d p a r t y / S Q L i t e "
S Y S T E M " t h i r d p a r t y / c p p l i n q "
S Y S T E M " t h i r d p a r t y / c p p - h t t p l i b "
S Y S T E M " t h i r d p a r t y / M D 5 "
2023-12-31 06:26:49 +00:00
)
2022-07-16 23:24:16 +00:00
# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)
2024-03-06 02:13:24 +00:00
# TODO: Should probably not do this.
2024-01-03 00:25:57 +00:00
if ( APPLE )
2022-07-16 23:24:16 +00:00
include_directories ( "/usr/local/include/" )
endif ( )
2021-12-05 17:54:36 +00:00
2022-07-16 23:24:16 +00:00
# Add linking directories:
2024-01-19 16:18:36 +00:00
if ( UNIX )
2024-03-18 01:48:09 +00:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Werror" ) # Warning flags
2024-01-19 16:18:36 +00:00
endif ( )
2022-07-04 22:24:45 +00:00
file (
2022-07-16 23:24:16 +00:00
G L O B H E A D E R S _ D Z O N E M A N A G E R
L I S T _ D I R E C T O R I E S f a l s e
$ { P R O J E C T _ S O U R C E _ D I R } / d Z o n e M a n a g e r / * . h
2022-07-04 22:24:45 +00:00
)
2021-12-05 17:54:36 +00:00
file (
2022-07-16 23:24:16 +00:00
G L O B H E A D E R S _ D C O M M O N
L I S T _ D I R E C T O R I E S f a l s e
$ { P R O J E C T _ S O U R C E _ D I R } / d C o m m o n / * . h
2021-12-05 17:54:36 +00:00
)
file (
2022-07-16 23:24:16 +00:00
G L O B H E A D E R S _ D G A M E
L I S T _ D I R E C T O R I E S f a l s e
2022-08-02 05:30:19 +00:00
$ { P R O J E C T _ S O U R C E _ D I R } / d G a m e / E n t i t y . h
2022-07-16 23:24:16 +00:00
$ { P R O J E C T _ S O U R C E _ D I R } / d G a m e / d G a m e M e s s a g e s / G a m e M e s s a g e s . h
$ { P R O J E C T _ S O U R C E _ D I R } / d G a m e / E n t i t y M a n a g e r . h
$ { P R O J E C T _ S O U R C E _ D I R } / d S c r i p t s / C p p S c r i p t s . h
)
# Add our library subdirectories for creation of the library object
add_subdirectory ( dCommon )
add_subdirectory ( dDatabase )
add_subdirectory ( dChatFilter )
add_subdirectory ( dNet )
add_subdirectory ( dScripts ) # Add for dGame to use
add_subdirectory ( dGame )
add_subdirectory ( dZoneManager )
2022-08-02 05:30:19 +00:00
add_subdirectory ( dNavigation )
2022-07-16 23:24:16 +00:00
add_subdirectory ( dPhysics )
2024-01-06 05:32:09 +00:00
add_subdirectory ( dServer )
2022-07-16 23:24:16 +00:00
# Create a list of common libraries shared between all binaries
2024-05-02 11:35:55 +00:00
set ( COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "MariaDB::ConnCpp" "magic_enum" )
2022-07-16 23:24:16 +00:00
# Add platform specific common libraries
2024-01-03 00:25:57 +00:00
if ( UNIX )
2022-07-16 23:24:16 +00:00
set ( COMMON_LIBRARIES ${ COMMON_LIBRARIES } "dl" "pthread" )
2024-01-03 00:25:57 +00:00
if ( NOT APPLE AND ${ INCLUDE_BACKTRACE } )
2022-07-16 23:24:16 +00:00
set ( COMMON_LIBRARIES ${ COMMON_LIBRARIES } "backtrace" )
endif ( )
endif ( )
2021-12-05 17:54:36 +00:00
2022-07-16 23:24:16 +00:00
# Include all of our binary directories
add_subdirectory ( dWorldServer )
add_subdirectory ( dAuthServer )
add_subdirectory ( dChatServer )
add_subdirectory ( dMasterServer ) # Add MasterServer last so it can rely on the other binaries
2021-12-05 17:54:36 +00:00
2022-07-04 22:24:45 +00:00
target_precompile_headers (
2022-08-02 05:30:19 +00:00
d Z o n e M a n a g e r P R I V A T E
2022-07-16 23:24:16 +00:00
$ { H E A D E R S _ D Z O N E M A N A G E R }
2022-07-04 22:24:45 +00:00
)
target_precompile_headers (
2022-07-16 23:24:16 +00:00
d C o m m o n P R I V A T E
$ { H E A D E R S _ D C O M M O N }
2022-07-04 22:24:45 +00:00
)
target_precompile_headers (
2022-07-16 23:24:16 +00:00
t i n y x m l 2 P R I V A T E
" $ < $ < C O M P I L E _ L A N G U A G E : C X X > : $ { P R O J E C T _ S O U R C E _ D I R } / t h i r d p a r t y / t i n y x m l 2 / t i n y x m l 2 . h > "
2022-08-02 05:30:19 +00:00
)
2022-11-07 08:12:35 +00:00
2024-01-03 00:25:57 +00:00
if ( ${ ENABLE_TESTING } )
2022-11-07 08:12:35 +00:00
add_subdirectory ( tests )
endif ( )