diff options
author | Mateusz Loskot <mateusz@loskot.net> | 2018-04-17 20:53:26 (GMT) |
---|---|---|
committer | Mateusz Loskot <mateusz@loskot.net> | 2018-04-17 20:53:26 (GMT) |
commit | 1f6649b7d118e9de2a51c9e48b5fea527f608fc1 (patch) | |
tree | 56169bceca9d8b7dec4c777a4e030fe7c2b4188e /Modules/FindJPEG.cmake | |
parent | 8d07408a62c03123c0c49b9946025930d1d61e16 (diff) | |
download | CMake-1f6649b7d118e9de2a51c9e48b5fea527f608fc1.zip CMake-1f6649b7d118e9de2a51c9e48b5fea527f608fc1.tar.gz CMake-1f6649b7d118e9de2a51c9e48b5fea527f608fc1.tar.bz2 |
FindJPEG: Add version detection and associated test update and docs
Diffstat (limited to 'Modules/FindJPEG.cmake')
-rw-r--r-- | Modules/FindJPEG.cmake | 27 |
1 files changed, 26 insertions, 1 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}) |