Skip to content

Commit cf2ea1d

Browse files
committed
Use 'check_required_components' macro to check missing components
1 parent 8d04c1c commit cf2ea1d

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

Foo/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ write_basic_package_version_file(
9191
# Use variables:
9292
# * targets_export_name
9393
# * PROJECT_NAME
94-
configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY)
94+
configure_package_config_file(
95+
"cmake/Config.cmake.in"
96+
"${project_config}"
97+
INSTALL_DESTINATION "${config_install_dir}"
98+
)
9599

96100
# Targets:
97101
# * <prefix>/lib/libbar.a

Foo/cmake/Config.cmake.in

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
set(_package_components "${@PROJECT_NAME@_FIND_COMPONENTS}")
2-
string(COMPARE NOTEQUAL "${_package_components}" "" _has_components)
3-
if(_has_components)
4-
set(_error_message "Package `@PROJECT_NAME@` has no components:")
5-
foreach(x ${_package_components})
6-
set(_error_message "${_error_message}\n ${x}")
7-
endforeach()
8-
set(
9-
_error_message
10-
"${_error_message}\nPlease check your `find_package` call."
11-
)
12-
13-
message(FATAL_ERROR "${_error_message}")
14-
endif()
1+
@PACKAGE_INIT@
152

163
include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
4+
check_required_components("@PROJECT_NAME@")

0 commit comments

Comments
 (0)