pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.04k stars 2.11k forks source link

Postgres CMakeList.txt #4540

Open datajango opened 2 months ago

datajango commented 2 months ago

Describe the bug On Ubuntu 22.04, the poco/cmake/FindPostgreSQL.cmake and /home/tony/dev/tony/poco/Data/PostgreSQL/CMakeLists.txt files contains a bug. I used... libpq-dev

apt show libpq-dev
Package: libpq-dev
Version: 14.11-0ubuntu0.22.04.1
Priority: optional
Section: libdevel
Source: postgresql-14
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian PostgreSQL Maintainers <team+postgresql@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 586 kB
Depends: libpq5 (= 14.11-0ubuntu0.22.04.1), libssl-dev
Suggests: postgresql-doc-14
Homepage: http://www.postgresql.org/
Download-Size: 147 kB
APT-Manual-Installed: yes
APT-Sources: http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
Description: header files for libpq5 (PostgreSQL library)
 Header files and static library for compiling C programs to link
 with the libpq library in order to communicate with a PostgreSQL
 database backend.
 .
 PostgreSQL is an object-relational SQL database management system.

N: There is 1 additional record. Please use the '-a' switch to see it

To Reproduce cd cmake-build cmake ..

 cmake ..
-- Checking for C++17 compiler
-- Checking for C++17 compiler - available
-- Could NOT find APR (missing: APR_INCLUDE_DIR APR_LIBRARY) 
-- Could NOT find APRUTIL (missing: APRUTIL_INCLUDE_DIR APRUTIL_LIBRARY) 
-- Could NOT find Apache2 (missing: APACHE2_INCLUDE_DIR) 
-- Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR) 
-- Building without tests & samples
-- Using internal sqlite, zlib, pcre2, expat, ...
-- SQLite Support Enabled
-- MySQL Support Disabled
-- PostgreSQL Support Enabled
-- ODBC Support Disabled
-- CMake 3.22.1 successfully configured Poco using Unix Makefiles generator
-- Poco package version: 1.13.3
-- Building dynamic libraries
-- [cmake] Installation target path: /usr/local
-- [cmake] Build for OS type:      Linux
-- [cmake] Build for OS version:   6.5.0-27-generic
-- [cmake] Build for CPU type:     x86_64
-- [cmake] Build type:             RelWithDebInfo
-- [cmake] Build with cxx flags:   -O2 -g -DNDEBUG 
-- [cmake] Build with c flags:     -O2 -g -DNDEBUG 
-- [cmake] C++ symbol visibility:  
-- Building: Encodings
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: MongoDB
-- Building: Redis
-- Building: Prometheus
-- Building: JWT
-- Building: NetSSL_OpenSSL
-- Building: Crypto
-- Building: Data
-- Building: Data/SQLite
-- Building: Data/PostgreSQL
-- Building: ActiveRecord
-- Building: ActiveRecordCompiler
-- Building: Zip
-- Building: PageCompiler
-- Building: File2Page
-- Configuring done
CMake Error at Data/PostgreSQL/CMakeLists.txt:15 (add_library):
  Target "DataPostgreSQL" links to target "PostgreSQL::client" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

Expected behavior

cmake ..
-- Checking for C++17 compiler
-- Checking for C++17 compiler - available
-- Could NOT find APR (missing: APR_INCLUDE_DIR APR_LIBRARY) 
-- Could NOT find APRUTIL (missing: APRUTIL_INCLUDE_DIR APRUTIL_LIBRARY) 
-- Could NOT find Apache2 (missing: APACHE2_INCLUDE_DIR) 
-- Could NOT find ODBC (missing: ODBC_LIBRARY ODBC_INCLUDE_DIR) 
-- Building without tests & samples
-- Using internal sqlite, zlib, pcre2, expat, ...
-- SQLite Support Enabled
-- MySQL Support Disabled
-- PostgreSQL Support Enabled
-- ODBC Support Disabled
-- CMake 3.22.1 successfully configured Poco using Unix Makefiles generator
-- Poco package version: 1.13.3
-- Building dynamic libraries
-- [cmake] Installation target path: /usr/local
-- [cmake] Build for OS type:      Linux
-- [cmake] Build for OS version:   6.5.0-27-generic
-- [cmake] Build for CPU type:     x86_64
-- [cmake] Build type:             RelWithDebInfo
-- [cmake] Build with cxx flags:   -O2 -g -DNDEBUG 
-- [cmake] Build with c flags:     -O2 -g -DNDEBUG 
-- [cmake] C++ symbol visibility:  
-- Building: Encodings
-- Building: XML
-- Building: JSON
-- Building: Util
-- Building: Net
-- Building: MongoDB
-- Building: Redis
-- Building: Prometheus
-- Building: JWT
-- Building: NetSSL_OpenSSL
-- Building: Crypto
-- Building: Data
-- Building: Data/SQLite
-- Building: Data/PostgreSQL
-- Building: ActiveRecord
-- Building: ActiveRecordCompiler
-- Building: Zip
-- Building: PageCompiler
-- Building: File2Page
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tony/dev/tony/poco/cmake-build

Please add relevant environment information:

Additional context Fixes:

poco/cmake/FindPostgreSQL.cmake

if(PostgreSQL_FOUND AND NOT TARGET PostgreSQL::PostgreSQL)
    add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED)
    set_target_properties(PostgreSQL::PostgreSQL PROPERTIES
        IMPORTED_LOCATION "${PostgreSQL_LIBRARY}"
        INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR}"
    )
endif()

poco/Data/PostgreSQL/CMakeLists.txt

target_link_libraries(DataPostgreSQL PUBLIC Poco::Data PostgreSQL::PostgreSQL)
target_include_directories(DataPostgreSQL
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
andrewauclair commented 2 months ago

You can submit a pull request with the change. That'll be the fastest way to get the issue fixed.