FindTIFF: Add TIFF_VERSION

This deprecates the TIFF_VERSION_STRING result variable.

Issue: #27088
This commit is contained in:
Peter Kokot
2025-08-04 21:02:30 +02:00
parent 185a4e6c5d
commit 8076414d2d
5 changed files with 71 additions and 16 deletions

View File

@@ -43,3 +43,6 @@ Find Modules
modules now provide their respective ``<PackageName>_VERSION`` result modules now provide their respective ``<PackageName>_VERSION`` result
variables. Previous ``<PACKAGENAME>_VERSION_STRING`` result variables variables. Previous ``<PACKAGENAME>_VERSION_STRING`` result variables
are deprecated. are deprecated.
* The :module:`FindTIFF` module now provides a ``TIFF_VERSION`` result
variable. The ``TIFF_VERSION_STRING`` result variable is deprecated.

View File

@@ -5,14 +5,25 @@
FindTIFF FindTIFF
-------- --------
Finds the `TIFF library <https://libtiff.gitlab.io/libtiff/>`_ (``libtiff``). Finds the `TIFF library <https://libtiff.gitlab.io/libtiff/>`_ (``libtiff``):
.. code-block:: cmake
find_package(TIFF [<version>] [COMPONENTS <components>...] [...])
This module also takes into account the upstream TIFF library's exported CMake This module also takes into account the upstream TIFF library's exported CMake
package configuration, if available. package configuration, if available.
Components Components
^^^^^^^^^^ ^^^^^^^^^^
This module supports the following components: This module supports optional components which can be specified with:
.. code-block:: cmake
find_package(TIFF [COMPONENTS <components>...])
Supported components include:
``CXX`` ``CXX``
.. versionadded:: 3.19 .. versionadded:: 3.19
@@ -20,12 +31,6 @@ This module supports the following components:
Optional component that ensures that the C++ wrapper library (``libtiffxx``) Optional component that ensures that the C++ wrapper library (``libtiffxx``)
is found. is found.
Components can be specified using the standard syntax:
.. code-block:: cmake
find_package(TIFF [COMPONENTS <components>...])
Imported Targets Imported Targets
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
@@ -51,10 +56,12 @@ Result Variables
This module defines the following variables: This module defines the following variables:
``TIFF_FOUND`` ``TIFF_FOUND``
Boolean indicating whether the TIFF is found. Boolean indicating whether (the requested version of) TIFF is found.
``TIFF_VERSION_STRING`` ``TIFF_VERSION``
The version of the TIFF library found. .. versionadded:: 4.2
The version of TIFF library found.
``TIFF_INCLUDE_DIRS`` ``TIFF_INCLUDE_DIRS``
The directory containing the TIFF headers. 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. 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 Examples
^^^^^^^^ ^^^^^^^^
@@ -244,7 +262,8 @@ if (Tiff_FOUND)
endif () endif ()
endif () 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) foreach (_TIFF_component IN LISTS TIFF_FIND_COMPONENTS)
set(TIFF_${_TIFF_component}_FOUND "${Tiff_${_TIFF_component}_FOUND}") set(TIFF_${_TIFF_component}_FOUND "${Tiff_${_TIFF_component}_FOUND}")
endforeach () endforeach ()
@@ -254,7 +273,7 @@ if (Tiff_FOUND)
find_package_handle_standard_args(TIFF find_package_handle_standard_args(TIFF
HANDLE_COMPONENTS HANDLE_COMPONENTS
REQUIRED_VARS Tiff_DIR REQUIRED_VARS Tiff_DIR
VERSION_VAR TIFF_VERSION_STRING) VERSION_VAR TIFF_VERSION)
cmake_policy(POP) cmake_policy(POP)
return () 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 .*") REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*")
string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" 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) unset(tiff_version_str)
endif() endif()
@@ -316,7 +336,7 @@ include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TIFF find_package_handle_standard_args(TIFF
HANDLE_COMPONENTS HANDLE_COMPONENTS
REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR
VERSION_VAR TIFF_VERSION_STRING) VERSION_VAR TIFF_VERSION)
if(TIFF_FOUND) if(TIFF_FOUND)
set(TIFF_LIBRARIES ${TIFF_LIBRARY}) set(TIFF_LIBRARIES ${TIFF_LIBRARY})

View File

@@ -126,6 +126,7 @@ foreach(
PNG PostgreSQL Protobuf PNG PostgreSQL Protobuf
Ruby RUBY Ruby RUBY
SDL SWIG SDL SWIG
TIFF
ZLIB ZLIB
) )
check_version_string(${VTEST} ${VTEST}_VERSION) check_version_string(${VTEST} ${VTEST}_VERSION)

View File

@@ -6,6 +6,10 @@ find_package(TIFF REQUIRED COMPONENTS CXX)
add_executable(test_tiff_tgt main.c) add_executable(test_tiff_tgt main.c)
target_link_libraries(test_tiff_tgt TIFF::TIFF) 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_test(NAME test_tiff_tgt COMMAND test_tiff_tgt)
add_executable(test_tiffxx_tgt main.cxx) 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) add_executable(test_tiff_var main.c)
target_include_directories(test_tiff_var PRIVATE ${TIFF_INCLUDE_DIRS}) target_include_directories(test_tiff_var PRIVATE ${TIFF_INCLUDE_DIRS})
target_link_libraries(test_tiff_var PRIVATE ${TIFF_LIBRARIES}) 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_test(NAME test_tiff_var COMMAND test_tiff_var)
add_executable(test_tiffxx_var main.cxx) add_executable(test_tiffxx_var main.cxx)

View File

@@ -1,4 +1,6 @@
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include <string.h>
#include <tiffio.h> #include <tiffio.h>
int main(void) int main(void)
@@ -8,5 +10,26 @@ int main(void)
TIFF* tiff = TIFFOpen("invalid.tiff", "r"); TIFF* tiff = TIFFOpen("invalid.tiff", "r");
assert(!tiff); 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;
} }