diff options
author | Mateusz Loskot <mateusz@loskot.net> | 2018-04-17 21:52:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-04-18 12:59:06 (GMT) |
commit | 87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423 (patch) | |
tree | ba042fc7de4a29acecb7385dc7fca0da70f8d038 | |
parent | 13952a3b7fb930baeeda299bf186e29d57d794fe (diff) | |
download | CMake-87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423.zip CMake-87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423.tar.gz CMake-87f2cf3b1ce0ef7b8e71eae0f44cf9753660d423.tar.bz2 |
FindJPEG: Add imported target support and full test
-rw-r--r-- | Help/release/dev/FindJPEG-imported-targets.rst | 4 | ||||
-rw-r--r-- | Modules/FindJPEG.cmake | 42 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-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 |
6 files changed, 88 insertions, 2 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 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 $<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; +} |