From 1f6649b7d118e9de2a51c9e48b5fea527f608fc1 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 17 Apr 2018 22:53:26 +0200 Subject: FindJPEG: Add version detection and associated test update and docs --- Modules/FindJPEG.cmake | 27 ++++++++++++++++++++++++++- Tests/CMakeOnly/AllFindModules/CMakeLists.txt | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index 04e4d20..9c047e5 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -18,12 +18,16 @@ # where to find jpeglib.h, etc. # ``JPEG_LIBRARIES`` # the libraries needed to use JPEG. +# ``JPEG_VERSION`` +# the version of the JPEG library found # # Cache variables # ^^^^^^^^^^^^^^^ # # The following cache variables may also be set: # +# ``JPEG_INCLUDE_DIR`` +# where to find jpeglib.h, etc. # ``JPEG_LIBRARY`` # where to find the JPEG library. @@ -32,8 +36,29 @@ find_path(JPEG_INCLUDE_DIR jpeglib.h) set(JPEG_NAMES ${JPEG_NAMES} jpeg libjpeg) find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES}) +if(JPEG_INCLUDE_DIR AND EXISTS "${JPEG_INCLUDE_DIR}/jpeglib.h") + file(STRINGS "${JPEG_INCLUDE_DIR}/jpeglib.h" + jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*") + + if (NOT jpeg_lib_version) + # libjpeg-turbo sticks JPEG_LIB_VERSION in jconfig.h + find_path(jconfig_dir jconfig.h) + if (jconfig_dir) + file(STRINGS "${jconfig_dir}/jconfig.h" + jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*") + endif() + unset(jconfig_dir) + endif() + + string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*" + "\\1" JPEG_VERSION "${jpeg_lib_version}") + unset(jpeg_lib_version) +endif() + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -find_package_handle_standard_args(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR) +find_package_handle_standard_args(JPEG + REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR + VERSION_VAR JPEG_VERSION) if(JPEG_FOUND) set(JPEG_LIBRARIES ${JPEG_LIBRARY}) diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt index 443d366..a53e441 100644 --- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt +++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt @@ -86,7 +86,7 @@ foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HG endforeach() foreach(VTEST BISON Boost CUDA DOXYGEN FLEX GIF GTK2 - HDF5 LibArchive OPENSCENEGRAPH RUBY SWIG Protobuf) + HDF5 JPEG LibArchive OPENSCENEGRAPH RUBY SWIG Protobuf) check_version_string(${VTEST} ${VTEST}_VERSION) endforeach() -- cgit v0.12