summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiroshi Miura <miurahr@linux.com>2021-10-06 00:39:02 (GMT)
committerBrad King <brad.king@kitware.com>2021-10-06 15:28:09 (GMT)
commit6e8754c6251bc2f7edfb0d71303e1b85fce93f5e (patch)
tree077977c922a7e5cf3a9473cce443777605d2fff2
parentbdbce845cd714a1e844976e4cba4734932e89dd5 (diff)
downloadCMake-6e8754c6251bc2f7edfb0d71303e1b85fce93f5e.zip
CMake-6e8754c6251bc2f7edfb0d71303e1b85fce93f5e.tar.gz
CMake-6e8754c6251bc2f7edfb0d71303e1b85fce93f5e.tar.bz2
FindJasper: Add IMPORTED target
Fixes: #20601 Signed-off-by: Hiroshi Miura <miurahr@linux.com>
-rw-r--r--Help/release/dev/FindJasper-imported-target.rst4
-rw-r--r--Modules/FindJasper.cmake27
-rw-r--r--Tests/CMakeLists.txt1
-rw-r--r--Tests/FindJasper/CMakeLists.txt10
-rw-r--r--Tests/FindJasper/Test/CMakeLists.txt16
-rw-r--r--Tests/FindJasper/Test/main.c17
6 files changed, 75 insertions, 0 deletions
diff --git a/Help/release/dev/FindJasper-imported-target.rst b/Help/release/dev/FindJasper-imported-target.rst
new file mode 100644
index 0000000..33ee885
--- /dev/null
+++ b/Help/release/dev/FindJasper-imported-target.rst
@@ -0,0 +1,4 @@
+FindJasper-imported-target
+--------------------------
+
+* The :module:`FindJasper` module now provides an imported target.
diff --git a/Modules/FindJasper.cmake b/Modules/FindJasper.cmake
index 0ca0f31..9a62669 100644
--- a/Modules/FindJasper.cmake
+++ b/Modules/FindJasper.cmake
@@ -7,6 +7,12 @@ FindJasper
Find the Jasper JPEG2000 library.
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+``Jasper::Jasper``
+ The jasper library, if found.
+
Result Variables
^^^^^^^^^^^^^^^^
@@ -60,4 +66,25 @@ find_package_handle_standard_args(Jasper
if(JASPER_FOUND)
set(JASPER_LIBRARIES ${JASPER_LIBRARIES} ${JPEG_LIBRARIES})
set(JASPER_INCLUDE_DIRS ${JASPER_INCLUDE_DIR})
+ if(NOT TARGET Jasper::Jasper)
+ add_library(Jasper::Jasper UNKNOWN IMPORTED)
+ if(JASPER_INCLUDE_DIRS)
+ set_target_properties(Jasper::Jasper PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${JASPER_INCLUDE_DIRS}")
+ endif()
+ if(EXISTS "${JASPER_LIBRARY_RELEASE}")
+ set_property(TARGET Jasper::Jasper APPEND PROPERTY
+ IMPORTED CONFIGURATION RELEASE)
+ set_target_properties(Jasper::Jasper PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
+ IMPORTED_LOCATION "${JASPER_LIBRARY_RELEASE}")
+ endif()
+ if(EXISTS "${JASPER_LIBRARY_DEBUG}")
+ set_property(TARGET Jasper::Jasper APPEND PROPERTY
+ IMPORTED CONFIGURATION DEBUG)
+ set_target_properties(Jasper::Jasper PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
+ IMPORTED_LOCATION "${JASPER_LIBRARY_DEBUG}")
+ endif()
+ endif()
endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 20b6e25..d1f7b69 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1466,6 +1466,7 @@ if(BUILD_TESTING)
Iconv
ICU
Intl
+ Jasper
JPEG
JsonCpp
LAPACK
diff --git a/Tests/FindJasper/CMakeLists.txt b/Tests/FindJasper/CMakeLists.txt
new file mode 100644
index 0000000..1bfae78
--- /dev/null
+++ b/Tests/FindJasper/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindJasper.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindJasper/Test"
+ "${CMake_BINARY_DIR}/Tests/FindJasper/Test"
+ ${build_generator_args}
+ --build-project TestFindJasper
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindJasper/Test/CMakeLists.txt b/Tests/FindJasper/Test/CMakeLists.txt
new file mode 100644
index 0000000..1e9467d
--- /dev/null
+++ b/Tests/FindJasper/Test/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.21)
+project(TestFindJasper C)
+include(CTest)
+
+find_package(Jasper)
+
+add_definitions(-DCMAKE_EXPECTED_JASPER_VERSION=${JASPER_VERSION_STRING})
+
+add_executable(test_jasper_tgt main.c)
+target_link_libraries(test_jasper_tgt Jasper::Jasper)
+add_test(NAME test_jasper_tgt COMMAND test_jasper_tgt)
+
+add_executable(test_jasper_var main.c)
+target_include_directories(test_jasper_var PRIVATE ${JASPER_INCLUDE_DIRS})
+target_link_libraries(test_jasper_var PRIVATE ${JASPER_LIBRARIES})
+add_test(NAME test_jasper_var COMMAND test_jasper_var)
diff --git a/Tests/FindJasper/Test/main.c b/Tests/FindJasper/Test/main.c
new file mode 100644
index 0000000..771344d
--- /dev/null
+++ b/Tests/FindJasper/Test/main.c
@@ -0,0 +1,17 @@
+#include <assert.h>
+// clang-format off
+#include <stdio.h>
+#include <jasper/jasper.h>
+// clang-format on
+
+int main()
+{
+ /* Without any JPEG file to open, test that the call fails as
+ expected. This tests that linking worked. */
+ jas_init();
+ jas_image_t* img = jas_image_create0();
+ jas_image_destroy(img);
+ jas_cleanup();
+
+ return (JAS_VERSION != CMAKE_EXPECTED_JASPER_VERSION);
+}