Fix indentation and divided the cmake into libraries and bins

- Each library and binary got their own CMakeLists.txt
- Indentation was fixed everywhere
- Weird if statement flows replaced
This commit is contained in:
Jett 2022-01-22 10:27:19 +00:00
parent c25a8004be
commit 005a12424e
13 changed files with 248 additions and 283 deletions

View File

@ -63,11 +63,9 @@ FetchContent_MakeAvailable(mysql)
set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR}) set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
set_target_properties(zlib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}") # Why? set_target_properties(zlib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}") # Why?
add_library(ZLIB::ZLIB ALIAS zlib) # You're welcome add_library(ZLIB::ZLIB ALIAS zlib) # You're welcome
endif()
endif(WIN32) if(UNIX AND NOT APPLE)
if(UNIX)
if(APPLE)
else()
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
@ -93,13 +91,11 @@ if (__include_backtrace__ AND __compile_backtrace__)
COMMAND bash -c "cd ${backtrace_SOURCE_DIR} && ${backtrace_make_cmd} && make && cd ${CMAKE_SOURCE_DIR}" COMMAND bash -c "cd ${backtrace_SOURCE_DIR} && ${backtrace_make_cmd} && make && cd ${CMAKE_SOURCE_DIR}"
) )
endif() endif()
endif()
link_directories(${backtrace_SOURCE_DIR}/.libs/) link_directories(${backtrace_SOURCE_DIR}/.libs/)
include_directories(${backtrace_SOURCE_DIR}) include_directories(${backtrace_SOURCE_DIR})
endif(__include_backtrace__ AND __compile_backtrace__)
endif() endif()
endif(UNIX)
# Set the version # Set the version
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
@ -113,18 +109,14 @@ set(CMAKE_CXX_STANDARD 17)
if(WIN32) if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif(WIN32) endif()
# Our output dir # Our output dir
set(CMAKE_BINARY_DIR ${PROJECT_BINARY_DIR}) set(CMAKE_BINARY_DIR ${PROJECT_BINARY_DIR})
# Create a /res directory # Create /res, /locale and /logs directories
make_directory(${CMAKE_BINARY_DIR}/res) make_directory(${CMAKE_BINARY_DIR}/res)
# Create a /locale directory
make_directory(${CMAKE_BINARY_DIR}/locale) make_directory(${CMAKE_BINARY_DIR}/locale)
# Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs) make_directory(${CMAKE_BINARY_DIR}/logs)
# Copy ini files on first build # Copy ini files on first build
@ -169,12 +161,13 @@ if(UNIX)
else() else()
include_directories(${mysql_SOURCE_DIR}/include/jdbc/) include_directories(${mysql_SOURCE_DIR}/include/jdbc/)
include_directories(${mysql_SOURCE_DIR}/include/jdbc/cppconn/) include_directories(${mysql_SOURCE_DIR}/include/jdbc/cppconn/)
endif(APPLE) endif()
endif(UNIX) endif()
if(WIN32) if(WIN32)
include_directories(${mysql_SOURCE_DIR}/include/jdbc) include_directories(${mysql_SOURCE_DIR}/include/jdbc)
include_directories(${mysql_SOURCE_DIR}/include/jdbc/cppconn) include_directories(${mysql_SOURCE_DIR}/include/jdbc/cppconn)
endif(WIN32) endif()
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/tinyxml2/) include_directories(${PROJECT_SOURCE_DIR}/thirdparty/tinyxml2/)
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include) include_directories(${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include)
include_directories(${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include) include_directories(${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include)
@ -213,7 +206,7 @@ include_directories(${PROJECT_SOURCE_DIR}/dScripts/)
set(MYSQL_LIB mysql) set(MYSQL_LIB mysql)
if(WIN32) if(WIN32)
set(MYSQL_LIB mysqlcppconn) set(MYSQL_LIB mysqlcppconn)
endif(WIN32) endif()
# Lib folders: # Lib folders:
link_directories(${PROJECT_BINARY_DIR}) link_directories(${PROJECT_BINARY_DIR})
@ -225,196 +218,46 @@ if(UNIX)
# Link to libmysqlcppconn on Linux # Link to libmysqlcppconn on Linux
set(MYSQL_LIB mysqlcppconn) set(MYSQL_LIB mysqlcppconn)
endif(APPLE) endif()
endif(UNIX) endif()
if(WIN32) if(WIN32)
link_directories(${mysql_SOURCE_DIR}/lib64/vs14) link_directories(${mysql_SOURCE_DIR}/lib64/vs14)
endif(WIN32) endif()
# Third-Party libraries # Third-Party libraries
add_subdirectory(thirdparty) add_subdirectory(thirdparty)
# Source Code # add_subdirectory for libraries
file( add_subdirectory(dCommon)
GLOB SOURCES add_subdirectory(dChatFilter)
LIST_DIRECTORIES false add_subdirectory(dDatabase)
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" add_subdirectory(dNet)
${PROJECT_SOURCE_DIR}/dWorldServer/*.cpp add_subdirectory(dGame)
) add_subdirectory(dZoneManager)
add_subdirectory(dPhysics)
# Source Code for AuthServer # Setup shared libraries between binaries
file(
GLOB SOURCES_AUTH
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dAuthServer/*.cpp
)
# Source Code for MasterServer set(SHARED_LIBS dCommon dNet dDatabase raknet ${MYSQL_LIB})
file(
GLOB SOURCES_MASTER
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dMasterServer/*.cpp
)
# Source Code for ChatServer
file(
GLOB SOURCES_CHAT
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dChatServer/*.cpp
)
# Source Code for dCommon
file(
GLOB SOURCES_DCOMMON
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dCommon/*.cpp
)
# Source Code for dChatFilter
file(
GLOB SOURCES_DCHATFILTER
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dChatFilter/*.cpp
)
# Source Code for dDatabase
file(
GLOB SOURCES_DDATABASE
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dDatabase/*.cpp
${PROJECT_SOURCE_DIR}/dDatabase/Tables/*.cpp
)
# Source Code for dNet
file(
GLOB SOURCES_DNET
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dNet/*.cpp
)
# Source Code for dGame
file(
GLOB SOURCES_DGAME
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dGame/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dBehaviors/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dComponents/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dGameMessages/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dInventory/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dMission/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dEntity/*.cpp
${PROJECT_SOURCE_DIR}/dGame/dUtilities/*.cpp
${PROJECT_SOURCE_DIR}/dScripts/*.cpp
)
# Source Code for dZoneManager
file(
GLOB SOURCES_DZM
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dZoneManager/*.cpp
)
# Source Code for dPhysics
file(
GLOB SOURCES_DPHYSICS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/dPhysics/*.cpp
)
if(MSVC)
# Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
add_compile_options("/wd4267")
endif(MSVC)
# Our static libraries:
add_library(dCommon ${SOURCES_DCOMMON})
add_library(dChatFilter ${SOURCES_DCHATFILTER})
add_library(dDatabase ${SOURCES_DDATABASE})
add_library(dNet ${SOURCES_DNET})
add_library(dGame ${SOURCES_DGAME})
add_library(dZoneManager ${SOURCES_DZM})
add_library(dPhysics ${SOURCES_DPHYSICS})
target_link_libraries(dDatabase sqlite3)
target_link_libraries(dNet dCommon) #Needed because otherwise linker errors occur.
target_link_libraries(dCommon ZLIB::ZLIB)
target_link_libraries(dCommon libbcrypt)
if(WIN32)
target_link_libraries(raknet ws2_32)
endif(WIN32)
# Our executables:
add_executable(WorldServer ${SOURCES})
add_executable(AuthServer ${SOURCES_AUTH})
add_executable(MasterServer ${SOURCES_MASTER})
add_executable(ChatServer ${SOURCES_CHAT})
# Target libraries to link to:
target_link_libraries(WorldServer dCommon)
target_link_libraries(WorldServer dChatFilter)
target_link_libraries(WorldServer dDatabase)
target_link_libraries(WorldServer dNet)
target_link_libraries(WorldServer dGame)
target_link_libraries(WorldServer dZoneManager)
target_link_libraries(WorldServer dPhysics)
target_link_libraries(WorldServer detour)
target_link_libraries(WorldServer recast)
target_link_libraries(WorldServer raknet)
target_link_libraries(WorldServer ${MYSQL_LIB})
if(UNIX) if(UNIX)
set(SHARED_LIBS ${SHARED_LIBS} pthread dl)
if(NOT APPLE AND __include_backtrace__) if(NOT APPLE AND __include_backtrace__)
target_link_libraries(WorldServer backtrace) set(SHARED_LIBS ${SHARED_LIBS} backtrace)
target_link_libraries(MasterServer backtrace) endif()
target_link_libraries(AuthServer backtrace)
target_link_libraries(ChatServer backtrace)
endif() endif()
endif(UNIX) # Our executables:
target_link_libraries(WorldServer tinyxml2) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Target libraries for Auth: add_subdirectory(dAuthServer)
target_link_libraries(AuthServer dCommon) add_subdirectory(dChatServer)
target_link_libraries(AuthServer dDatabase) add_subdirectory(dWorldServer)
target_link_libraries(AuthServer dNet) add_subdirectory(dMasterServer)
target_link_libraries(AuthServer raknet)
target_link_libraries(AuthServer ${MYSQL_LIB})
if(UNIX)
target_link_libraries(AuthServer pthread)
target_link_libraries(AuthServer dl)
endif(UNIX)
# Target libraries for Master:
target_link_libraries(MasterServer dCommon)
target_link_libraries(MasterServer dDatabase)
target_link_libraries(MasterServer dNet)
target_link_libraries(MasterServer raknet)
target_link_libraries(MasterServer ${MYSQL_LIB})
if(UNIX)
target_link_libraries(MasterServer pthread)
target_link_libraries(MasterServer dl)
endif(UNIX)
# Target libraries for Chat:
target_link_libraries(ChatServer dCommon)
target_link_libraries(ChatServer dChatFilter)
target_link_libraries(ChatServer dDatabase)
target_link_libraries(ChatServer dNet)
target_link_libraries(ChatServer raknet)
target_link_libraries(ChatServer ${MYSQL_LIB})
if(UNIX)
target_link_libraries(ChatServer pthread)
target_link_libraries(ChatServer dl)
endif(UNIX)
# Compiler flags: # Compiler flags:
# Disabled deprecated warnings as the MySQL includes have deprecated code in them. # Disabled deprecated warnings as the MySQL includes have deprecated code in them.
@ -433,13 +276,11 @@ if(UNIX)
if (__ggdb) if (__ggdb)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
endif() endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC")
endif(UNIX)
if(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC")
add_dependencies(MasterServer WorldServer) elseif(WIN32)
add_dependencies(MasterServer AuthServer) # Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
add_dependencies(MasterServer ChatServer) add_compile_options("/wd4267")
endif() endif()
# Finally, add the tests # Finally, add the tests

View File

@ -0,0 +1,9 @@
file(
GLOB SOURCES_AUTH
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_executable(AuthServer ${SOURCES_AUTH})
target_link_libraries(AuthServer ${SHARED_LIBS})

View File

@ -0,0 +1,8 @@
file(
GLOB SOURCES_DCHATFILTER
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_library(dChatFilter ${SOURCES_DCHATFILTER})

View File

@ -0,0 +1,10 @@
file(
GLOB SOURCES_CHAT
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_executable(ChatServer ${SOURCES_CHAT})
target_link_libraries(ChatServer dChatFilter)
target_link_libraries(ChatServer ${SHARED_LIBS})

10
dCommon/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
file(
GLOB SOURCES_DCOMMON
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_library(dCommon ${SOURCES_DCOMMON})
target_link_libraries(dCommon ZLIB::ZLIB)
target_link_libraries(dCommon libbcrypt)

10
dDatabase/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
file(
GLOB SOURCES_DDATABASE
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
Tables/*.cpp
)
add_library(dDatabase ${SOURCES_DDATABASE})
target_link_libraries(dDatabase sqlite3)

16
dGame/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
file(
GLOB SOURCES_DGAME
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
dBehaviors/*.cpp
dComponents/*.cpp
dGameMessages/*.cpp
dInventory/*.cpp
dMission/*.cpp
dEntity/*.cpp
dUtilities/*.cpp
../dScripts/*.cpp
)
add_library(dGame ${SOURCES_DGAME})

View File

@ -0,0 +1,15 @@
file(
GLOB SOURCES_MASTER
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_executable(MasterServer ${SOURCES_MASTER})
target_link_libraries(MasterServer ${SHARED_LIBS})
if(WIN32)
add_dependencies(MasterServer WorldServer)
add_dependencies(MasterServer AuthServer)
add_dependencies(MasterServer ChatServer)
endif()

9
dNet/CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
file(
GLOB SOURCES_DNET
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_library(dNet ${SOURCES_DNET})
target_link_libraries(dNet dCommon) # Needed because otherwise linker errors occur.

8
dPhysics/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
file(
GLOB SOURCES_DPHYSICS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_library(dPhysics ${SOURCES_DPHYSICS})

View File

@ -0,0 +1,17 @@
file(
GLOB SOURCES_WORLD
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_executable(WorldServer ${SOURCES_WORLD})
target_link_libraries(WorldServer dChatFilter)
target_link_libraries(WorldServer dGame)
target_link_libraries(WorldServer dZoneManager)
target_link_libraries(WorldServer dPhysics)
target_link_libraries(WorldServer detour)
target_link_libraries(WorldServer recast)
target_link_libraries(WorldServer tinyxml2)
target_link_libraries(WorldServer ${SHARED_LIBS})

View File

@ -0,0 +1,9 @@
# Source Code for dZoneManager
file(
GLOB SOURCES_DZM
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
*.cpp
)
add_library(dZoneManager ${SOURCES_DZM})

View File

@ -48,7 +48,6 @@ ${CMAKE_CURRENT_SOURCE_DIR}/SQLite/*.c
) )
# 3rdparty static libraries: # 3rdparty static libraries:
#add_library(zlib ${SOURCES_ZLIB})
add_library(raknet ${SOURCES_RAKNET}) add_library(raknet ${SOURCES_RAKNET})
add_library(tinyxml2 ${SOURCES_TINYXML2}) add_library(tinyxml2 ${SOURCES_TINYXML2})
add_library(detour ${SOURCES_DETOUR}) add_library(detour ${SOURCES_DETOUR})
@ -63,4 +62,8 @@ target_link_libraries(sqlite3 pthread dl m)
target_compile_options(sqlite3 PRIVATE "-Wno-return-local-addr" "-Wno-maybe-uninitialized") target_compile_options(sqlite3 PRIVATE "-Wno-return-local-addr" "-Wno-maybe-uninitialized")
target_compile_options(raknet PRIVATE "-Wno-write-strings" "-Wformat-overflow=0" "-Wformat=0") target_compile_options(raknet PRIVATE "-Wno-write-strings" "-Wformat-overflow=0" "-Wformat=0")
target_compile_options(libbcrypt PRIVATE "-Wno-implicit-function-declaration" "-Wno-int-conversion") target_compile_options(libbcrypt PRIVATE "-Wno-implicit-function-declaration" "-Wno-int-conversion")
endif(UNIX) endif()
if(WIN32)
target_link_libraries(raknet ws2_32)
endif()