Skip to content

Commit

Permalink
Add VCPKG_FIND_PACKAGE_<Pkg>
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt committed Dec 10, 2022
1 parent cf1fda5 commit f7f08f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/users/buildsystems/cmake-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,12 @@ See the `--feature-flags=` command line option for more information.

When this option is turned on, every call to `find_package` is printed.
Nested calls (e.g. via `find_dependency`) are indented according to nesting depth.

### `VCPKG_FIND_PACKAGE_<Pkg>`

When this option is turned set, non-nested calls to `find_package` are either
required (`VCPKG_FIND_PACKAGE_<Pkg>=ON`) or disabled (`VCPKG_FIND_PACKAGE_<Pkg>=OFF`).

This variable is a tool to control direct dependencies and related features in vcpkg ports
which use the CMake build system. It can be used with `vcpkg_check_features` and avoids
unintented effects on transitive dependencies.
28 changes: 27 additions & 1 deletion scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,29 @@ macro("${VCPKG_OVERRIDE_FIND_PACKAGE_NAME}" z_vcpkg_find_package_package_name)
set(z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_ARGN "${ARGN}")
set(z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_backup_vars "")

if(z_vcpkg_find_package_backup_id EQUAL "1")
if(VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name})
# Avoid CMake warning when both REQUIRED and CMAKE_REQUIRE_FIND_PACKAGE_<Pkg> are used
if(NOT "REQUIRED" IN_LIST z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_ARGN)
list(APPEND z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_backup_vars "CMAKE_REQUIRE_FIND_PACKAGE_${z_vcpkg_find_package_package_name}")
set(z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_backup_CMAKE_REQUIRE_FIND_PACKAGE_${z_vcpkg_find_package_package_name} "${CMAKE_REQUIRE_FIND_PACKAGE_${z_vcpkg_find_package_package_name}}")
set(CMAKE_REQUIRE_FIND_PACKAGE_${z_vcpkg_find_package_package_name} 1)
endif()
if(VCPKG_TRACE_FIND_PACKAGE)
message(STATUS " (required by VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name}=${VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name}})")
endif()
elseif(DEFINED VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name})
list(APPEND z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_backup_vars "CMAKE_DISABLE_FIND_PACKAGE_${z_vcpkg_find_package_package_name}")
set(z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_backup_CMAKE_DISABLE_FIND_PACKAGE_${z_vcpkg_find_package_package_name} "${CMAKE_DISABLE_FIND_PACKAGE_${z_vcpkg_find_package_package_name}}")
set(CMAKE_DISABLE_FIND_PACKAGE_${z_vcpkg_find_package_package_name} 1)
if(VCPKG_TRACE_FIND_PACKAGE)
message(STATUS " (disabled by VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name}=${VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name}})")
endif()
elseif(VCPKG_TRACE_FIND_PACKAGE)
message(STATUS " (could be controlled by VCPKG_FIND_PACKAGE_${z_vcpkg_find_package_package_name})")
endif()
endif()

# Workaround to set the ROOT_PATH until upstream CMake stops overriding
# the ROOT_PATH at apple OS initialization phase.
# See https://gitlab.kitware.com/cmake/cmake/merge_requests/3273
Expand All @@ -783,7 +806,10 @@ macro("${VCPKG_OVERRIDE_FIND_PACKAGE_NAME}" z_vcpkg_find_package_package_name)
string(TOLOWER "${z_vcpkg_find_package_package_name}" z_vcpkg_find_package_lowercase_package_name)
set(z_vcpkg_find_package_vcpkg_cmake_wrapper_path
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/${z_vcpkg_find_package_lowercase_package_name}/vcpkg-cmake-wrapper.cmake")
if(EXISTS "${z_vcpkg_find_package_vcpkg_cmake_wrapper_path}")
if(CMAKE_DISABLE_FIND_PACKAGE_${z_vcpkg_find_package_package_name})
# Skip wrappers, fail if REQUIRED.
_find_package("${z_vcpkg_find_package_package_name}" ${z_vcpkg_find_package_${z_vcpkg_find_package_backup_id}_ARGN})
elseif(EXISTS "${z_vcpkg_find_package_vcpkg_cmake_wrapper_path}")
if(VCPKG_TRACE_FIND_PACKAGE)
string(REPEAT " " "${z_vcpkg_find_package_backup_id}" z_vcpkg_find_package_indent)
message(STATUS "${z_vcpkg_find_package_indent}using share/${z_vcpkg_find_package_lowercase_package_name}/vcpkg-cmake-wrapper.cmake")
Expand Down

0 comments on commit f7f08f0

Please sign in to comment.