diff --git a/CMakeLists.txt b/CMakeLists.txt index 602f3dc3a1..b0a1c183cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1849,23 +1849,14 @@ install(EXPORT netCDFTargets NAMESPACE netCDF:: ) +export(EXPORT netCDFTargets FILE netCDFTargets.cmake NAMESPACE netCDF::) + include(CMakePackageConfigHelpers) -CONFIGURE_PACKAGE_CONFIG_file( +configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/netCDFConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/netCDFConfig.cmake" INSTALL_DESTINATION "${ConfigPackageLocation}" - NO_CHECK_REQUIRED_COMPONENTS_MACRO - PATH_VARS - CMAKE_INSTALL_PREFIX - CMAKE_INSTALL_INCLUDEDIR - CMAKE_INSTALL_LIBDIR - ) - -install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/netCDFConfig.cmake" - DESTINATION "${ConfigPackageLocation}" - COMPONENT headers - ) +) add_library(netCDF::netcdf ALIAS netcdf) target_include_directories(netcdf @@ -1876,17 +1867,18 @@ target_include_directories(netcdf # Create export configuration write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/netCDF/netCDFConfigVersion.cmake" + netCDFConfigVersion.cmake VERSION ${netCDF_VERSION} COMPATIBILITY SameMajorVersion - ) +) install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/netCDF/netCDFConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/netCDFConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/netCDFConfigVersion.cmake" DESTINATION ${ConfigPackageLocation} COMPONENT headers - ) +) #### # End export files diff --git a/netCDFConfig.cmake.in b/netCDFConfig.cmake.in index 7adef5cf9c..66638e7d23 100644 --- a/netCDFConfig.cmake.in +++ b/netCDFConfig.cmake.in @@ -5,9 +5,6 @@ @PACKAGE_INIT@ set(NetCDFVersion "@PACKAGE_VERSION@") -set_and_check(netCDF_INSTALL_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@") -set_and_check(netCDF_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") -set_and_check(netCDF_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@") set(netCDF_LIBRARIES netCDF::netcdf)