Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CMake how to link subproject with external library

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading