Merge topic 'findexpat-importedtargets'

3a4f82e9 Help: Add notes for topic 'FindEXPAT-importedtargets'
bfe51369 FindEXPAT: Add unit test of target and variables
78f166f8 FindEXPAT: Add imported target and documentation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1207
This commit is contained in:
Brad King
2017-09-07 15:22:18 +00:00
committed by Kitware Robot
6 changed files with 83 additions and 7 deletions
@@ -0,0 +1,4 @@
FindEXPAT-importedtargets
-------------------------
* The :module:`FindEXPAT` module now provides imported targets.
+28 -7
View File
@@ -5,15 +5,28 @@
# FindEXPAT
# ---------
#
# Find expat
# Find the native Expat headers and library.
#
# Find the native EXPAT headers and libraries.
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# ::
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``EXPAT::EXPAT``
# The Expat ``expat`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``EXPAT_INCLUDE_DIRS``
# where to find expat.h, etc.
# ``EXPAT_LIBRARIES``
# the libraries to link against to use Expat.
# ``EXPAT_FOUND``
# true if the Expat headers and libraries were found.
#
# EXPAT_INCLUDE_DIRS - where to find expat.h, etc.
# EXPAT_LIBRARIES - List of libraries when using expat.
# EXPAT_FOUND - True if expat found.
find_package(PkgConfig QUIET)
@@ -49,10 +62,18 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
VERSION_VAR EXPAT_VERSION_STRING)
# Copy the results to the output variables.
# Copy the results to the output variables and target.
if(EXPAT_FOUND)
set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
if(NOT TARGET EXPAT::EXPAT)
add_library(EXPAT::EXPAT UNKNOWN IMPORTED)
set_target_properties(EXPAT::EXPAT PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${EXPAT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
endif()
endif()
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)
+4
View File
@@ -1431,6 +1431,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindDoxygen)
endif()
if(CMake_TEST_FindEXPAT)
add_subdirectory(FindEXPAT)
endif()
if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL)
endif()
+10
View File
@@ -0,0 +1,10 @@
add_test(NAME FindEXPAT.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindEXPAT/Test"
"${CMake_BINARY_DIR}/Tests/FindEXPAT/Test"
${build_generator_args}
--build-project TestFindEXPAT
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
+16
View File
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.9)
project(TestFindEXPAT C)
include(CTest)
find_package(EXPAT REQUIRED)
add_definitions(-DCMAKE_EXPECTED_EXPAT_VERSION="${EXPAT_VERSION_STRING}")
add_executable(testexpat_tgt main.c)
target_link_libraries(testexpat_tgt EXPAT::EXPAT)
add_test(NAME testexpat_tgt COMMAND testexpat_tgt)
add_executable(testexpat_var main.c)
target_include_directories(testexpat_var PRIVATE ${EXPAT_INCLUDE_DIRS})
target_link_libraries(testexpat_var PRIVATE ${EXPAT_LIBRARIES})
add_test(NAME testexpat_var COMMAND testexpat_var)
+21
View File
@@ -0,0 +1,21 @@
#include <expat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
XML_Expat_Version expat_version;
char expat_version_string[16];
expat_version = XML_ExpatVersionInfo();
snprintf(expat_version_string, 16, "%i.%i.%i", expat_version.major,
expat_version.minor, expat_version.micro);
if (strcmp(expat_version_string, CMAKE_EXPECTED_EXPAT_VERSION) != 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}