From: Matthew Fernandez Date: Tue, 8 Feb 2022 03:53:58 +0000 (+1100) Subject: CMake: detect and enable extra optional GD features with gdlib-config X-Git-Tag: 3.0.0~28^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffbd293687685fbb1a8520f35231f3ea04cd4d05;p=graphviz CMake: detect and enable extra optional GD features with gdlib-config 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 --- diff --git a/ci/tests.py b/ci/tests.py index 549c2d328..b700ded7c 100644 --- a/ci/tests.py +++ b/ci/tests.py @@ -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(): diff --git a/cmake/FindGD.cmake b/cmake/FindGD.cmake index 9a3ed1721..d2de4e71f 100644 --- a/cmake/FindGD.cmake +++ b/cmake/FindGD.cmake @@ -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() diff --git a/config-cmake.h.in b/config-cmake.h.in index 6003517a1..3406882cb 100644 --- a/config-cmake.h.in +++ b/config-cmake.h.in @@ -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