]> granicus.if.org Git - graphviz/commitdiff
CMake: detect and enable extra optional GD features with gdlib-config
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 8 Feb 2022 03:53:58 +0000 (14:53 +1100)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 15 Feb 2022 20:38:41 +0000 (07:38 +1100)
This replicates some logic from the Autotools build system, enabling output
formats like `png:gd`. Note that this only enables `png:gd` on CentOS because
other packaging ecosystems do not seem to include `gdlib-config`.

Gitlab: #1786

ci/tests.py
cmake/FindGD.cmake
config-cmake.h.in

index 549c2d32878df984ac7dda48c79bfcdab92d6d2a..b700ded7ca619396cc7deb836fe746a400768355 100644 (file)
@@ -5,9 +5,11 @@ test cases that are only relevant to run in CI
 """
 
 import os
+from pathlib import Path
 import platform
 import shutil
 import sys
+from typing import Dict
 import pytest
 
 sys.path.append(os.path.join(os.path.dirname(__file__), "../rtest"))
@@ -19,6 +21,30 @@ def is_cmake() -> bool:
   """
   return os.getenv("build_system") == "cmake"
 
+def _freedesktop_os_release() -> Dict[str, str]:
+  """
+  polyfill for `platform.freedesktop_os_release`
+  """
+  release = {}
+  os_release = Path("/etc/os-release")
+  if os_release.exists():
+    with open(os_release, "rt", encoding="utf-8") as f:
+      for line in f.readlines():
+        if line.startswith("#") or "=" not in line:
+          continue
+        key, _, value = (x.strip() for x in line.partition("="))
+        # remove quotes
+        if len(value) >= 2 and value[0] == '"' and value[-1] == '"':
+          value = value[1:-1]
+        release[key] = value
+  return release
+
+def is_centos() -> bool:
+  """
+  is the current CI environment CentOS-based?
+  """
+  return _freedesktop_os_release().get("ID") == "centos"
+
 @pytest.mark.parametrize("binary", [
   "acyclic",
   "bcomps",
@@ -149,7 +175,7 @@ def check_that_tool_does_not_exist(tool, os_id):
   assert shutil.which(tool) is None, f"{tool} has been resurrected in the " \
     f'{os.getenv("build_system")} build on {os_id}. Please remove skip.'
 
-@pytest.mark.xfail(is_cmake(),
+@pytest.mark.xfail(is_cmake() and not is_centos(),
                    reason="png:gd unavailable when built with CMake",
                    strict=True) # FIXME
 def test_1786():
index 9a3ed17214ab93b861b672d01ed77d4e49f35640..d2de4e71ffa091b646c84411c1655c6f79627d20 100644 (file)
@@ -17,3 +17,37 @@ mark_as_advanced(GD_INCLUDE_DIR GD_LIBRARY GD_RUNTIME_LIBRARY)
 set(GD_INCLUDE_DIRS ${GD_INCLUDE_DIR})
 set(GD_LIBRARIES ${GD_LIBRARY})
 set(GD_RUNTIME_LIBRARIES ${GD_RUNTIME_LIBRARY})
+
+find_program(GDLIB_CONFIG gdlib-config)
+if(GDLIB_CONFIG)
+  message(STATUS "Found gdlib-config: ${GDLIB_CONFIG}")
+  execute_process(COMMAND ${GDLIB_CONFIG} --features
+                  RESULT_VARIABLE GDLIB_CONFIG_EXIT_STATUS
+                  OUTPUT_VARIABLE GD_FEATURES
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+  if(NOT GDLIB_CONFIG_EXIT_STATUS EQUAL 0)
+    message(FATAL_ERROR "Failed to query GD features")
+  endif()
+  message(STATUS "Detected GD features: ${GD_FEATURES}")
+  string(REPLACE " " ";" GD_FEATURES_LIST ${GD_FEATURES})
+  if("GD_PNG" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_PNG 1)
+  endif()
+  if("GD_JPEG" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_JPEG 1)
+  endif()
+  if("GD_XPM" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_XPM 1)
+  endif()
+  if("GD_FONTCONFIG" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_FONTCONFIG 1)
+  endif()
+  if("GD_FREETYPE" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_FREETYPE 1)
+  endif()
+  if("GD_GIF" IN_LIST GD_FEATURES_LIST)
+    set(HAVE_GD_GIF 1)
+  endif()
+else()
+  message(WARNING "gdlib-config not found; skipping feature checks")
+endif()
index 6003517a19ea536eead9cfee2561ec2dbe19127f..3406882cb527fc15fc74dbd68fa97b6d1079d679 100644 (file)
@@ -44,6 +44,12 @@ typedef int ssize_t;
 #cmakedefine HAVE_ANN
 #cmakedefine HAVE_EXPAT
 #cmakedefine HAVE_LIBGD
+#cmakedefine HAVE_GD_PNG
+#cmakedefine HAVE_GD_JPEG
+#cmakedefine HAVE_GD_XPM
+#cmakedefine HAVE_GD_FONTCONFIG
+#cmakedefine HAVE_GD_FREETYPE
+#cmakedefine HAVE_GD_GIF
 #cmakedefine HAVE_ZLIB
 
 // Values