[vcpkg.cmake] PREPEND CMAKE_FIND_ROOT_PATH (#17336)

* [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 <mazzucan@outlook.com>

* Update scripts/buildsystems/vcpkg.cmake

Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com>
Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
This commit is contained in:
autoantwort 2021-06-24 00:30:46 +02:00 committed by GitHub
parent 2ed44b4546
commit 876e67c26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -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 This variable can be set to a list of additional command line parameters to pass to the vcpkg tool during automatic
installation. 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` #### `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 This variable can be set to a list of feature flags to pass to the vcpkg tool during automatic installation to opt-in to

View File

@ -47,6 +47,7 @@ mark_as_advanced(VCPKG_VERBOSE)
option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON) 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_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(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 # Manifest options and settings
if(NOT DEFINED VCPKG_MANIFEST_DIR) if(NOT DEFINED VCPKG_MANIFEST_DIR)
@ -379,29 +380,35 @@ set(_VCPKG_INSTALLED_DIR "${VCPKG_INSTALLED_DIR}"
CACHE PATH CACHE PATH
"The directory which contains the installed libraries for each triplet" FORCE) "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. 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}/debug"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" "${_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}/debug/lib/manual-link"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/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}/debug"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" "${_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. 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}"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" "${_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}/lib/manual-link"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/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}"
"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug"
) )