Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Improve config installation #2849

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 3 additions & 58 deletions CMake/curl-config.cmake.in
@@ -1,64 +1,9 @@

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()
@PACKAGE_INIT@

if("@USE_OPENSSL@")
include(CMakeFindDependencyMacro)
find_dependency(OpenSSL "@OPENSSL_VERSION_MAJOR@")
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)
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
39 changes: 24 additions & 15 deletions CMakeLists.txt
Expand Up @@ -1153,11 +1153,13 @@ 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()
include(GNUInstallDirs)

set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using vcpkg for building out libraries on Windows. One of its expectations is that lib files just contain object code. With things like cmake files it wants them to go into share/curl. Its pretty good about CMake conventions so I figured I'd mention it.

Other than that this looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of its expectations is that lib files just contain object code. With things like cmake files it wants them to go into share/curl

Can you please clarify is it relate to this patch or it's something you just want to have? Because before it was CMake and wasn't share/curl as you are expecting.

As a note there is no hard requirement for the layout on CMake side, from documentation:

This is merely a convention, so all (W) and (U) directories are still searched on all platforms.

So for simplicity reason it make sense to use same layout on all platforms. ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} is a generalization of previously used lib/cmake/curl.

set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
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)
add_subdirectory(docs)
Expand Down Expand Up @@ -1291,7 +1293,7 @@ set(VERSIONNUM "${CURL_VERSION_NUM}")
configure_file("${CURL_SOURCE_DIR}/curl-config.in"
"${CURL_BINARY_DIR}/curl-config" @ONLY)
install(FILES "${CURL_BINARY_DIR}/curl-config"
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
Expand All @@ -1301,7 +1303,7 @@ install(FILES "${CURL_BINARY_DIR}/curl-config"
configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
"${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
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.
if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
Expand All @@ -1310,25 +1312,32 @@ endif()

# install headers
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
DESTINATION include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h")


include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/curl-config-version.cmake"
"${version_config}"
VERSION ${CURL_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_file(CMake/curl-config.cmake.in
"${PROJECT_BINARY_DIR}/curl-config.cmake"
@ONLY
# Use:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(CMake/curl-config.cmake.in
"${project_config}"
INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
)

install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
)

install(
FILES ${PROJECT_BINARY_DIR}/curl-config.cmake
${PROJECT_BINARY_DIR}/curl-config-version.cmake
FILES ${version_config} ${project_config}
DESTINATION ${CURL_INSTALL_CMAKE_DIR}
)

Expand Down
14 changes: 4 additions & 10 deletions lib/CMakeLists.txt
Expand Up @@ -109,19 +109,13 @@ target_include_directories(${LIB_NAME} INTERFACE
$<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)

install(TARGETS ${LIB_NAME}
EXPORT libcurl-target
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
EXPORT ${TARGETS_EXPORT_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

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}
)
8 changes: 1 addition & 7 deletions src/CMakeLists.txt
Expand Up @@ -72,14 +72,8 @@ target_link_libraries(${EXE_NAME} libcurl ${CURL_LIBS})

#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}
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}
)