diff --git a/Foo/CMakeLists.txt b/Foo/CMakeLists.txt index cf44a62..19155b8 100644 --- a/Foo/CMakeLists.txt +++ b/Foo/CMakeLists.txt @@ -91,7 +91,11 @@ write_basic_package_version_file( # Use variables: # * targets_export_name # * PROJECT_NAME -configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY) +configure_package_config_file( + "cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) # Targets: # * /lib/libbar.a diff --git a/Foo/cmake/Config.cmake.in b/Foo/cmake/Config.cmake.in index 019131b..9b4c9ee 100644 --- a/Foo/cmake/Config.cmake.in +++ b/Foo/cmake/Config.cmake.in @@ -1,16 +1,4 @@ -set(_package_components "${@PROJECT_NAME@_FIND_COMPONENTS}") -string(COMPARE NOTEQUAL "${_package_components}" "" _has_components) -if(_has_components) - set(_error_message "Package `@PROJECT_NAME@` has no components:") - foreach(x ${_package_components}) - set(_error_message "${_error_message}\n ${x}") - endforeach() - set( - _error_message - "${_error_message}\nPlease check your `find_package` call." - ) - - message(FATAL_ERROR "${_error_message}") -endif() +@PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") +check_required_components("@PROJECT_NAME@")