From 30488b3b9f781e614a9115d0d3dc03f164331332 Mon Sep 17 00:00:00 2001 From: "T.J. Corona" Date: Thu, 5 Dec 2019 13:44:44 -0500 Subject: FindLibArchive: create a target --- Help/release/dev/FindLibArchive-target.rst | 5 +++++ Modules/FindLibArchive.cmake | 15 +++++++++++++++ Tests/CMakeLists.txt | 1 + Tests/FindLibArchive/CMakeLists.txt | 10 ++++++++++ Tests/FindLibArchive/Test/CMakeLists.txt | 14 ++++++++++++++ Tests/FindLibArchive/Test/main.c | 7 +++++++ 6 files changed, 52 insertions(+) create mode 100644 Help/release/dev/FindLibArchive-target.rst create mode 100644 Tests/FindLibArchive/CMakeLists.txt create mode 100644 Tests/FindLibArchive/Test/CMakeLists.txt create mode 100644 Tests/FindLibArchive/Test/main.c diff --git a/Help/release/dev/FindLibArchive-target.rst b/Help/release/dev/FindLibArchive-target.rst new file mode 100644 index 0000000..8998dae --- /dev/null +++ b/Help/release/dev/FindLibArchive-target.rst @@ -0,0 +1,5 @@ +FindLibArchive-target +--------------------- + +* The :module:`FindLibArchive` module now returns an ``IMPORTED`` target + for libarchive. diff --git a/Modules/FindLibArchive.cmake b/Modules/FindLibArchive.cmake index ef27b7d..ce3c8b8 100644 --- a/Modules/FindLibArchive.cmake +++ b/Modules/FindLibArchive.cmake @@ -16,18 +16,26 @@ The module defines the following variables: LibArchive_INCLUDE_DIRS - include search path LibArchive_LIBRARIES - libraries to link LibArchive_VERSION - libarchive 3-component version number + +The module defines the following ``IMPORTED`` targets: + +:: + + LibArchive::LibArchive - target for linking against libarchive #]=======================================================================] find_path(LibArchive_INCLUDE_DIR NAMES archive.h PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/include" + DOC "libarchive include directory" ) find_library(LibArchive_LIBRARY NAMES archive libarchive PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\LibArchive;InstallPath]/lib" + DOC "libarchive library" ) mark_as_advanced(LibArchive_INCLUDE_DIR LibArchive_LIBRARY) @@ -58,4 +66,11 @@ unset(LIBARCHIVE_FOUND) if(LibArchive_FOUND) set(LibArchive_INCLUDE_DIRS ${LibArchive_INCLUDE_DIR}) set(LibArchive_LIBRARIES ${LibArchive_LIBRARY}) + + if (NOT TARGET LibArchive::LibArchive) + add_library(LibArchive::LibArchive UNKNOWN IMPORTED) + set_target_properties(LibArchive::LibArchive PROPERTIES + IMPORTED_LOCATION "${LibArchive_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LibArchive_INCLUDE_DIR}") + endif () endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b45782e..0d9e43f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1405,6 +1405,7 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH ICU JPEG JsonCpp + LibArchive LibLZMA LibRHash Libinput diff --git a/Tests/FindLibArchive/CMakeLists.txt b/Tests/FindLibArchive/CMakeLists.txt new file mode 100644 index 0000000..f532ef2 --- /dev/null +++ b/Tests/FindLibArchive/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindLibArchive.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindLibArchive/Test" + "${CMake_BINARY_DIR}/Tests/FindLibArchive/Test" + ${build_generator_args} + --build-project TestFindLibArchive + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) diff --git a/Tests/FindLibArchive/Test/CMakeLists.txt b/Tests/FindLibArchive/Test/CMakeLists.txt new file mode 100644 index 0000000..35843bb --- /dev/null +++ b/Tests/FindLibArchive/Test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.12) +project(TestFindLibArchive C) +include(CTest) + +find_package(LibArchive REQUIRED) + +add_executable(test_libarchive_tgt main.c) +target_link_libraries(test_libarchive_tgt LibArchive::LibArchive) +add_test(NAME test_libarchive_tgt COMMAND test_libarchive_tgt) + +add_executable(test_libarchive_var main.c) +target_include_directories(test_libarchive_var PRIVATE ${LibArchive_INCLUDE_DIRS}) +target_link_libraries(test_libarchive_var PRIVATE ${LibArchive_LIBRARIES}) +add_test(NAME test_libarchive_var COMMAND test_libarchive_var) diff --git a/Tests/FindLibArchive/Test/main.c b/Tests/FindLibArchive/Test/main.c new file mode 100644 index 0000000..03e7ece --- /dev/null +++ b/Tests/FindLibArchive/Test/main.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + archive_read_free(archive_read_new()); + return 0; +} -- cgit v0.12