]> granicus.if.org Git - curl/commitdiff
CMake: Improve config installation
authorRuslan Baratov <ruslan_baratov@yahoo.com>
Tue, 17 Jul 2018 23:31:51 +0000 (02:31 +0300)
committerJay Satiro <raysatiro@yahoo.com>
Mon, 1 Oct 2018 20:16:29 +0000 (16:16 -0400)
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

CMake/curl-config.cmake.in
CMakeLists.txt
lib/CMakeLists.txt
src/CMakeLists.txt

index 40c1288e15465be6110a69b830471b54b336f007..2cae644c06caec0246d60455839784fbf66e703b 100644 (file)
@@ -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@")
index 26d4980fcb7e168b127163bd17bd9036531e243f..4d760536459a920fbe8ed6f8bdb3870a39f0b7db 100644 (file)
@@ -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})
+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)
@@ -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
@@ -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)
@@ -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}
 )
 
index be6f7a249fec0b67aca02de24ceca8bb3ab1d5c3..eca9a8af934e18a66623bb7a05f8252d9d005484 100644 (file)
@@ -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}
-)
index d3ea3e23b5c3dd742192a7a7941cc59e3c802dce..f10a3d0bba7b31f09208db21724725f5a1737cda 100644 (file)
@@ -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}
-)