mirror of
https://github.com/moparisthebest/curl
synced 2025-01-10 21:48:10 -05:00
CMake: Improve config installation
Use 'GNUInstallDirs' standard module to set destinations of installed files. Use uppercase "CURL" names instead of lowercase "curl" to match standard 'FindCURL.cmake' CMake module: * https://cmake.org/cmake/help/latest/module/FindCURL.html Meaning: * Install 'CURLConfig.cmake' instead of 'curl-config.cmake' * User should call 'find_package(CURL)' instead of 'find_package(curl)' Use 'configure_package_config_file' function to generate 'CURLConfig.cmake' file. This will make 'curl-config.cmake.in' template file smaller and handle components better. E.g. current configuration report no error if user specified unknown components (note: new configuration expects no components, report error if user will try to specify any). Closes https://github.com/curl/curl/pull/2849
This commit is contained in:
parent
b8ab30d309
commit
69328490fc
@ -1,64 +1,9 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
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()
|
|
||||||
|
|
||||||
if("@USE_OPENSSL@")
|
if("@USE_OPENSSL@")
|
||||||
include(CMakeFindDependencyMacro)
|
include(CMakeFindDependencyMacro)
|
||||||
find_dependency(OpenSSL "@OPENSSL_VERSION_MAJOR@")
|
find_dependency(OpenSSL "@OPENSSL_VERSION_MAJOR@")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(_curl_missing_components)
|
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
|
||||||
foreach(_comp ${CURL_FIND_COMPONENTS})
|
check_required_components("@PROJECT_NAME@")
|
||||||
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)
|
|
||||||
|
@ -1153,11 +1153,13 @@ function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
|
|||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(WIN32 AND NOT CYGWIN)
|
include(GNUInstallDirs)
|
||||||
set(CURL_INSTALL_CMAKE_DIR CMake)
|
|
||||||
else()
|
set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||||
set(CURL_INSTALL_CMAKE_DIR lib/cmake/curl)
|
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
||||||
endif()
|
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||||
|
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
|
||||||
|
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||||
|
|
||||||
if(USE_MANUAL)
|
if(USE_MANUAL)
|
||||||
add_subdirectory(docs)
|
add_subdirectory(docs)
|
||||||
@ -1291,7 +1293,7 @@ set(VERSIONNUM "${CURL_VERSION_NUM}")
|
|||||||
configure_file("${CURL_SOURCE_DIR}/curl-config.in"
|
configure_file("${CURL_SOURCE_DIR}/curl-config.in"
|
||||||
"${CURL_BINARY_DIR}/curl-config" @ONLY)
|
"${CURL_BINARY_DIR}/curl-config" @ONLY)
|
||||||
install(FILES "${CURL_BINARY_DIR}/curl-config"
|
install(FILES "${CURL_BINARY_DIR}/curl-config"
|
||||||
DESTINATION bin
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
PERMISSIONS
|
PERMISSIONS
|
||||||
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||||
GROUP_READ GROUP_EXECUTE
|
GROUP_READ GROUP_EXECUTE
|
||||||
@ -1301,7 +1303,7 @@ install(FILES "${CURL_BINARY_DIR}/curl-config"
|
|||||||
configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
|
configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
|
||||||
"${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
|
"${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
|
||||||
install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
|
install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
|
||||||
DESTINATION lib/pkgconfig)
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
|
||||||
# This needs to be run very last so other parts of the scripts can take advantage of this.
|
# This needs to be run very last so other parts of the scripts can take advantage of this.
|
||||||
if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
|
if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
|
||||||
@ -1310,25 +1312,32 @@ endif()
|
|||||||
|
|
||||||
# install headers
|
# install headers
|
||||||
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
|
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
|
||||||
DESTINATION include
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
FILES_MATCHING PATTERN "*.h")
|
FILES_MATCHING PATTERN "*.h")
|
||||||
|
|
||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
"${PROJECT_BINARY_DIR}/curl-config-version.cmake"
|
"${version_config}"
|
||||||
VERSION ${CURL_VERSION}
|
VERSION ${CURL_VERSION}
|
||||||
COMPATIBILITY SameMajorVersion
|
COMPATIBILITY SameMajorVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
configure_file(CMake/curl-config.cmake.in
|
# Use:
|
||||||
"${PROJECT_BINARY_DIR}/curl-config.cmake"
|
# * TARGETS_EXPORT_NAME
|
||||||
@ONLY
|
# * PROJECT_NAME
|
||||||
|
configure_package_config_file(CMake/curl-config.cmake.in
|
||||||
|
"${project_config}"
|
||||||
|
INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES ${PROJECT_BINARY_DIR}/curl-config.cmake
|
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||||
${PROJECT_BINARY_DIR}/curl-config-version.cmake
|
NAMESPACE "${PROJECT_NAME}::"
|
||||||
|
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES ${version_config} ${project_config}
|
||||||
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -109,19 +109,13 @@ target_include_directories(${LIB_NAME} INTERFACE
|
|||||||
$<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
$<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
||||||
|
|
||||||
install(TARGETS ${LIB_NAME}
|
install(TARGETS ${LIB_NAME}
|
||||||
EXPORT libcurl-target
|
EXPORT ${TARGETS_EXPORT_NAME}
|
||||||
ARCHIVE DESTINATION lib
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
export(TARGETS ${LIB_NAME}
|
export(TARGETS ${LIB_NAME}
|
||||||
APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
||||||
NAMESPACE CURL::
|
NAMESPACE CURL::
|
||||||
)
|
)
|
||||||
|
|
||||||
install(EXPORT libcurl-target
|
|
||||||
FILE libcurl-target.cmake
|
|
||||||
NAMESPACE CURL::
|
|
||||||
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
|
|
||||||
)
|
|
||||||
|
@ -72,14 +72,8 @@ target_link_libraries(${EXE_NAME} libcurl ${CURL_LIBS})
|
|||||||
|
|
||||||
#INCLUDE(ModuleInstall OPTIONAL)
|
#INCLUDE(ModuleInstall OPTIONAL)
|
||||||
|
|
||||||
install(TARGETS ${EXE_NAME} EXPORT curl-target DESTINATION bin)
|
install(TARGETS ${EXE_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
export(TARGETS ${EXE_NAME}
|
export(TARGETS ${EXE_NAME}
|
||||||
APPEND FILE ${PROJECT_BINARY_DIR}/curl-target.cmake
|
APPEND FILE ${PROJECT_BINARY_DIR}/curl-target.cmake
|
||||||
NAMESPACE CURL::
|
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