diff options
author | Brad King <brad.king@kitware.com> | 2018-04-19 12:26:28 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-04-19 12:26:34 (GMT) |
commit | c14497191bf4412b7b7f5241030f251373e4c0ae (patch) | |
tree | 3531b463471a188f58dfa53b43069ba726945230 | |
parent | 1a2eb621053c3f32c6eca2a962af436c0bd1044a (diff) | |
parent | 87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423 (diff) | |
download | CMake-c14497191bf4412b7b7f5241030f251373e4c0ae.zip CMake-c14497191bf4412b7b7f5241030f251373e4c0ae.tar.gz CMake-c14497191bf4412b7b7f5241030f251373e4c0ae.tar.bz2 |
Merge topic 'FindJPEG-imported-targets'
87f2cf3b1c FindJPEG: Add imported target support and full test
13952a3b7f FindJPEG: Add multi config support and associated docs
1f6649b7d1 FindJPEG: Add version detection and associated test update and docs
8d07408a62 FindJPEG: Cleanup documentation formatting
e70da3f0f3 FindJPEG: Clean up whitepaces and lowercase function names
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1974
-rw-r--r-- | Help/release/dev/FindJPEG-imported-targets.rst | 4 | ||||
-rw-r--r-- | Modules/FindJPEG.cmake | 119 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/CMakeOnly/AllFindModules/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/FindJPEG/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindJPEG/Test/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/FindJPEG/Test/main.c | 16 |
7 files changed, 153 insertions, 16 deletions
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 e233714..9542f69 100644 --- a/Modules/FindJPEG.cmake +++ b/Modules/FindJPEG.cmake @@ -5,38 +5,127 @@ # FindJPEG # -------- # -# Find JPEG +# Find the JPEG library (libjpeg) # -# Find the native JPEG includes and library This module defines +# Imported targets +# ^^^^^^^^^^^^^^^^ # -# :: +# This module defines the following :prop_tgt:`IMPORTED` targets: # -# 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::JPEG`` +# The JPEG library, if found. # -# also defined, but not for general use are +# Result variables +# ^^^^^^^^^^^^^^^^ # -# :: +# This module will set the following variables in your project: # -# JPEG_LIBRARY, where to find the JPEG library. +# ``JPEG_FOUND`` +# If false, do not try to use JPEG. +# ``JPEG_INCLUDE_DIRS`` +# 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_DIRS`` +# 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_INCLUDE_DIR`` +# where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS) +# ``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" + 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}) + 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. -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) 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/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() 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 $<CONFIGURATION> + --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 $<CONFIGURATION> + ) 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 <assert.h> +#include <stdio.h> + +#include <jpeglib.h> + +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; +} |