diff --git a/Help/release/dev/find-modules.rst b/Help/release/dev/find-modules.rst index f691c74620..fffc8cfa90 100644 --- a/Help/release/dev/find-modules.rst +++ b/Help/release/dev/find-modules.rst @@ -43,3 +43,6 @@ Find Modules modules now provide their respective ``_VERSION`` result variables. Previous ``_VERSION_STRING`` result variables are deprecated. + +* The :module:`FindTIFF` module now provides a ``TIFF_VERSION`` result + variable. The ``TIFF_VERSION_STRING`` result variable is deprecated. diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake index c756b93bfb..c1fa7898d4 100644 --- a/Modules/FindTIFF.cmake +++ b/Modules/FindTIFF.cmake @@ -5,14 +5,25 @@ FindTIFF -------- -Finds the `TIFF library `_ (``libtiff``). +Finds the `TIFF library `_ (``libtiff``): + +.. code-block:: cmake + + find_package(TIFF [] [COMPONENTS ...] [...]) + This module also takes into account the upstream TIFF library's exported CMake package configuration, if available. Components ^^^^^^^^^^ -This module supports the following components: +This module supports optional components which can be specified with: + +.. code-block:: cmake + + find_package(TIFF [COMPONENTS ...]) + +Supported components include: ``CXX`` .. versionadded:: 3.19 @@ -20,12 +31,6 @@ This module supports the following components: Optional component that ensures that the C++ wrapper library (``libtiffxx``) is found. -Components can be specified using the standard syntax: - -.. code-block:: cmake - - find_package(TIFF [COMPONENTS ...]) - Imported Targets ^^^^^^^^^^^^^^^^ @@ -51,10 +56,12 @@ Result Variables This module defines the following variables: ``TIFF_FOUND`` - Boolean indicating whether the TIFF is found. + Boolean indicating whether (the requested version of) TIFF is found. -``TIFF_VERSION_STRING`` - The version of the TIFF library found. +``TIFF_VERSION`` + .. versionadded:: 4.2 + + The version of TIFF library found. ``TIFF_INCLUDE_DIRS`` The directory containing the TIFF headers. @@ -90,6 +97,17 @@ The following cache variables may also be set: The path to the TIFFXX library for debug configurations. +Deprecated Variables +^^^^^^^^^^^^^^^^^^^^ + +The following variables are provided for backward compatibility: + +``TIFF_VERSION_STRING`` + .. deprecated:: 4.2 + Superseded by the ``TIFF_VERSION``. + + The version of TIFF library found. + Examples ^^^^^^^^ @@ -244,7 +262,8 @@ if (Tiff_FOUND) endif () endif () endif () - set(TIFF_VERSION_STRING "${Tiff_VERSION}") + set(TIFF_VERSION "${Tiff_VERSION}") + set(TIFF_VERSION_STRING "${TIFF_VERSION}") foreach (_TIFF_component IN LISTS TIFF_FIND_COMPONENTS) set(TIFF_${_TIFF_component}_FOUND "${Tiff_${_TIFF_component}_FOUND}") endforeach () @@ -254,7 +273,7 @@ if (Tiff_FOUND) find_package_handle_standard_args(TIFF HANDLE_COMPONENTS REQUIRED_VARS Tiff_DIR - VERSION_VAR TIFF_VERSION_STRING) + VERSION_VAR TIFF_VERSION) cmake_policy(POP) return () @@ -280,7 +299,8 @@ if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*") string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" - "\\1" TIFF_VERSION_STRING "${tiff_version_str}") + "\\1" TIFF_VERSION "${tiff_version_str}") + set(TIFF_VERSION_STRING "${TIFF_VERSION}") unset(tiff_version_str) endif() @@ -316,7 +336,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(TIFF HANDLE_COMPONENTS REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR - VERSION_VAR TIFF_VERSION_STRING) + VERSION_VAR TIFF_VERSION) if(TIFF_FOUND) set(TIFF_LIBRARIES ${TIFF_LIBRARY}) diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt index 38b6cbf2a5..388339d565 100644 --- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt +++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt @@ -126,6 +126,7 @@ foreach( PNG PostgreSQL Protobuf Ruby RUBY SDL SWIG + TIFF ZLIB ) check_version_string(${VTEST} ${VTEST}_VERSION) diff --git a/Tests/FindTIFF/Test/CMakeLists.txt b/Tests/FindTIFF/Test/CMakeLists.txt index c734b253a9..0ca6ac372f 100644 --- a/Tests/FindTIFF/Test/CMakeLists.txt +++ b/Tests/FindTIFF/Test/CMakeLists.txt @@ -6,6 +6,10 @@ find_package(TIFF REQUIRED COMPONENTS CXX) add_executable(test_tiff_tgt main.c) target_link_libraries(test_tiff_tgt TIFF::TIFF) +target_compile_definitions( + test_tiff_tgt + PRIVATE CMAKE_EXPECTED_TIFF_VERSION="${TIFF_VERSION}" +) add_test(NAME test_tiff_tgt COMMAND test_tiff_tgt) add_executable(test_tiffxx_tgt main.cxx) @@ -15,6 +19,10 @@ add_test(NAME test_tiffxx_tgt COMMAND test_tiffxx_tgt) add_executable(test_tiff_var main.c) target_include_directories(test_tiff_var PRIVATE ${TIFF_INCLUDE_DIRS}) target_link_libraries(test_tiff_var PRIVATE ${TIFF_LIBRARIES}) +target_compile_definitions( + test_tiff_var + PRIVATE CMAKE_EXPECTED_TIFF_VERSION="${TIFF_VERSION}" +) add_test(NAME test_tiff_var COMMAND test_tiff_var) add_executable(test_tiffxx_var main.cxx) diff --git a/Tests/FindTIFF/Test/main.c b/Tests/FindTIFF/Test/main.c index bce4a3e63f..5230eac58c 100644 --- a/Tests/FindTIFF/Test/main.c +++ b/Tests/FindTIFF/Test/main.c @@ -1,4 +1,6 @@ #include +#include +#include #include int main(void) @@ -8,5 +10,26 @@ int main(void) TIFF* tiff = TIFFOpen("invalid.tiff", "r"); assert(!tiff); - return 0; + char const* info = TIFFGetVersion(); + char const* version_prefix = "Version "; + char const* start = strstr(info, version_prefix); + char version_str[16]; + + if (start) { + start += strlen(version_prefix); + int major, minor, patch; + + if (sscanf(start, "%d.%d.%d", &major, &minor, &patch) == 3) { + snprintf(version_str, sizeof(version_str), "%d.%d.%d", major, minor, + patch); + printf("Found TIFF version %s, expected version %s\n", version_str, + CMAKE_EXPECTED_TIFF_VERSION); + + return strcmp(version_str, CMAKE_EXPECTED_TIFF_VERSION); + } + } + + fprintf(stderr, + "TIFF version not found or TIFF version could not be parsed\n"); + return 1; }