diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index a25f0f716c1d7b..698e83aaf27e3c 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -380,39 +380,24 @@ 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(${Z_VCPKG_PATH_LIST_OP} CMAKE_PREFIX_PATH - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" - ) - 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(${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(${Z_VCPKG_PATH_LIST_OP} CMAKE_PREFIX_PATH - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" - ) - 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" +function(z_vcpkg_add_vcpkg_to_cmake_path list suffix) + set(vcpkg_paths + "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}${suffix}" + "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug${suffix}" ) - list(${Z_VCPKG_PATH_LIST_OP} CMAKE_FIND_ROOT_PATH - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" - "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug" - ) -endif() + if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE MATCHES "^[Dd][Ee][Bb][Uu][Gg]$") + list(REVERSE vcpkg_paths) # Debug build: Put Debug paths before Release paths. + endif() + if(VCPKG_PREFER_SYSTEM_LIBS) + list(APPEND "${list}" "${vcpkg_paths}") + else() + list(INSERT "${list}" 0 "${vcpkg_paths}") # CMake 3.15 is required for list(PREPEND ...). + endif() + set("${list}" "${${list}}" PARENT_SCOPE) +endfunction() +z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_PREFIX_PATH "") +z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_LIBRARY_PATH "/lib/manual-link") +z_vcpkg_add_vcpkg_to_cmake_path(CMAKE_FIND_ROOT_PATH "") # If one CMAKE_FIND_ROOT_PATH_MODE_* variables is set to ONLY, to make sure that ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET} # and ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug are searched, it is not sufficient to just add them to CMAKE_FIND_ROOT_PATH, diff --git a/scripts/test_ports/cmake/vcpkg.json b/scripts/test_ports/cmake/vcpkg.json index 541ea1d77bb7b2..a57bd1d3d46ea5 100644 --- a/scripts/test_ports/cmake/vcpkg.json +++ b/scripts/test_ports/cmake/vcpkg.json @@ -1,6 +1,7 @@ { "name": "cmake", "version-string": "3.20.0", + "port-version": 1, "description": "CMake is an open-source, cross-platform family of tools designed to build, test and package software.", "homepage": "https://cmake.org/", "dependencies": [