mirror of
https://github.com/curl/curl.git
synced 2024-11-21 01:16:58 +08:00
cmake: Export libcurl and curl targets to use by other cmake projects
The config files define curl and libcurl targets as imported targets CURL::curl and CURL::libcurl. For backward compatibility with CMake- provided find-module the CURL_INCLUDE_DIRS and CURL_LIBRARIES are also set. Closes #1879
This commit is contained in:
parent
58a9e770e3
commit
1cb4f5d6e8
59
CMake/curl-config.cmake
Normal file
59
CMake/curl-config.cmake
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
|
||||
if(NOT CURL_FIND_COMPONENTS)
|
||||
set(CURL_FIND_COMPONENTS curl libcurl)
|
||||
if(CURL_FIND_REQUIRED)
|
||||
set(CURL_FIND_REQUIRED_curl TRUE)
|
||||
set(CURL_FIND_REQUIRED_libcurl TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(_curl_missing_components)
|
||||
foreach(_comp ${CURL_FIND_COMPONENTS})
|
||||
if(EXISTS "${_DIR}/${_comp}-target.cmake")
|
||||
include("${_DIR}/${_comp}-target.cmake")
|
||||
set(CURL_${_comp}_FOUND TRUE)
|
||||
else()
|
||||
set(CURL_${_comp}_FOUND FALSE)
|
||||
if(CURL_FIND_REQUIRED_${_comp})
|
||||
set(CURL_FOUND FALSE)
|
||||
list(APPEND _curl_missing_components ${_comp})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_curl_missing_components)
|
||||
set(CURL_NOT_FOUND_MESSAGE "Following required components not found: " ${_curl_missing_components})
|
||||
else()
|
||||
if(TARGET CURL::libcurl)
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" _curl_current_config)
|
||||
if(NOT _curl_current_config)
|
||||
set(_curl_current_config "NOCONFIG")
|
||||
endif()
|
||||
get_target_property(_curl_configurations CURL::libcurl IMPORTED_CONFIGURATIONS)
|
||||
list(FIND _curl_configurations "${_curl_current_config}" _i)
|
||||
if(_i LESS 0)
|
||||
set(_curl_config "RELEASE")
|
||||
list(FIND _curl_configurations "${_curl_current_config}" _i)
|
||||
if(_i LESS 0)
|
||||
set(_curl_config "NOCONFIG")
|
||||
list(FIND _curl_configurations "${_curl_current_config}" _i)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(_i LESS 0)
|
||||
set(_curl_current_config "") # let CMake pick config at random
|
||||
else()
|
||||
set(_curl_current_config "_${_curl_current_config}")
|
||||
endif()
|
||||
|
||||
get_target_property(CURL_INCLUDE_DIRS CURL::libcurl INTERFACE_INCLUDE_DIRECTORIES)
|
||||
get_target_property(CURL_LIBRARIES CURL::libcurl "LOCATION${_curl_current_config}")
|
||||
set(_curl_current_config)
|
||||
set(_curl_configurations)
|
||||
set(_i)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
unset(_curl_missing_components)
|
@ -38,7 +38,7 @@
|
||||
# To check:
|
||||
# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
|
||||
# (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
|
||||
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
|
||||
include(Utilities)
|
||||
include(Macros)
|
||||
@ -1130,6 +1130,12 @@ function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
|
||||
|
||||
endfunction()
|
||||
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
set(CURL_INSTALL_CMAKE_DIR CMake)
|
||||
else()
|
||||
set(CURL_INSTALL_CMAKE_DIR lib/cmake/curl)
|
||||
endif()
|
||||
|
||||
if(USE_MANUAL)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
@ -1280,6 +1286,25 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
|
||||
DESTINATION include
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
"${PROJECT_BINARY_DIR}/curl-config-version.cmake"
|
||||
VERSION ${CURL_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
configure_file(CMake/curl-config.cmake
|
||||
"${PROJECT_BINARY_DIR}/curl-config.cmake"
|
||||
COPYONLY
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${PROJECT_BINARY_DIR}/curl-config.cmake
|
||||
${PROJECT_BINARY_DIR}/curl-config-version.cmake
|
||||
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||
)
|
||||
|
||||
# Workaround for MSVS10 to avoid the Dialog Hell
|
||||
# FIXME: This could be removed with future version of CMake.
|
||||
if(MSVC_VERSION EQUAL 1600)
|
||||
|
@ -30,7 +30,8 @@ CMAKE_DIST = CMakeLists.txt CMake/CMakeConfigurableFile.in \
|
||||
CMake/Macros.cmake \
|
||||
CMake/CurlSymbolHiding.cmake CMake/FindCARES.cmake \
|
||||
CMake/FindLibSSH2.cmake CMake/FindNGHTTP2.cmake \
|
||||
CMake/FindMbedTLS.cmake CMake/cmake_uninstall.cmake.in
|
||||
CMake/FindMbedTLS.cmake CMake/cmake_uninstall.cmake.in \
|
||||
CMake/curl-config.cmake
|
||||
|
||||
VC6_LIBTMPL = projects/Windows/VC6/lib/libcurl.tmpl
|
||||
VC6_LIBDSP = projects/Windows/VC6/lib/libcurl.dsp.dist
|
||||
|
@ -108,7 +108,24 @@ if(WIN32)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(${LIB_NAME} INTERFACE
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
install(TARGETS ${LIB_NAME}
|
||||
EXPORT libcurl-target
|
||||
ARCHIVE DESTINATION lib
|
||||
LIBRARY DESTINATION lib
|
||||
RUNTIME DESTINATION bin)
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
|
||||
export(TARGETS ${LIB_NAME}
|
||||
APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
||||
NAMESPACE CURL::
|
||||
)
|
||||
|
||||
install(EXPORT libcurl-target
|
||||
FILE libcurl-target.cmake
|
||||
NAMESPACE CURL::
|
||||
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||
)
|
||||
|
||||
|
@ -76,4 +76,15 @@ set_target_properties(${EXE_NAME} PROPERTIES
|
||||
|
||||
#INCLUDE(ModuleInstall OPTIONAL)
|
||||
|
||||
install(TARGETS ${EXE_NAME} DESTINATION bin)
|
||||
install(TARGETS ${EXE_NAME} EXPORT curl-target DESTINATION bin)
|
||||
export(TARGETS ${EXE_NAME}
|
||||
APPEND FILE ${PROJECT_BINARY_DIR}/curl-target.cmake
|
||||
NAMESPACE CURL::
|
||||
)
|
||||
|
||||
install(EXPORT curl-target
|
||||
FILE curl-target.cmake
|
||||
NAMESPACE CURL::
|
||||
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user