mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-16 12:11:04 -06:00
FindJPEG: Add imported target support and full test
This commit is contained in:
committed by
Brad King
parent
13952a3b7f
commit
87f2cf3b1c
4
Help/release/dev/FindJPEG-imported-targets.rst
Normal file
4
Help/release/dev/FindJPEG-imported-targets.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
FindJPEG-imported-targets
|
||||
-------------------------
|
||||
|
||||
* The :module:`FindJPEG` module now provides imported targets.
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
10
Tests/FindJPEG/CMakeLists.txt
Normal file
10
Tests/FindJPEG/CMakeLists.txt
Normal file
@@ -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>
|
||||
)
|
||||
14
Tests/FindJPEG/Test/CMakeLists.txt
Normal file
14
Tests/FindJPEG/Test/CMakeLists.txt
Normal file
@@ -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)
|
||||
16
Tests/FindJPEG/Test/main.c
Normal file
16
Tests/FindJPEG/Test/main.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user