From dcc5ed93775b66339c14f297e35c91f1cf3dd43a Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 14 Sep 2021 17:46:30 -0700 Subject: [PATCH] fix inability to include and use gvc.h from a parent CMake project When attempting to declare a dependency on gvc when using Graphviz as a CMake subproject, the include path necessary to compile gvc headers would not be propagated to dependent targets. The result would be a compilation error when the transitive includes of gvc.h could not be found. To validate this change, create an empty directory and add the following CMakeLists.txt: project(foo) add_subdirectory(graphviz) add_executable(bar main.c) target_link_libraries(bar gvc) Add the following main.c: #include int main(void) { return 0; } Clone Graphviz into the subdirectory 'graphviz'. Then the standard CMake steps: mkdir build cd build cmake .. make Note that Graphviz dependencies and then 'bar' are correctly built. I am not a CMake expert; this was written based on my best guess of what Graphviz should be doing according to the CMake docs. Assuming this is correct, other Graphviz targets probably need similar fixes. Fixes #1477, #2109. --- CHANGELOG.md | 4 ++++ lib/gvc/CMakeLists.txt | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6571020..5898e90ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - the CMake build system installs gzipped man pages if `gzip` is available #1883 +- CMake projects using Graphviz as a subproject (`add_subdirectory`) can now + link against and use `gvc`. ### Fixed @@ -18,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 projects #2119 - compile failures with a C++20-compatible toolchain #2122 - compile errors on macOS when using Bison 3.8 #2127 +- Make Graphviz buildable as a cmake subproject/subdirectory #1477 +- Header not found in Cmake project #2109 ## [2.49.0] – 2021-08-28 diff --git a/lib/gvc/CMakeLists.txt b/lib/gvc/CMakeLists.txt index 038636469..745841176 100644 --- a/lib/gvc/CMakeLists.txt +++ b/lib/gvc/CMakeLists.txt @@ -36,14 +36,17 @@ add_library(gvc SHARED gvc.def ) -target_include_directories(gvc PRIVATE - ${GRAPHVIZ_LIB_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} +target_include_directories(gvc + PUBLIC + $ + $ + $ + $ + $ + $ + $ + PRIVATE ${TOP_SOURCE_DIR} - ${GRAPHVIZ_LIB_DIR}/cdt - ${GRAPHVIZ_LIB_DIR}/cgraph - ${GRAPHVIZ_LIB_DIR}/common - ${GRAPHVIZ_LIB_DIR}/pathplan ) target_link_libraries(gvc PRIVATE -- 2.40.0