From e70da3f0f3fe2f4373152953ba9822ce0f368cf5 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 17 Apr 2018 21:43:07 +0200 Subject: FindJPEG: Clean up whitepaces and lowercase function names --- Modules/FindJPEG.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index e233714..a9e6396 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -24,19 +24,19 @@ find_path(JPEG_INCLUDE_DIR jpeglib.h) set(JPEG_NAMES ${JPEG_NAMES} jpeg libjpeg) -find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES} ) +find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES}) 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 DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR) if(JPEG_FOUND) set(JPEG_LIBRARIES ${JPEG_LIBRARY}) endif() # Deprecated declarations. -set (NATIVE_JPEG_INCLUDE_PATH ${JPEG_INCLUDE_DIR} ) +set(NATIVE_JPEG_INCLUDE_PATH ${JPEG_INCLUDE_DIR}) if(JPEG_LIBRARY) - get_filename_component (NATIVE_JPEG_LIB_PATH ${JPEG_LIBRARY} PATH) + get_filename_component(NATIVE_JPEG_LIB_PATH ${JPEG_LIBRARY} PATH) endif() -mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR ) +mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR) -- cgit v0.12 From 8d07408a62c03123c0c49b9946025930d1d61e16 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 17 Apr 2018 21:46:50 +0200 Subject: FindJPEG: Cleanup documentation formatting --- Modules/FindJPEG.cmake | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index a9e6396..04e4d20 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -5,21 +5,27 @@ # FindJPEG # -------- # -# Find JPEG +# Find the JPEG library (libjpeg) # -# Find the native JPEG includes and library This module defines +# Result variables +# ^^^^^^^^^^^^^^^^ # -# :: +# This module will set the following variables in your project: # -# JPEG_INCLUDE_DIR, where to find jpeglib.h, etc. -# JPEG_LIBRARIES, the libraries needed to use JPEG. -# JPEG_FOUND, If false, do not try to use JPEG. +# ``JPEG_FOUND`` +# If false, do not try to use JPEG. +# ``JPEG_INCLUDE_DIR`` +# where to find jpeglib.h, etc. +# ``JPEG_LIBRARIES`` +# the libraries needed to use JPEG. # -# also defined, but not for general use are +# Cache variables +# ^^^^^^^^^^^^^^^ # -# :: +# The following cache variables may also be set: # -# JPEG_LIBRARY, where to find the JPEG library. +# ``JPEG_LIBRARY`` +# where to find the JPEG library. find_path(JPEG_INCLUDE_DIR jpeglib.h) -- cgit v0.12 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 From 13952a3b7fb930baeeda299bf186e29d57d794fe Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 17 Apr 2018 23:26:44 +0200 Subject: FindJPEG: Add multi config support and associated docs --- Modules/FindJPEG.cmake | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index 9c047e5..fa4f3a1 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -28,13 +28,33 @@ # # ``JPEG_INCLUDE_DIR`` # where to find jpeglib.h, etc. +# ``JPEG_LIBRARY_RELEASE`` +# where to find the JPEG library (optimized). +# ``JPEG_LIBRARY_DEBUG`` +# where to find the JPEG library (debug). +# +# Obsolete variables +# ^^^^^^^^^^^^^^^^^^ +# # ``JPEG_LIBRARY`` # where to find the JPEG library. find_path(JPEG_INCLUDE_DIR jpeglib.h) -set(JPEG_NAMES ${JPEG_NAMES} jpeg libjpeg) -find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES}) +set(jpeg_names ${JPEG_NAMES} jpeg libjpeg) +foreach(name ${JPEG_NAMES}) + list(APPEND jpeg_names_debug "${name}d") +endforeach() + +if(NOT JPEG_LIBRARY) + find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names}) + find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug}) + include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + select_library_configurations(JPEG) + mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG) +endif() +unset(jpeg_names) +unset(jpeg_names_debug) if(JPEG_INCLUDE_DIR AND EXISTS "${JPEG_INCLUDE_DIR}/jpeglib.h") file(STRINGS "${JPEG_INCLUDE_DIR}/jpeglib.h" -- cgit v0.12 From 87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 17 Apr 2018 23:52:53 +0200 Subject: FindJPEG: Add imported target support and full test --- Help/release/dev/FindJPEG-imported-targets.rst | 4 +++ Modules/FindJPEG.cmake | 42 ++++++++++++++++++++++++-- Tests/CMakeLists.txt | 4 +++ Tests/FindJPEG/CMakeLists.txt | 10 ++++++ Tests/FindJPEG/Test/CMakeLists.txt | 14 +++++++++ Tests/FindJPEG/Test/main.c | 16 ++++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 Help/release/dev/FindJPEG-imported-targets.rst create mode 100644 Tests/FindJPEG/CMakeLists.txt create mode 100644 Tests/FindJPEG/Test/CMakeLists.txt create mode 100644 Tests/FindJPEG/Test/main.c diff --git a/Help/release/dev/FindJPEG-imported-targets.rst b/Help/release/dev/FindJPEG-imported-targets.rst new file mode 100644 index 0000000..32cf2f6 --- /dev/null +++ b/Help/release/dev/FindJPEG-imported-targets.rst @@ -0,0 +1,4 @@ +FindJPEG-imported-targets +------------------------- + +* The :module:`FindJPEG` module now provides imported targets. diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake index fa4f3a1..9542f69 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -7,6 +7,14 @@ # # Find the JPEG library (libjpeg) # +# Imported targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``JPEG::JPEG`` +# The JPEG library, if found. +# # Result variables # ^^^^^^^^^^^^^^^^ # @@ -14,7 +22,7 @@ # # ``JPEG_FOUND`` # If false, do not try to use JPEG. -# ``JPEG_INCLUDE_DIR`` +# ``JPEG_INCLUDE_DIRS`` # where to find jpeglib.h, etc. # ``JPEG_LIBRARIES`` # the libraries needed to use JPEG. @@ -26,7 +34,7 @@ # # The following cache variables may also be set: # -# ``JPEG_INCLUDE_DIR`` +# ``JPEG_INCLUDE_DIRS`` # where to find jpeglib.h, etc. # ``JPEG_LIBRARY_RELEASE`` # where to find the JPEG library (optimized). @@ -36,6 +44,8 @@ # Obsolete variables # ^^^^^^^^^^^^^^^^^^ # +# ``JPEG_INCLUDE_DIR`` +# where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS) # ``JPEG_LIBRARY`` # where to find the JPEG library. @@ -82,6 +92,34 @@ find_package_handle_standard_args(JPEG if(JPEG_FOUND) set(JPEG_LIBRARIES ${JPEG_LIBRARY}) + set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}") + + if(NOT TARGET JPEG::JPEG) + add_library(JPEG::JPEG UNKNOWN IMPORTED) + if(JPEG_INCLUDE_DIRS) + set_target_properties(JPEG::JPEG PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}") + endif() + if(EXISTS "${JPEG_LIBRARY}") + set_target_properties(JPEG::JPEG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${JPEG_LIBRARY}") + endif() + if(EXISTS "${JPEG_LIBRARY_RELEASE}") + set_property(TARGET JPEG::JPEG APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(JPEG::JPEG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}") + endif() + if(EXISTS "${JPEG_LIBRARY_DEBUG}") + set_property(TARGET JPEG::JPEG APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(JPEG::JPEG PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}") + endif() + endif() endif() # Deprecated declarations. diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index aad7cfc..38b4828 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1359,6 +1359,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindICU) endif() + if(CMake_TEST_FindJPEG) + add_subdirectory(FindJPEG) + endif() + if(CMake_TEST_FindJsonCpp) add_subdirectory(FindJsonCpp) endif() diff --git a/Tests/FindJPEG/CMakeLists.txt b/Tests/FindJPEG/CMakeLists.txt new file mode 100644 index 0000000..c8663c5 --- /dev/null +++ b/Tests/FindJPEG/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindJPEG.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindJPEG/Test" + "${CMake_BINARY_DIR}/Tests/FindJPEG/Test" + ${build_generator_args} + --build-project TestFindJPEG + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) diff --git a/Tests/FindJPEG/Test/CMakeLists.txt b/Tests/FindJPEG/Test/CMakeLists.txt new file mode 100644 index 0000000..a744f85 --- /dev/null +++ b/Tests/FindJPEG/Test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1) +project(TestFindJPEG C) +include(CTest) + +find_package(JPEG) + +add_executable(test_jpeg_tgt main.c) +target_link_libraries(test_jpeg_tgt JPEG::JPEG) +add_test(NAME test_jpeg_tgt COMMAND test_jpeg_tgt) + +add_executable(test_jpeg_var main.c) +target_include_directories(test_jpeg_var PRIVATE ${JPEG_INCLUDE_DIRS}) +target_link_libraries(test_jpeg_var PRIVATE ${JPEG_LIBRARIES}) +add_test(NAME test_jpeg_var COMMAND test_jpeg_var) diff --git a/Tests/FindJPEG/Test/main.c b/Tests/FindJPEG/Test/main.c new file mode 100644 index 0000000..c6e48f0 --- /dev/null +++ b/Tests/FindJPEG/Test/main.c @@ -0,0 +1,16 @@ +#include +#include + +#include + +int main() +{ + /* Without any JPEG file to open, test that the call fails as + expected. This tests that linking worked. */ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + + return 0; +} -- cgit v0.12