Merge topic 'curl-target'

ee06f3c339 FindCURL: Revise documentation markup
83c0cb3f03 FindCURL: provide imported target CURL::CURL

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1822
This commit is contained in:
Brad King 2018-03-08 14:56:14 +00:00 committed by Kitware Robot
commit 151763c9b2
6 changed files with 78 additions and 7 deletions

View File

@ -0,0 +1,4 @@
curl-target
-----------
* The :module:`FindCURL` module now provides imported targets.

View File

@ -5,16 +5,30 @@
# FindCURL
# --------
#
# Find curl
#
# Find the native CURL headers and libraries.
#
# ::
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc.
# CURL_LIBRARIES - List of libraries when using curl.
# CURL_FOUND - True if curl found.
# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8)
# This module defines :prop_tgt:`IMPORTED` target ``CURL::CURL``, if
# curl has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ``CURL_FOUND``
# True if curl found.
#
# ``CURL_INCLUDE_DIRS``
# where to find curl/curl.h, etc.
#
# ``CURL_LIBRARIES``
# List of libraries when using curl.
#
# ``CURL_VERSION_STRING``
# The version of curl found.
# Look for the header file.
find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
@ -52,4 +66,10 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
if(CURL_FOUND)
set(CURL_LIBRARIES ${CURL_LIBRARY})
set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
if(NOT TARGET CURL::CURL)
add_library(CURL::CURL UNKNOWN IMPORTED)
set_target_properties(CURL::CURL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
set_property(TARGET CURL::CURL APPEND PROPERTY IMPORTED_LOCATION "${CURL_LIBRARY}")
endif()
endif()

View File

@ -1326,6 +1326,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindBZip2)
endif()
if(CMake_TEST_FindCURL)
add_subdirectory(FindCURL)
endif()
if(CMake_TEST_FindDoxygen)
add_subdirectory(FindDoxygen)
endif()

View File

@ -0,0 +1,10 @@
add_test(NAME FindCURL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindCURL/Test"
"${CMake_BINARY_DIR}/Tests/FindCURL/Test"
${build_generator_args}
--build-project TestFindCURL
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.10)
project(TestFindCURL C)
include(CTest)
find_package(CURL REQUIRED)
add_definitions(-DCMAKE_EXPECTED_CURL_VERSION="${CURL_VERSION_STRING}")
add_executable(test_tgt main.c)
target_link_libraries(test_tgt CURL::CURL)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${CURL_LIBRARIES})
add_test(NAME test_var COMMAND test_var)

View File

@ -0,0 +1,17 @@
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct curl_slist* slist;
curl_global_init(0);
slist = curl_slist_append(NULL, "CMake");
curl_slist_free_all(slist);
curl_global_cleanup();
return 0;
}