SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.37k stars 472 forks source link

Missing backend includes #1122

Open danny-mhlv opened 5 months ago

danny-mhlv commented 5 months ago

Issue with CMake

Setup: OS: Ubuntu 22.04.3 LTS, Compiler: Clang 15.0.7 x86_64, C++ standard: c++20, CMake version: 3.28.1.

I've just started using SOCI for my project and encountered an odd error:

soci/include/soci/postgresql/soci-postgresql.h:22:10: fatal error: 'libpq-fe.h' file not found
[build] #include <libpq-fe.h>

As follows from the error - I am using PostgreSQL. Seems like main header of libpq++ is not included.

I'm going add_subdirectory(...) route in my project (I'm using git-submodules) and building a shared library version of SOCI (SOCI_SHARED set to ON). Before using SOCI I've read the documentation and checked out the examples. Nothing helped. Then I've started debugging CMake and figured out something.

In soci/cmake/SociBackend.cmake file:

if (SOCI_SHARED)
  add_library(${THIS_BACKEND_TARGET}
     SHARED
     ${THIS_BACKEND_SOURCES}
     ${THIS_BACKEND_HEADERS})
     add_library(Soci::${NAMEL} ALIAS ${THIS_BACKEND_TARGET})

  target_link_libraries(${THIS_BACKEND_TARGET}
    ${SOCI_CORE_TARGET}
    ${THIS_BACKEND_DEPENDS_LIBRARIES})
...

No include directories are provided for target (soci_postgresql in my case). Considering this - I've added:

target_include_directories(${THIS_BACKEND_TARGET} 
  PUBLIC
  ${THIS_BACKEND_DEPENDS_INCLUDE_DIRS})

I do understand, that I can as well include PostgreSQL's headers directly to my target, but wouldn't it be more convenient to include libpq-fe.h in SOCI (file: SociBackend.cmake), when initializing PostgreSQL's backend, considering it is already successfully locates said headers? Am I missing something?

For better understanding I've provided a minimal reproduction repository.

Thank you in advance.

vadz commented 5 months ago

Sorry, I don't understand how exactly does this differ from building SOCI directly which definitely does work. CMake is not my strong point (and I'm being euphemistic here), so it's quite possible that there is a bug in SOCI CMakefiles but I have no idea why would it happen only when it's included as a subdirectory, would you?

Krzmbrzl commented 4 months ago

This will be (or should be at least) resolved via #1118