Skip to content

Commit

Permalink
Merge pull request #10904 from daschuer/vcpkg_root_fix
Browse files Browse the repository at this point in the history
Vcpkg root fix
  • Loading branch information
Holzhaus authored Sep 28, 2022
2 parents 2994e27 + 3415b85 commit c12f6ff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
44 changes: 37 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,48 @@ if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

# Check if any relevant env vars were set from the build env scripts
if(DEFINED ENV{X_VCPKG_APPLOCAL_DEPS_INSTALL} AND NOT DEFINED X_VCPKG_APPLOCAL_DEPS_INSTALL)
set(X_VCPKG_APPLOCAL_DEPS_INSTALL "$ENV{X_VCPKG_APPLOCAL_DEPS_INSTALL}" CACHE BOOL "")
# We use here ENV{MIXXX_VCPKG_ROOT} as a workaround to find the overlay folders
# in manifest mode https://github.com/microsoft/vcpkg/issues/12289.
# Note: VCPKG_ROOT, the default location for the vcpkg cli tool is later
# adjusted by CMAKE_TOOLCHAIN_FILE.
if(DEFINED ENV{MIXXX_VCPKG_ROOT} AND NOT DEFINED MIXXX_VCPKG_ROOT)
set(MIXXX_VCPKG_ROOT "$ENV{MIXXX_VCPKG_ROOT}")
endif()

if(DEFINED MIXXX_VCPKG_ROOT)
if(EXISTS "$ENV{MIXXX_VCPKG_ROOT}/overlay/ports" OR NOT EXISTS "$ENV{MIXXX_VCPKG_ROOT}/ports")
# MIXXX_VCPKG_ROOT points to our vcpkg environment
# and we configure the CMAKE_TOOLCHAIN_FILE and overlays accordingly
message(STATUS "Using MIXXX_VCPKG_ROOT: $ENV{MIXXX_VCPKG_ROOT}")
else()
message(FATAL_ERROR "MIXXX_VCPKG_ROOT not correct (missing $ENV{MIXXX_VCPKG_ROOT}/overlay/ports)")
endif()

if(NOT DEFINED VCPKG_OVERLAY_PORTS)
# required for manifest mode
set(VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/ports")
if(APPLE)
list(APPEND VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/osx")
elseif(WIN32)
list(APPEND VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/windows")
endif()
endif()

if(NOT DEFINED VCPKG_OVERLAY_TRIPLETS)
# required for manifest mode
set(VCPKG_OVERLAY_TRIPLETS "${MIXXX_VCPKG_ROOT}/overlay/triplets")
endif()

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${MIXXX_VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()
endif()

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}")
endif()
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON CACHE BOOL "Automatically copy dependencies into the install target directory for executables." FORCE)

if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()

# Set a default build type if none was specified
# See https://blog.kitware.com/cmake-and-the-default-build-type/ for details.
Expand Down
8 changes: 4 additions & 4 deletions tools/windows_buildenv.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IF "%~1"=="" (
)

REM Make These permanent, not local to the batch script.
ENDLOCAL & SET "VCPKG_ROOT=%VCPKG_ROOT%" & SET "VCPKG_DEFAULT_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" & SET "X_VCPKG_APPLOCAL_DEPS_INSTALL=%X_VCPKG_APPLOCAL_DEPS_INSTALL%" & SET "CMAKE_GENERATOR=%CMAKE_GENERATOR%"
ENDLOCAL & SET "MIXXX_VCPKG_ROOT=%MIXXX_VCPKG_ROOT%" & SET "VCPKG_DEFAULT_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" & SET "X_VCPKG_APPLOCAL_DEPS_INSTALL=%X_VCPKG_APPLOCAL_DEPS_INSTALL%" & SET "CMAKE_GENERATOR=%CMAKE_GENERATOR%"

EXIT /B 0

Expand Down Expand Up @@ -86,19 +86,19 @@ EXIT /B 0

ECHO ^Build environment path: !BUILDENV_PATH!

SET "VCPKG_ROOT=!BUILDENV_PATH!"
SET "MIXXX_VCPKG_ROOT=!BUILDENV_PATH!"
SET "VCPKG_DEFAULT_TRIPLET=x64-windows"
SET "X_VCPKG_APPLOCAL_DEPS_INSTALL=ON"
SET "CMAKE_GENERATOR=Ninja"

ECHO ^Environment Variables:
ECHO ^- VCPKG_ROOT='!VCPKG_ROOT!'
ECHO ^- MIXXX_VCPKG_ROOT='!MIXXX_VCPKG_ROOT!'
ECHO ^- VCPKG_DEFAULT_TRIPLET='!VCPKG_DEFAULT_TRIPLET!'
ECHO ^- X_VCPKG_APPLOCAL_DEPS_INSTALL='!X_VCPKG_APPLOCAL_DEPS_INSTALL!'
ECHO ^- CMAKE_GENERATOR='!CMAKE_GENERATOR!'

IF DEFINED GITHUB_ENV (
ECHO VCPKG_ROOT=!VCPKG_ROOT!>>!GITHUB_ENV!
ECHO MIXXX_VCPKG_ROOT=!MIXXX_VCPKG_ROOT!>>!GITHUB_ENV!
ECHO VCPKG_DEFAULT_TRIPLET=!VCPKG_DEFAULT_TRIPLET!>>!GITHUB_ENV!
ECHO X_VCPKG_APPLOCAL_DEPS_INSTALL=!X_VCPKG_APPLOCAL_DEPS_INSTALL!>>!GITHUB_ENV!
ECHO CMAKE_GENERATOR=!CMAKE_GENERATOR!>>!GITHUB_ENV!
Expand Down

0 comments on commit c12f6ff

Please sign in to comment.