From 9608717a84d83e0bad0a0855cf3479d585c86613 Mon Sep 17 00:00:00 2001 From: Martin Ejdestig Date: Wed, 21 Oct 2020 04:22:49 +0200 Subject: Make it easier to use libdlt when building DLT as a CMake subproject (#254) By calling target_include_directories() for the dlt target in src/lib/. CMake filters out duplicate include paths. So even if the include directories are already added with include_directories() in the top-level CMakeLists.txt, they are not duplicated when the compiler is invoked. For example, with this patch, the following works: [~/Source/foo]$ ls bar CMakeLists.txt dlt-daemon [~/Source/foo]$ cat CMakeLists.txt cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(foo) add_subdirectory(dlt-daemon) add_subdirectory(bar) [~/Source/foo]$ cat bar/CMakeLists.txt cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(bar) add_executable(bar main.cpp) target_link_libraries(bar dlt) install(TARGETS bar RUNTIME DESTINATION bin) bar/main.cpp contains the example from the top of doc/dlt_for_developers.md that does "#include " and then uses the DLT logging macros. Signed-off-by: Martin Ejdestig --- src/lib/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index b28b7af..ff06584 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -45,6 +45,7 @@ else() endif() target_link_libraries(dlt ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) +target_include_directories(dlt PUBLIC ${PROJECT_SOURCE_DIR}/include/dlt ${PROJECT_BINARY_DIR}/include/dlt) set_target_properties(dlt PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) install(TARGETS dlt -- cgit v1.2.1