Commit b3b238c3 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'bzip2-imported-targets'

79eba4b7 Help: Add notes for topic 'bzip2-imported-targets'
069cac58 Tests: Add FindBZip2 unit tests
e9ce0503 FindBZip2: Add imported target
parents a3aaf0a1 79eba4b7
bzip2-imported-targets
----------------------
* The :module:`FindBZip2` module now provides imported targets.
......@@ -4,7 +4,16 @@
#
# Try to find BZip2
#
# Once done this will define
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``BZip2::BZip2``, if
# BZip2 has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
......@@ -64,6 +73,31 @@ if (BZIP2_FOUND)
set(CMAKE_REQUIRED_LIBRARIES ${BZIP2_LIBRARIES})
CHECK_SYMBOL_EXISTS(BZ2_bzCompressInit "bzlib.h" BZIP2_NEED_PREFIX)
cmake_pop_check_state()
if(NOT TARGET BZip2::BZip2)
add_library(BZip2::BZip2 UNKNOWN IMPORTED)
set_target_properties(BZip2::BZip2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIRS}")
if(BZIP2_LIBRARY_RELEASE)
set_property(TARGET BZip2::BZip2 APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(BZip2::BZip2 PROPERTIES
IMPORTED_LOCATION_RELEASE "${BZIP2_LIBRARY_RELEASE}")
endif()
if(BZIP2_LIBRARY_DEBUG)
set_property(TARGET BZip2::BZip2 APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(BZip2::BZip2 PROPERTIES
IMPORTED_LOCATION_DEBUG "${BZIP2_LIBRARY_DEBUG}")
endif()
if(NOT BZIP2_LIBRARY_RELEASE AND NOT BZIP2_LIBRARY_DEBUG)
set_property(TARGET BZip2::BZip2 APPEND PROPERTY
IMPORTED_LOCATION "${BZIP2_LIBRARY}")
endif()
endif()
endif ()
mark_as_advanced(BZIP2_INCLUDE_DIR)
......@@ -1356,6 +1356,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindBoost)
endif()
if(CMake_TEST_FindBZip2)
add_subdirectory(FindBZip2)
endif()
if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL)
endif()
......
add_test(NAME FindBZip2.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindBZip2/Test"
"${CMake_BINARY_DIR}/Tests/FindBZip2/Test"
${build_generator_args}
--build-project TestFindBZip2
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.4)
project(TestFindBZip2 C)
include(CTest)
find_package(BZip2 REQUIRED)
add_definitions(-DCMAKE_EXPECTED_BZip2_VERSION="${BZip2_VERSION_STRING}")
add_executable(test_tgt main.c)
target_link_libraries(test_tgt BZip2::BZip2)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${BZIP2_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${BZIP2_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
#include <bzlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int chunksize = 1024;
FILE* file = fopen("test.bzip2", "wb");
char* buf = malloc(sizeof(char) * chunksize);
int error, rsize;
unsigned int in, out;
BZFILE* bzfile = BZ2_bzWriteOpen(&error, file, 64, 1, 10);
/* Don't actually write anything for the purposes of the test */
BZ2_bzWriteClose(&error, bzfile, 1, &in, &out);
free(buf);
fclose(file);
remove("test.bzip2");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment