From 89e2819b296172eb1e4fbd19f9740882a06468fc Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 12 Feb 2020 17:06:39 +0000 Subject: [PATCH] use custom CMake module for PostgreSQL the module CMake provides cannot detect it in Travis Signed-off-by: Ivailo Monev --- cmake/modules/FindPostgreSQL.cmake | 43 ++++++++++++++++++++++++++++++ src/plugins/sqldrivers/psql/CMakeLists.txt | 4 +-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/FindPostgreSQL.cmake diff --git a/cmake/modules/FindPostgreSQL.cmake b/cmake/modules/FindPostgreSQL.cmake new file mode 100644 index 000000000..f9a11d88f --- /dev/null +++ b/cmake/modules/FindPostgreSQL.cmake @@ -0,0 +1,43 @@ +# - Try to find PostgreSQL database engine +# Once done this will define +# +# POSTGRESQL_FOUND - system has PostgreSQL database engine +# POSTGRESQL_INCLUDES - the PostgreSQL database engine include directory +# POSTGRESQL_LIBRARIES - the libraries needed to use PostgreSQL database engine +# +# Copyright (c) 2020, Ivailo Monev, +# +# Redistribution and use is allowed according to the terms of the BSD license. + +if(POSTGRESQL_INCLUDES AND POSTGRESQL_LIBRARIES) + set(POSTGRESQL_FIND_QUIETLY TRUE) +endif() + +if(NOT WIN32) + include(FindPkgConfig) + pkg_check_modules(PC_POSTGRESQL QUIET libpq) + + set(POSTGRESQL_INCLUDES ${PC_POSTGRESQL_INCLUDE_DIRS}) + set(POSTGRESQL_LIBRARIES ${PC_POSTGRESQL_LIBRARIES}) +endif() + +if(NOT POSTGRESQL_INCLUDES OR NOT POSTGRESQL_LIBRARIES) + find_path(POSTGRESQL_INCLUDES + NAMES libpq-fe.h + PATH_SUFFIXES postgresql + HINTS $ENV{POSTGRESQLDIR}/include + ) + + find_library(POSTGRESQL_LIBRARIES + NAMES pq + HINTS $ENV{POSTGRESQLDIR}/lib + ) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PostgreSQL + VERSION_VAR PC_POSTGRESQL_VERSION + REQUIRED_VARS POSTGRESQL_LIBRARIES POSTGRESQL_INCLUDES +) + +mark_as_advanced(POSTGRESQL_INCLUDES POSTGRESQL_LIBRARIES) diff --git a/src/plugins/sqldrivers/psql/CMakeLists.txt b/src/plugins/sqldrivers/psql/CMakeLists.txt index cbc60fd77..5e5b1b422 100644 --- a/src/plugins/sqldrivers/psql/CMakeLists.txt +++ b/src/plugins/sqldrivers/psql/CMakeLists.txt @@ -7,12 +7,12 @@ set(PSQLDRIVER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/qsql_psql.cpp ) -include_directories(${PostgreSQL_INCLUDE_DIRS}) +include_directories(${POSTGRESQL_INCLUDES}) katie_setup_target(qsqlpsqlplugin ${PSQLDRIVER_SOURCES} ${PSQLDRIVER_HEADERS}) add_library(qsqlpsqlplugin MODULE ${qsqlpsqlplugin_SOURCES}) -target_link_libraries(qsqlpsqlplugin KtSql ${PostgreSQL_LIBRARIES}) +target_link_libraries(qsqlpsqlplugin KtSql ${POSTGRESQL_LIBRARIES}) set_target_properties(qsqlpsqlplugin PROPERTIES OUTPUT_NAME qsqlpsql) install( -- 2.11.0