Skip to content

Commit

Permalink
[vcpkg.cmake] PREPEND CMAKE_FIND_ROOT_PATH (#17336)
Browse files Browse the repository at this point in the history
* [vcpkg.cmake] PREPEND CMAKE_FIND_ROOT_PATH

* [vcpkg.cmake] make PREPEND optional (default off, option VCPKG_PREFER_VCPKG_LIBS)

* Apply suggestions from code review

Co-authored-by: nicole mazzuca <[email protected]>

* Update scripts/buildsystems/vcpkg.cmake

Co-authored-by: nicole mazzuca <[email protected]>
Co-authored-by: nicole mazzuca <[email protected]>
  • Loading branch information
3 people authored Jun 23, 2021
1 parent 2ed44b4 commit 876e67c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/users/manifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ Defaults to `OFF`.
This variable can be set to a list of additional command line parameters to pass to the vcpkg tool during automatic
installation.

#### `VCPKG_PREFER_SYSTEM_LIBS`

This variable controls whether vcpkg will appends instead of prepends its paths to `CMAKE_PREFIX_PATH`, `CMAKE_LIBRARY_PATH` and `CMAKE_FIND_ROOT_PATH` so that vcpkg libraries/packages are found after toolchain/system libraries/packages.

Defaults to `OFF`.

#### `VCPKG_FEATURE_FLAGS`

This variable can be set to a list of feature flags to pass to the vcpkg tool during automatic installation to opt-in to
Expand Down
19 changes: 13 additions & 6 deletions scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mark_as_advanced(VCPKG_VERBOSE)
option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON)
option(X_VCPKG_APPLOCAL_DEPS_SERIALIZED "(experimental) Add USES_TERMINAL to VCPKG_APPLOCAL_DEPS to force serialization." OFF)
option(X_VCPKG_APPLOCAL_DEPS_INSTALL "(experimental) Automatically copy dependencies into the install target directory for executables." OFF)
option(VCPKG_PREFER_SYSTEM_LIBS "Appends the vcpkg paths to CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH and CMAKE_FIND_ROOT_PATH so that vcpkg libraries/packages are found after toolchain/system libraries/packages." OFF)

# Manifest options and settings
if(NOT DEFINED VCPKG_MANIFEST_DIR)
Expand Down Expand Up @@ -379,29 +380,35 @@ set(_VCPKG_INSTALLED_DIR "${VCPKG_INSTALLED_DIR}"
CACHE PATH
"The directory which contains the installed libraries for each triplet" FORCE)

if(VCPKG_PREFER_SYSTEM_LIBS)
set(Z_VCPKG_PATH_LIST_OP APPEND)
else()
set(Z_VCPKG_PATH_LIST_OP PREPEND)
endif()

if(CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$" OR NOT DEFINED CMAKE_BUILD_TYPE) #Debug build: Put Debug paths before Release paths.
list(APPEND CMAKE_PREFIX_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_PREFIX_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
)
list(APPEND CMAKE_LIBRARY_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_LIBRARY_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib/manual-link"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/manual-link"
)
list(APPEND CMAKE_FIND_ROOT_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_FIND_ROOT_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
)
else() #Release build: Put Release paths before Debug paths. Debug Paths are required so that CMake generates correct info in autogenerated target files.
list(APPEND CMAKE_PREFIX_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_PREFIX_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug"
)
list(APPEND CMAKE_LIBRARY_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_LIBRARY_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/manual-link"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib/manual-link"
)
list(APPEND CMAKE_FIND_ROOT_PATH
list(${Z_VCPKG_PATH_LIST_OP} CMAKE_FIND_ROOT_PATH
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug"
)
Expand Down

0 comments on commit 876e67c

Please sign in to comment.