diff --git a/CMakeLists.txt b/CMakeLists.txt index 20af0c22c..4549c5001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/dCommon/CMakeLists.txt b/dCommon/CMakeLists.txt index d020ff72f..18fda0ed7 100644 --- a/dCommon/CMakeLists.txt +++ b/dCommon/CMakeLists.txt @@ -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) diff --git a/dDatabase/GameDatabase/CMakeLists.txt b/dDatabase/GameDatabase/CMakeLists.txt index 11fcffb7e..8f9e5c8fd 100644 --- a/dDatabase/GameDatabase/CMakeLists.txt +++ b/dDatabase/GameDatabase/CMakeLists.txt @@ -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) @@ -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( @@ -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 . target_precompile_headers( diff --git a/dDatabase/GameDatabase/Database.cpp b/dDatabase/GameDatabase/Database.cpp index 9477d1a62..56df5e856 100644 --- a/dDatabase/GameDatabase/Database.cpp +++ b/dDatabase/GameDatabase/Database.cpp @@ -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 diff --git a/dGame/CMakeLists.txt b/dGame/CMakeLists.txt index 26eb859a9..661c36886 100644 --- a/dGame/CMakeLists.txt +++ b/dGame/CMakeLists.txt @@ -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" diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index c60e135fe..c6e72f290 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -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" diff --git a/dNet/CMakeLists.txt b/dNet/CMakeLists.txt index 15cdda42b..172aee205 100644 --- a/dNet/CMakeLists.txt +++ b/dNet/CMakeLists.txt @@ -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" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 24adec61d..01c00f3b0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,8 +10,10 @@ if(APPLE) set(CMAKE_INSTALL_RPATH "@executable_path") endif() -add_custom_target(conncpp_tests - ${CMAKE_COMMAND} -E copy $ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +if(${DLU_MYSQL_DATABASE} EQUAL 1) + add_custom_target(conncpp_tests + ${CMAKE_COMMAND} -E copy $ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +endif() # Add the subdirectories add_subdirectory(dCommonTests) diff --git a/tests/dCommonTests/CMakeLists.txt b/tests/dCommonTests/CMakeLists.txt index ef7c4cba9..80f3dcdf3 100644 --- a/tests/dCommonTests/CMakeLists.txt +++ b/tests/dCommonTests/CMakeLists.txt @@ -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 diff --git a/tests/dGameTests/CMakeLists.txt b/tests/dGameTests/CMakeLists.txt index e1c294331..2a2a5c441 100644 --- a/tests/dGameTests/CMakeLists.txt +++ b/tests/dGameTests/CMakeLists.txt @@ -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 diff --git a/thirdparty/SQLite/CMakeLists.txt b/thirdparty/SQLite/CMakeLists.txt index e745c46aa..4a9e9311b 100644 --- a/thirdparty/SQLite/CMakeLists.txt +++ b/thirdparty/SQLite/CMakeLists.txt @@ -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