hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 360 forks source link

Support adding libconfig with cmake `add_subdirectory` #154

Open dandrestor opened 4 years ago

dandrestor commented 4 years ago

Right now the libconfig project cannot be added as a sub-project in a larger cmake codebase. The problem is that the header files are not automatically found during the build phase. Please support this by adding something along the lines of:

diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index e0d4730..c05eaf1 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -82,10 +82,12 @@ endif()

 target_include_directories(${libname}
   PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
+        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
   )

 target_include_directories(${libname}++
   PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
+        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
   )

 install(TARGETS ${libname}
Challanger524 commented 2 months ago

first library to not to support add_subdirectory :(

Challanger524 commented 2 months ago

Looks like this is fixed/addressed

target_include_directories(${libname} PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_include_directories(${libname}++ PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)