]> granicus.if.org Git - graphviz/commitdiff
fix inability to include and use gvc.h from a parent CMake project
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 15 Sep 2021 00:46:30 +0000 (17:46 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 21 Sep 2021 00:01:39 +0000 (17:01 -0700)
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 <gvc/gvc.h>
  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
lib/gvc/CMakeLists.txt

index 2c657102034275fc9f73373b518c5ba4f25033fd..5898e90aca15ba8517919f2c26252cd28504995b 100644 (file)
@@ -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
 
index 038636469416588797a84297aaffe4ce9438ede7..745841176f2173309385aa855d514976101c869d 100644 (file)
@@ -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
+    $<BUILD_INTERFACE:${GRAPHVIZ_LIB_DIR}>
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+    $<BUILD_INTERFACE:${GRAPHVIZ_LIB_DIR}/cdt>
+    $<BUILD_INTERFACE:${GRAPHVIZ_LIB_DIR}/cgraph>
+    $<BUILD_INTERFACE:${GRAPHVIZ_LIB_DIR}/common>
+    $<BUILD_INTERFACE:${GRAPHVIZ_LIB_DIR}/pathplan>
+    $<INSTALL_INTERFACE:include/graphviz>
+  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