mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 11:49:55 -06:00
FindDevIL: Add DevIL_VERSION
This module now provides a DevIL_VERSION result variable and supports the `<version>` argument in the find_package() call. Version range can be also specified. Fixes: #26858
This commit is contained in:
6
Help/release/dev/FindDevIL.rst
Normal file
6
Help/release/dev/FindDevIL.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
FindDevIL
|
||||
---------
|
||||
|
||||
* The :module:`FindDevIL` module now provides a ``DevIL_VERSION`` result
|
||||
variable and version argument and version range can be specified by
|
||||
:command:`find_package`, when finding the DevIL package.
|
||||
@@ -9,7 +9,11 @@ Finds the Developer's Image Library, `DevIL <https://openil.sourceforge.net/>`_:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
find_package(DevIL [...])
|
||||
find_package(DevIL [<version>] [...])
|
||||
|
||||
.. versionadded:: 4.2
|
||||
Support for the ``<version>`` argument in the :command:`find_package`
|
||||
call. Version can be also specified as a range.
|
||||
|
||||
The DevIL package internally consists of the following libraries, all
|
||||
distributed as part of the same release:
|
||||
@@ -62,8 +66,13 @@ Result Variables
|
||||
This module defines the following variables:
|
||||
|
||||
``DevIL_FOUND``
|
||||
Boolean indicating whether the DevIL package is found, including the IL and
|
||||
ILU libraries.
|
||||
Boolean indicating whether the (requested version of) DevIL package is
|
||||
found, including the IL and ILU libraries.
|
||||
|
||||
``DevIL_VERSION``
|
||||
.. versionadded:: 4.2
|
||||
|
||||
The version of the DevIL found.
|
||||
|
||||
``DevIL_ILUT_FOUND``
|
||||
.. versionadded:: 3.21
|
||||
@@ -113,8 +122,8 @@ Linking against the Image Library Utility Toolkit (ILUT):
|
||||
target_link_libraries(app PRIVATE DevIL::ILUT)
|
||||
#]=======================================================================]
|
||||
|
||||
# TODO: Add version support.
|
||||
# Tested under Linux and Windows (MSVC)
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
@@ -123,35 +132,62 @@ find_path(IL_INCLUDE_DIR il.h
|
||||
DOC "The path to the directory that contains il.h"
|
||||
)
|
||||
|
||||
#message("IL_INCLUDE_DIR is ${IL_INCLUDE_DIR}")
|
||||
|
||||
find_library(IL_LIBRARIES
|
||||
NAMES IL DEVIL
|
||||
PATH_SUFFIXES libx32 lib64 lib lib32
|
||||
DOC "The file that corresponds to the base il library."
|
||||
)
|
||||
|
||||
#message("IL_LIBRARIES is ${IL_LIBRARIES}")
|
||||
|
||||
find_library(ILUT_LIBRARIES
|
||||
NAMES ILUT
|
||||
PATH_SUFFIXES libx32 lib64 lib lib32
|
||||
DOC "The file that corresponds to the il (system?) utility library."
|
||||
)
|
||||
|
||||
#message("ILUT_LIBRARIES is ${ILUT_LIBRARIES}")
|
||||
|
||||
find_library(ILU_LIBRARIES
|
||||
NAMES ILU
|
||||
PATH_SUFFIXES libx32 lib64 lib lib32
|
||||
DOC "The file that corresponds to the il utility library."
|
||||
)
|
||||
|
||||
#message("ILU_LIBRARIES is ${ILU_LIBRARIES}")
|
||||
# Get version.
|
||||
block(PROPAGATE DevIL_VERSION)
|
||||
if(IL_INCLUDE_DIR AND EXISTS "${IL_INCLUDE_DIR}/il.h")
|
||||
set(regex "^[ \t]*#[ \t]*define[ \t]+IL_VERSION[ \t]+([0-9]+)[ \t]*$")
|
||||
|
||||
file(STRINGS ${IL_INCLUDE_DIR}/il.h result REGEX "${regex}")
|
||||
|
||||
if(result MATCHES "${regex}")
|
||||
set(DevIL_VERSION "${CMAKE_MATCH_1}")
|
||||
|
||||
math(EXPR DevIL_VERSION_MAJOR "${DevIL_VERSION} / 100")
|
||||
math(EXPR DevIL_VERSION_MINOR "${DevIL_VERSION} / 10 % 10")
|
||||
math(EXPR DevIL_VERSION_PATCH "${DevIL_VERSION} % 10")
|
||||
|
||||
set(DevIL_VERSION "")
|
||||
foreach(part MAJOR MINOR PATCH)
|
||||
if(DevIL_VERSION)
|
||||
string(APPEND ".${DevIL_VERSION_${part}}")
|
||||
else()
|
||||
set(DevIL_VERSION "${DevIL_VERSION_${part}}")
|
||||
endif()
|
||||
|
||||
set(
|
||||
DevIL_VERSION
|
||||
"${DevIL_VERSION_MAJOR}.${DevIL_VERSION_MINOR}.${DevIL_VERSION_PATCH}"
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
endblock()
|
||||
|
||||
find_package_handle_standard_args(
|
||||
DevIL
|
||||
REQUIRED_VARS IL_LIBRARIES ILU_LIBRARIES IL_INCLUDE_DIR
|
||||
VERSION_VAR DevIL_VERSION
|
||||
HANDLE_VERSION_RANGE
|
||||
)
|
||||
|
||||
find_package_handle_standard_args(DevIL DEFAULT_MSG
|
||||
IL_LIBRARIES ILU_LIBRARIES
|
||||
IL_INCLUDE_DIR)
|
||||
# provide legacy variable for compatibility
|
||||
set(IL_FOUND ${DevIL_FOUND})
|
||||
|
||||
@@ -187,3 +223,5 @@ if(DevIL_FOUND)
|
||||
target_link_libraries(DevIL::ILUT INTERFACE DevIL::ILU)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
cmake_policy(POP)
|
||||
|
||||
@@ -115,7 +115,7 @@ foreach(
|
||||
ALSA Armadillo
|
||||
BISON Boost BZip2 BZIP2
|
||||
CUDA Cups
|
||||
Doxygen DOXYGEN
|
||||
DevIL Doxygen DOXYGEN
|
||||
EXPAT
|
||||
FLEX Freetype
|
||||
Gettext GIF GTK2
|
||||
|
||||
@@ -4,19 +4,21 @@ include(CTest)
|
||||
|
||||
find_package(DevIL)
|
||||
|
||||
#FIXME: check version too.
|
||||
# add_definitions(
|
||||
# -DCMAKE_EXPECTED_SDL_VERSION_MAJOR=${SDL_VERSION_MAJOR}
|
||||
# -DCMAKE_EXPECTED_SDL_VERSION_MINOR=${SDL_VERSION_MINOR}
|
||||
# -DCMAKE_EXPECTED_SDL_VERSION_PATCH=${SDL_VERSION_PATCH})
|
||||
|
||||
add_executable(test_devil_var main.c)
|
||||
target_include_directories(test_devil_var PRIVATE ${IL_INCLUDE_DIRS})
|
||||
target_link_libraries(test_devil_var PRIVATE ${IL_LIBRARIES})
|
||||
target_compile_definitions(
|
||||
test_devil_var
|
||||
PRIVATE CMAKE_EXPECTED_DEVIL_VERSION="${DevIL_VERSION}"
|
||||
)
|
||||
add_test(NAME test_devil_var COMMAND test_devil_var)
|
||||
|
||||
add_executable(test_devil_il_tgt main.c)
|
||||
target_link_libraries(test_devil_il_tgt DevIL::IL)
|
||||
target_compile_definitions(
|
||||
test_devil_il_tgt
|
||||
PRIVATE CMAKE_EXPECTED_DEVIL_VERSION="${DevIL_VERSION}"
|
||||
)
|
||||
add_test(NAME test_devil_il_tgt COMMAND test_devil_il_tgt)
|
||||
|
||||
add_executable(test_devil_ilu_tgt main_ilu.c)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <IL/il.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -6,5 +8,16 @@ int main(void)
|
||||
ilInit();
|
||||
|
||||
ilShutDown();
|
||||
return 0;
|
||||
|
||||
int version = IL_VERSION;
|
||||
int major = version / 100;
|
||||
int minor = version / 10 % 10;
|
||||
int patch = version % 10;
|
||||
char version_string[100];
|
||||
snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor,
|
||||
patch);
|
||||
|
||||
printf("Found DevIL version %s, expected version %s\n", version_string,
|
||||
CMAKE_EXPECTED_DEVIL_VERSION);
|
||||
return strcmp(version_string, CMAKE_EXPECTED_DEVIL_VERSION);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user