drogonframework / drogonframework/drogon
USE_POSTGRESQL symbol not defined even if Postgres detected
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
I am installing Drogon with Postgres support. I have the development headers and libraries. CMake detects Postgres and sets `pg_FOUND` correctly. Postgres is enabled with `option(USE_POSTGRESQL "Enable PostgreSQL" ON)`. However, the preprocessor symbol `USE_POSTGRESQL` is *not* set. Thus in `DbClientManager::addDbClient()` in `orm_lib/src/DBClientManager.cc` the code to add the Postgres connection configuration to the `dbInfos_` vector is not compiled and the fatal error is produced at runtime instead.
To resolve the problem, I manually added the `USE_POSTGRESQL` definition to `CMakeLists.txt` around line 616:
```cmake
if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
if (pg_FOUND)
message(STATUS "Enable PostgreSQL")
option(USE_POSTGRESQL "Enable PostgreSQL" ON)
add_definitions(-DUSE_POSTGRESQL)
else (pg_FOUND)
option(USE_POSTGRESQL "Disable PostgreSQL" OFF)
endif (pg_FOUND)
```
I confirmed the absence of the `USE_POSTGRESQL` symbol was the issue by adding `static_assert` and `assert` macros to the Drogon source code, rebuilding, and observing that compilation and runtime failures occurred in the expected places.
Once I added the definition directly to `CMakeLists.txt` I was able to connect to my Postgres server without any further issues.
I am using Ubuntu 22.04 with gcc 15 and CMake 4.
Contributor guide
Assessment
This issue has not been assessed yet.