I have the following Structure of my Project:
CMakeLists.txt
cmake
CMakeLists.txt
src
server
CMakeLists.txt
impl
server.cpp
CMakeLitst.txt
main.cpp
I am trying to include subproject src that’s depends in my case on PostgreSQL.
Cmake is configuring fine, but building subproject with error:
libpq-fe.h: No such file or directory.
PostgreSQL is finding ok and linking without subproject good.
These are the current CMakeLists.txt Files:
cmake/CmakeLists.txt:
FetchContent_Declare(ormpp
GIT_REPOSITORY https://github.com/qicosmos/ormpp.git
GIT_TAG 6f4f9dcb07487a4a7273eb9fa0d7535f6adf6963)
FetchContent_MakeAvailable(ormpp)
CMakeLists.txt:
find_package(PostgreSQL REQUIRED)
add_subdirectory(cmake)
add_subdirectory(src)
src/server/CMakeLists.txt:
add_executable(server main.cpp)
target_link_libraries(server PUBLIC PostgreSQL::PostgreSQL)
What do I have to change in my CMakeFiles to get subproject linking to work properly?
Thanks a lot in advance.
>Solution :
You need to add this:
target_include_directories(server SYSTEM "D:\postgreSQL\postgresql\include")
Or this, if you have multiple targets and just want to specify it once:
include_directories(SYSTEM "D:\postgreSQL\postgresql\include")
Ref: https://cmake.org/cmake/help/latest/command/target_include_directories.html