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: test using FetchContent for dependencies #1651

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ docker/configs
# Third party libraries
thirdparty/mysql/
thirdparty/mysql_linux/
thirdparty/backtrace/
thirdparty/magic_enum/
thirdparty/recastnavigation/
thirdparty/tinyxml2/
CMakeVariables.txt

# Build folders
Expand Down
12 changes: 0 additions & 12 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
[submodule "thirdparty/cpp-httplib"]
path = thirdparty/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
[submodule "thirdparty/tinyxml2"]
path = thirdparty/tinyxml2
url = https://github.com/leethomason/tinyxml2
[submodule "thirdparty/recastnavigation"]
path = thirdparty/recastnavigation
url = https://github.com/recastnavigation/recastnavigation
[submodule "thirdparty/libbcrypt"]
path = thirdparty/libbcrypt
url = https://github.com/trusch/libbcrypt.git
[submodule "thirdparty/mariadb-connector-cpp"]
path = thirdparty/mariadb-connector-cpp
url = https://github.com/mariadb-corporation/mariadb-connector-cpp.git
ignore = dirty
[submodule "thirdparty/magic_enum"]
path = thirdparty/magic_enum
url = https://github.com/Neargye/magic_enum.git
54 changes: 49 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,53 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

find_package(MariaDB)

# Fetch third party dependencies
set(DLU_THIRDPARTY_SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty)

include(FetchContent)
FetchContent_Declare(
backtrace
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/backtrace
GIT_REPOSITORY https://github.com/ianlancetaylor/libbacktrace.git
)
FetchContent_Declare(
bcrypt
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/libbcrypt
GIT_REPOSITORY https://github.com/trusch/libbcrypt.git
GIT_TAG d6523c370de6e724ce4ec703e2449b5b028ea3b1
)
FetchContent_Declare(
magic_enum
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/magic_enum
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
GIT_TAG v0.9.7
)
FetchContent_Declare(
Recast
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/recastnavigation
GIT_REPOSITORY https://github.com/recastnavigation/recastnavigation.git
GIT_TAG v1.6.0
)
FetchContent_Declare(
tinyxml2
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/tinyxml2
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
GIT_TAG 9.0.0
)
FetchContent_MakeAvailable(magic_enum Recast tinyxml2)

# Turn off tinyxml2 testing
set(tinyxml2_BUILD_TESTING OFF)

include(CMakePrintHelpers)
cmake_print_properties(TARGETS magic_enum Recast tinyxml2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES)

# Create a /resServer directory
make_directory(${CMAKE_BINARY_DIR}/resServer)

Expand Down Expand Up @@ -251,10 +298,7 @@ include_directories(
"tests/dGameTests/dComponentsTests"

SYSTEM
"thirdparty/magic_enum/include/magic_enum"
"thirdparty/raknet/Source"
"thirdparty/tinyxml2"
"thirdparty/recastnavigation"
"thirdparty/SQLite"
"thirdparty/cpplinq"
"thirdparty/cpp-httplib"
Expand All @@ -272,7 +316,7 @@ if(MSVC)
# add_compile_options("/W4")
# Want to enable warnings eventually, but WAY too much noise right now
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options("-Wuninitialized" "-Wold-style-cast")
add_compile_options("-Wuninitialized" "-Wold-style-cast" "-Wstrict-aliasing")
else()
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.")
endif()
Expand Down Expand Up @@ -341,7 +385,7 @@ target_precompile_headers(

target_precompile_headers(
tinyxml2 PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${PROJECT_SOURCE_DIR}/thirdparty/tinyxml2/tinyxml2.h>"
"$<$<COMPILE_LANGUAGE:CXX>:${tinyxml2_SOURCE_DIR}/tinyxml2.h>"
)

if(${ENABLE_TESTING})
Expand Down
1 change: 1 addition & 0 deletions dCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ else ()
endif ()

target_link_libraries(dCommon
PUBLIC magic_enum
PRIVATE ZLIB::ZLIB bcrypt tinyxml2
INTERFACE dDatabase)
2 changes: 1 addition & 1 deletion dCommon/dEnums/MessageType/Game.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>

#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

namespace MessageType {
enum class Game : uint16_t {
Expand Down
2 changes: 1 addition & 1 deletion dCommon/dEnums/MessageType/World.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>

#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

namespace MessageType {
enum class World : uint32_t {
Expand Down
2 changes: 1 addition & 1 deletion dCommon/dEnums/StringifiedEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __STRINGIFIEDENUM_H__

#include <string>
#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

namespace StringifiedEnum {
template<typename T>
Expand Down
3 changes: 1 addition & 2 deletions dCommon/dEnums/eInventoryType.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#define __EINVENTORYTYPE__H__

#include <cstdint>

#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

static const uint8_t NUMBER_OF_INVENTORIES = 17;
/**
Expand Down
2 changes: 1 addition & 1 deletion dDatabase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_subdirectory(GameDatabase)
add_library(dDatabase STATIC "MigrationRunner.cpp")
target_include_directories(dDatabase PUBLIC ".")
target_link_libraries(dDatabase
PUBLIC dDatabaseCDClient dDatabaseGame)
PUBLIC magic_enum dDatabaseCDClient dDatabaseGame)
2 changes: 1 addition & 1 deletion dGame/dBehaviors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
"VerifyBehavior.cpp")

add_library(dBehaviors OBJECT ${DGAME_DBEHAVIORS_SOURCES})
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics)
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics magic_enum tinyxml2)
target_include_directories(dBehaviors PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # via BehaviorContext.h
PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion dGame/dComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ target_include_directories(dComponents PUBLIC "."
)
target_precompile_headers(dComponents REUSE_FROM dGameBase)

target_link_libraries(dComponents INTERFACE dBehaviors)
target_link_libraries(dComponents PUBLIC magic_enum tinyxml2 INTERFACE dBehaviors)
2 changes: 1 addition & 1 deletion dGame/dGameMessages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(DGAME_DGAMEMESSAGES_SOURCES

add_library(dGameMessages OBJECT ${DGAME_DGAMEMESSAGES_SOURCES})
target_link_libraries(dGameMessages
PUBLIC dDatabase
PUBLIC magic_enum tinyxml2 dDatabase
INTERFACE dGameBase # TradingManager
)
target_include_directories(dGameMessages PUBLIC "."
Expand Down
1 change: 1 addition & 0 deletions dGame/dInventory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ target_include_directories(dInventory PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
"${PROJECT_SOURCE_DIR}/dZoneManager" # via Item.cpp
)
target_link_libraries(dInventory PUBLIC magic_enum tinyxml2)
target_precompile_headers(dInventory REUSE_FROM dGameBase)
# Workaround for compiler bug where the optimized code could result in a memcpy of 0 bytes, even though that isnt possible.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97185
Expand Down
2 changes: 1 addition & 1 deletion dGame/dMission/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(DGAME_DMISSION_SOURCES
"MissionTask.cpp")

add_library(dMission OBJECT ${DGAME_DMISSION_SOURCES})
target_link_libraries(dMission PUBLIC dDatabase)
target_link_libraries(dMission PUBLIC tinyxml2 dDatabase)
target_include_directories(dMission PUBLIC "."
PRIVATE
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
Expand Down
2 changes: 1 addition & 1 deletion dGame/dPropertyBehaviors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ foreach(file ${DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES})
endforeach()

add_library(dPropertyBehaviors OBJECT ${DGAME_DPROPERTYBEHAVIORS_SOURCES})
target_link_libraries(dPropertyBehaviors PRIVATE dDatabaseCDClient)
target_link_libraries(dPropertyBehaviors PUBLIC tinyxml2 PRIVATE dDatabaseCDClient)
target_include_directories(dPropertyBehaviors PUBLIC "." "ControlBehaviorMessages"
PRIVATE
"${PROJECT_SOURCE_DIR}/dCommon/dClient" # ControlBehaviors.cpp uses AssetManager
Expand Down
2 changes: 1 addition & 1 deletion dNavigation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ target_include_directories(dNavigation PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dEntity"
"${PROJECT_SOURCE_DIR}/dNavigation/dTerrain" # via dNavMesh.cpp
)
target_link_libraries(dNavigation PRIVATE Detour Recast dCommon)
target_link_libraries(dNavigation PUBLIC tinyxml2 PRIVATE Detour Recast dCommon)
2 changes: 1 addition & 1 deletion dNet/AuthPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define _VARIADIC_MAX 10
#include "dCommonVars.h"
#include "dNetCommon.h"
#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

enum class ServerType : uint32_t;
enum class eLoginResponse : uint8_t;
Expand Down
2 changes: 1 addition & 1 deletion dNet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(DNET_SOURCES "AuthPackets.cpp"
"ZoneInstanceManager.cpp")

add_library(dNet STATIC ${DNET_SOURCES})
target_link_libraries(dNet PRIVATE bcrypt MD5)
target_link_libraries(dNet PUBLIC magic_enum PRIVATE bcrypt MD5)
target_include_directories(dNet PRIVATE
"${PROJECT_SOURCE_DIR}/dCommon"
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
Expand Down
2 changes: 1 addition & 1 deletion dWorldServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target_include_directories(WorldServer PRIVATE
"${PROJECT_SOURCE_DIR}/dServer" # BinaryPathFinder.h
)

target_link_libraries(WorldServer ${COMMON_LIBRARIES}
target_link_libraries(WorldServer PUBLIC ${COMMON_LIBRARIES}
dScripts
dGameBase
dComponents
Expand Down
2 changes: 1 addition & 1 deletion tests/dCommonTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ add_custom_command(TARGET dCommonTests POST_BUILD
endif()

# Link needed libraries
target_link_libraries(dCommonTests ${COMMON_LIBRARIES} GTest::gtest_main)
target_link_libraries(dCommonTests ${COMMON_LIBRARIES} GTest::gtest_main magic_enum)

# Copy test files to testing directory
add_subdirectory(TestBitStreams)
Expand Down
2 changes: 1 addition & 1 deletion tests/dCommonTests/dEnumsTests/MagicEnumTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Game.h"
#include "MessageType/Game.h"
#include "MessageType/World.h"
#include "magic_enum.hpp"
#include <magic_enum/magic_enum.hpp>

#define ENUM_EQ(e, y, z)\
LOG("%s %s", StringifiedEnum::ToString(static_cast<e>(y)).data(), #z);\
Expand Down
2 changes: 1 addition & 1 deletion tests/dGameTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_custom_command(TARGET dGameTests POST_BUILD
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()

target_link_libraries(dGameTests ${COMMON_LIBRARIES} GTest::gtest_main
target_link_libraries(dGameTests ${COMMON_LIBRARIES} magic_enum GTest::gtest_main
dGame dScripts dPhysics Detour Recast tinyxml2 dWorldServer dZoneManager dChatFilter dNavigation)

# Discover the tests
Expand Down
30 changes: 8 additions & 22 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
# Source Code for recast
add_subdirectory(recastnavigation)

# Turn off tinyxml2 testing
set(tinyxml2_BUILD_TESTING OFF)
# Source Code for tinyxml2
add_subdirectory(tinyxml2)
# add_subdirectory(recastnavigation)

# Source Code for libbcrypt. Uses a file glob instead to get around Windows build issues.
file(
GLOB SOURCES_LIBBCRYPT
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${CMAKE_CURRENT_SOURCE_DIR}/libbcrypt/src/*.c
file(
GLOB SOURCES_LIBBCRYPT
LIST_DIRECTORIES false
RELATIVE "${DLU_THIRDPARTY_SOURCE_DIR}"
${DLU_THIRDPARTY_SOURCE_DIR}/libbcrypt/src/*.c
)

add_library(bcrypt ${SOURCES_LIBBCRYPT})

Check failure on line 12 in thirdparty/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

No SOURCES given to target: bcrypt

Check failure on line 12 in thirdparty/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

No SOURCES given to target: bcrypt

Check failure on line 12 in thirdparty/CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

No SOURCES given to target: bcrypt

# Because we are not using the libbcrypt CMakeLists.txt, we need to include these headers for the library to use.
# fortunately they are only needed for building the libbcrypt directory and nothing else, so these are marked private.

if(NOT WIN32)
target_include_directories(bcrypt PRIVATE "libbcrypt/include/bcrypt")
target_include_directories(bcrypt PRIVATE "libbcrypt/include/bcrypt")
endif()

# Need to define this on Clang and GNU for 'strdup' support
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L")
target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L")
endif()

target_include_directories(bcrypt INTERFACE "libbcrypt/include")
Expand All @@ -34,21 +29,12 @@
# Source code for sqlite
add_subdirectory(SQLite)

# Source code for magic_enum
add_subdirectory(magic_enum)

# Create our third party library objects
add_subdirectory(raknet)

# Download Backtrace if configured
if(UNIX AND NOT APPLE)
include(FetchContent)
if (${INCLUDE_BACKTRACE} AND ${COMPILE_BACKTRACE})
FetchContent_Declare(
backtrace
GIT_REPOSITORY https://github.com/ianlancetaylor/libbacktrace.git
)

FetchContent_MakeAvailable(backtrace)

if (NOT EXISTS ${backtrace_SOURCE_DIR}/.libs)
Expand Down
1 change: 0 additions & 1 deletion thirdparty/libbcrypt
Submodule libbcrypt deleted from d6523c
1 change: 0 additions & 1 deletion thirdparty/magic_enum
Submodule magic_enum deleted from e55b9b
1 change: 0 additions & 1 deletion thirdparty/recastnavigation
Submodule recastnavigation deleted from c5cbd5
1 change: 0 additions & 1 deletion thirdparty/tinyxml2
Submodule tinyxml2 deleted from a97739
Loading