Skip to content

Commit

Permalink
add switch for different backends
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC committed Dec 7, 2024
1 parent 2a89e67 commit fc17a9a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 28 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

find_package(MariaDB)
if(${DLU_MYSQL_DATABASE} EQUAL 1)
find_package(MariaDB)
endif()

# Create a /resServer directory
make_directory(${CMAKE_BINARY_DIR}/resServer)
Expand Down
1 change: 0 additions & 1 deletion dCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ target_include_directories(dCommon
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase"
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"
)

if (UNIX)
Expand Down
37 changes: 23 additions & 14 deletions dDatabase/GameDatabase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ set(DDATABASE_GAMEDATABASE_SOURCES
"Database.cpp"
)

# add_subdirectory(MySQL)
#
# foreach(file ${DDATABSE_DATABSES_MYSQL_SOURCES})
# set(DDATABASE_GAMEDATABASE_SOURCES ${DDATABASE_GAMEDATABASE_SOURCES} "MySQL/${file}")
# endforeach()

add_subdirectory(SQLite)

foreach(file ${DDATABSE_DATABSES_SQLITE_SOURCES})
set(DDATABASE_GAMEDATABASE_SOURCES ${DDATABASE_GAMEDATABASE_SOURCES} "SQLite/${file}")
endforeach()
if(${DLU_MYSQL_DATABASE} EQUAL 1)
add_subdirectory(MySQL)

foreach(file ${DDATABSE_DATABSES_MYSQL_SOURCES})
set(DDATABASE_GAMEDATABASE_SOURCES ${DDATABASE_GAMEDATABASE_SOURCES} "MySQL/${file}")
endforeach()
set(LinkingWithMySQL true)
elseif(${DLU_SQLITE_DATABASE} EQUAL 1)
add_subdirectory(SQLite)

foreach(file ${DDATABSE_DATABSES_SQLITE_SOURCES})
set(DDATABASE_GAMEDATABASE_SOURCES ${DDATABASE_GAMEDATABASE_SOURCES} "SQLite/${file}")
endforeach()
else()
message(FATAL_ERROR "No database specified. Please use DLU_SQLITE_DATABASE or DLU_MYSQL_DATABASE.")
endif()

add_subdirectory(TestSQL)

Expand All @@ -26,9 +31,13 @@ target_include_directories(dDatabaseGame PUBLIC "."
"${PROJECT_SOURCE_DIR}/dCommon"
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
)

target_link_libraries(dDatabaseGame
PUBLIC MariaDB::ConnCpp
INTERFACE dCommon)
INTERFACE dCommon PRIVATE sqlite3)

if(${DLU_MYSQL_DATABASE} EQUAL 1)
target_link_libraries(dDatabaseGame PUBLIC MariaDB::ConnCpp)
endif()

# Glob together all headers that need to be precompiled
file(
Expand All @@ -37,7 +46,7 @@ file(
ITables/*.h
)

target_compile_definitions(dDatabaseGame PRIVATE DLU_SQLITE_DATABASE="${DLU_SQLITE_DATABASE}" DLU_MYSQL_DATABASE="${DLU_MYSQL_DATABASE}")
target_compile_definitions(dDatabaseGame PRIVATE DLU_SQLITE_DATABASE=${DLU_SQLITE_DATABASE} DLU_MYSQL_DATABASE=${DLU_MYSQL_DATABASE})

# Need to specify to use the CXX compiler language here or else we get errors including <string>.
target_precompile_headers(
Expand Down
4 changes: 2 additions & 2 deletions dDatabase/GameDatabase/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "SQLiteDatabase.h"
#include "DluAssert.h"

#if defined(DLU_SQLITE_DATABASE)
#if DLU_SQLITE_DATABASE == 1
# define DluGameDatabase SQLiteDatabase
# include "SQLiteDatabase.h"
#elif defined(DLU_MYSQL_DATABASE)
#elif DLU_MYSQL_DATABASE == 1
# define DluGameDatabase MySQLDatabase
# include "MySQLDatabase.h"
#else
Expand Down
1 change: 0 additions & 1 deletion dGame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ target_include_directories(dGameBase PUBLIC "." "dEntity"
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"
# dPhysics
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include"
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include"
Expand Down
1 change: 0 additions & 1 deletion dGame/dComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ target_include_directories(dComponents PUBLIC "."
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"
# dPhysics (via dpWorld.h)
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Recast/Include"
"${PROJECT_SOURCE_DIR}/thirdparty/recastnavigation/Detour/Include"
Expand Down
1 change: 0 additions & 1 deletion dNet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ target_include_directories(dNet PRIVATE
"${PROJECT_SOURCE_DIR}/dDatabase/CDClientDatabase/CDClientTables"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase"
"${PROJECT_SOURCE_DIR}/dDatabase/GameDatabase/ITables"
"${PROJECT_SOURCE_DIR}/thirdparty/mariadb-connector-cpp/include"

"${PROJECT_SOURCE_DIR}/dGame" # UserManager.h
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
Expand Down
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ if(APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path")
endif()

add_custom_target(conncpp_tests
${CMAKE_COMMAND} -E copy $<TARGET_FILE:MariaDB::ConnCpp> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
if(${DLU_MYSQL_DATABASE} EQUAL 1)
add_custom_target(conncpp_tests
${CMAKE_COMMAND} -E copy $<TARGET_FILE:MariaDB::ConnCpp> ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()

# Add the subdirectories
add_subdirectory(dCommonTests)
Expand Down
7 changes: 5 additions & 2 deletions tests/dCommonTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ list(APPEND DCOMMONTEST_SOURCES ${DENUMS_TESTS})

# Set our executable
add_executable(dCommonTests ${DCOMMONTEST_SOURCES})
add_dependencies(dCommonTests conncpp_tests)

if(${DLU_MYSQL_DATABASE} EQUAL 1)
add_dependencies(dCommonTests conncpp_tests)
endif()

# Apple needs some special linkage for the mariadb connector for tests.
if(APPLE)
if(APPLE AND ${DLU_MYSQL_DATABASE} EQUAL 1)
add_custom_command(TARGET dCommonTests POST_BUILD
COMMAND otool ARGS -l dCommonTests
COMMAND otool ARGS -L dCommonTests
Expand Down
7 changes: 5 additions & 2 deletions tests/dGameTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ file(COPY ${COMPONENT_TEST_DATA} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

# Add the executable. Remember to add all tests above this!
add_executable(dGameTests ${DGAMETEST_SOURCES})
add_dependencies(dGameTests conncpp_tests)

if(${DLU_MYSQL_DATABASE} EQUAL 1)
add_dependencies(dGameTests conncpp_tests)
endif()

# Apple needs some special linkage for the mariadb connector for tests.
if(APPLE)
if(APPLE AND ${DLU_MYSQL_DATABASE} EQUAL 1)
add_custom_command(TARGET dGameTests POST_BUILD
COMMAND install_name_tool ARGS -change libmariadbcpp.dylib @rpath/libmariadbcpp.dylib dGameTests
COMMAND otool ARGS -L dGameTests
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/SQLite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set (SQLITE3_SOURCES
"sqlite3.c"
)

add_library (sqlite3 ${SQLITE3_SOURCES})
add_library(sqlite3 ${SQLITE3_SOURCES})

if(UNIX)
# Add warning disable flags and link Unix libraries to sqlite3
Expand Down

0 comments on commit fc17a9a

Please sign in to comment.