From 8a538ca23ce9ec8647145179b1640ce7e360830b Mon Sep 17 00:00:00 2001 From: dizzy Date: Mon, 27 Aug 2007 20:02:18 +0000 Subject: [PATCH] Added PostgreSQL storage support option for cmake for Unices (on Windows we will need some registry readings or lookup directory within src path). Also fixed issues with mysql/sqlite finding scripts that were ignoring some attributes (like REQUIRED which makes it error if it cannot find it). --- pvpgn/CMakeLists.txt | 1 + pvpgn/ConfigureChecks.cmake | 3 ++ pvpgn/cmake/Modules/FindMySQL.cmake | 12 +++--- pvpgn/cmake/Modules/FindPostgreSQL.cmake | 53 ++++++++++++++++++++++++ pvpgn/cmake/Modules/FindSQLite3.cmake | 12 +++--- pvpgn/src/CMakeLists.txt | 3 ++ pvpgn/src/bnetd/CMakeLists.txt | 8 ++-- 7 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 pvpgn/cmake/Modules/FindPostgreSQL.cmake diff --git a/pvpgn/CMakeLists.txt b/pvpgn/CMakeLists.txt index ee3af2e..5265d8a 100644 --- a/pvpgn/CMakeLists.txt +++ b/pvpgn/CMakeLists.txt @@ -20,6 +20,7 @@ endif(WIN32) #storage backends flags option(WITH_MYSQL "include MySQL user accounts support" OFF) option(WITH_SQLITE3 "include SQLite3 user accounts support" OFF) +option(WITH_PGSQL "include PostgreSQL user accounts support" OFF) include(ConfigureChecks.cmake) diff --git a/pvpgn/ConfigureChecks.cmake b/pvpgn/ConfigureChecks.cmake index 488f8ef..7af1a70 100644 --- a/pvpgn/ConfigureChecks.cmake +++ b/pvpgn/ConfigureChecks.cmake @@ -43,6 +43,9 @@ endif(WITH_MYSQL) if(WITH_SQLITE3) find_package(SQLite3 REQUIRED) endif(WITH_SQLITE3) +if(WITH_PGSQL) + find_package(PostgreSQL REQUIRED) +endif(WITH_PGSQL) # if any of nsl or socket exists we need to make sure the following tests # use them otherwise some functions may not be found diff --git a/pvpgn/cmake/Modules/FindMySQL.cmake b/pvpgn/cmake/Modules/FindMySQL.cmake index 2e8a166..4e0074d 100644 --- a/pvpgn/cmake/Modules/FindMySQL.cmake +++ b/pvpgn/cmake/Modules/FindMySQL.cmake @@ -7,7 +7,7 @@ IF (MYSQL_INCLUDE_DIR) # Already in cache, be silent - SET(MYSQL_FIND_QUIETLY TRUE) + SET(MySQL_FIND_QUIETLY TRUE) ENDIF (MYSQL_INCLUDE_DIR) FIND_PATH(MYSQL_INCLUDE_DIR mysql.h @@ -43,17 +43,17 @@ ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY) IF (MYSQL_FOUND) - IF (NOT MYSQL_FIND_QUIETLY) + IF (NOT MySQL_FIND_QUIETLY) MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}") - ENDIF (NOT MYSQL_FIND_QUIETLY) + ENDIF (NOT MySQL_FIND_QUIETLY) ELSE (MYSQL_FOUND) - IF (MYSQL_FIND_REQUIRED) + IF (MySQL_FIND_REQUIRED) MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.") MESSAGE(FATAL_ERROR "Could NOT find MySQL library") - ENDIF (MYSQL_FIND_REQUIRED) + ENDIF (MySQL_FIND_REQUIRED) ENDIF (MYSQL_FOUND) MARK_AS_ADVANCED( MYSQL_LIBRARY MYSQL_INCLUDE_DIR - ) +) diff --git a/pvpgn/cmake/Modules/FindPostgreSQL.cmake b/pvpgn/cmake/Modules/FindPostgreSQL.cmake new file mode 100644 index 0000000..86658fe --- /dev/null +++ b/pvpgn/cmake/Modules/FindPostgreSQL.cmake @@ -0,0 +1,53 @@ +# - Find libpq +# Find the native PostgreSQL includes and library +# +# PGSQL_INCLUDE_DIR - where to find libpq-fe.h, etc. +# PGSQL_LIBRARIES - List of libraries when using PGSQL. +# PGSQL_FOUND - True if PGSQL found. + +IF (PGSQL_INCLUDE_DIR) + # Already in cache, be silent + SET(PostgreSQL_FIND_QUIETLY TRUE) +ENDIF (PGSQL_INCLUDE_DIR) + +FIND_PATH(PGSQL_INCLUDE_DIR libpq-fe.h + /usr/local/pgsql/include + /usr/local/include/pgsql + /usr/local/include + /usr/include/pgsql + /usr/include + /usr/pgsql/include +) + +SET(PGSQL_NAMES pq) +SET(PGSQL_SEARCH_LIB_PATHS + /usr/local/pgsql/lib /usr/local/lib /usr/lib +) +FIND_LIBRARY(PGSQL_LIBRARY + NAMES ${PGSQL_NAMES} + PATHS ${PGSQL_SEARCH_LIB_PATHS} +) + +IF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + SET(PGSQL_FOUND TRUE) + SET( PGSQL_LIBRARIES ${PGSQL_LIBRARY} ) +ELSE (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + SET(PGSQL_FOUND FALSE) + SET( PGSQL_LIBRARIES ) +ENDIF (PGSQL_INCLUDE_DIR AND PGSQL_LIBRARY) + +IF (PGSQL_FOUND) + IF (NOT PostgreSQL_FIND_QUIETLY) + MESSAGE(STATUS "Found PostgreSQL: ${PGSQL_LIBRARY}") + ENDIF (NOT PostgreSQL_FIND_QUIETLY) +ELSE (PGSQL_FOUND) + IF (PostgreSQL_FIND_REQUIRED) + MESSAGE(STATUS "Looked for PostgreSQL libraries named ${PGSQL_NAMES}.") + MESSAGE(FATAL_ERROR "Could NOT find PostgreSQL library") + ENDIF (PostgreSQL_FIND_REQUIRED) +ENDIF (PGSQL_FOUND) + +MARK_AS_ADVANCED( + PGSQL_LIBRARY + PGSQL_INCLUDE_DIR +) diff --git a/pvpgn/cmake/Modules/FindSQLite3.cmake b/pvpgn/cmake/Modules/FindSQLite3.cmake index 1d772c9..e99e486 100644 --- a/pvpgn/cmake/Modules/FindSQLite3.cmake +++ b/pvpgn/cmake/Modules/FindSQLite3.cmake @@ -7,7 +7,7 @@ IF (SQLITE3_INCLUDE_DIR) # Already in cache, be silent - SET(SQLITE3_FIND_QUIETLY TRUE) + SET(SQLite3_FIND_QUIETLY TRUE) ENDIF (SQLITE3_INCLUDE_DIR) FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h @@ -32,17 +32,17 @@ ELSE (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) ENDIF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY) IF (SQLITE3_FOUND) - IF (NOT SQLITE3_FIND_QUIETLY) + IF (NOT SQLite3_FIND_QUIETLY) MESSAGE(STATUS "Found SQLite3: ${SQLITE3_LIBRARY}") - ENDIF (NOT SQLITE3_FIND_QUIETLY) + ENDIF (NOT SQLite3_FIND_QUIETLY) ELSE (SQLITE3_FOUND) - IF (SQLITE3_FIND_REQUIRED) + IF (SQLite3_FIND_REQUIRED) MESSAGE(STATUS "Looked for SQLite3 libraries named ${SQLITE3_NAMES}.") MESSAGE(FATAL_ERROR "Could NOT find SQLite3 library") - ENDIF (SQLITE3_FIND_REQUIRED) + ENDIF (SQLite3_FIND_REQUIRED) ENDIF (SQLITE3_FOUND) MARK_AS_ADVANCED( SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR - ) +) diff --git a/pvpgn/src/CMakeLists.txt b/pvpgn/src/CMakeLists.txt index 93cbbe5..9389268 100644 --- a/pvpgn/src/CMakeLists.txt +++ b/pvpgn/src/CMakeLists.txt @@ -25,6 +25,9 @@ endif(MYSQL_FOUND) if(SQLITE3_FOUND) add_definitions("-DWITH_SQL_SQLITE3") endif(SQLITE3_FOUND) +if(PGSQL_FOUND) + add_definitions("-DWITH_SQL_PGSQL") +endif(PGSQL_FOUND) subdirs(compat common win32 tinycdb bntrackd client bniutils bnpass) diff --git a/pvpgn/src/bnetd/CMakeLists.txt b/pvpgn/src/bnetd/CMakeLists.txt index 35ba8c6..47b9b1d 100644 --- a/pvpgn/src/bnetd/CMakeLists.txt +++ b/pvpgn/src/bnetd/CMakeLists.txt @@ -1,5 +1,7 @@ # add aditional includes corresponding to the additional libraries bellow -include_directories(${ZLIB_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR} ${SQLITE3_INCLUDE_DIR}) +include_directories(${ZLIB_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR} + ${SQLITE3_INCLUDE_DIR} ${PGSQL_INCLUDE_DIR} +) set(BNETD_SOURCES account.cpp account.h account_wrap.cpp account_wrap.h adbanner.cpp @@ -44,7 +46,7 @@ set(BNETD_GUI_SOURCES add_executable(bnetd ${BNETD_SOURCES} ${BNETD_CONSOLE_RESOURCES}) target_link_libraries(bnetd common compat win32 tinycdb ${NETWORK_LIBRARIES} - ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES}) + ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES}) install(TARGETS bnetd DESTINATION ${SBINDIR}) # build the GUI version too @@ -54,6 +56,6 @@ if(WITH_WIN32_GUI) ${BNETD_GUI_RESOURCES}) set_target_properties(bnetd_gui PROPERTIES COMPILE_FLAGS "-DWIN32_GUI") target_link_libraries(bnetd_gui common_gui compat win32_gui tinycdb ${NETWORK_LIBRARIES} - ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES}) + ${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES} ${PGSQL_LIBRARIES}) install(TARGETS bnetd_gui DESTINATION ${SBINDIR}) endif(WITH_WIN32_GUI)