Skip to content

Commit

Permalink
Move to MIXXX_VCPKG_ROOT to avoid conflicts with system wide VCPKG_ROOT
Browse files Browse the repository at this point in the history
and fail build early in case it is not correctly set
  • Loading branch information
daschuer authored Sep 28, 2022
1 parent 556da26 commit 0d9c522
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
37 changes: 18 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,40 @@ if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

# Note: ENV{VCPKG_ROOT} is the default location for the vcpkg cli tool which is
# later adjusted by CMAKE_TOOLCHAIN_FILE. We use it here as a workaround to find the
# overlay folders in manifest mode https://github.com/microsoft/vcpkg/issues/12289.
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED VCPKG_ROOT)
if(EXISTS "$ENV{VCPKG_ROOT}/overlay/ports" OR NOT EXISTS "$ENV{VCPKG_ROOT}/ports")
# We assume ENV{VCPKG_ROOT} points to our vcpkg environment
# 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 "Setting VCKG_ROOT from environment: $ENV{VCPKG_ROOT}")
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}")
message(STATUS "Using MIXXX_VCPKG_ROOT: $ENV{MIXXX_VCPKG_ROOT}")
else()
# The official GitHub Actions runner images sometimes set these
# variables, but we don't want to use vcpkg from the runner. If we use
# vcpkg, we use our own prebuilt environment, not the one from the image.
message(STATUS "Ignoring env VCKG_ROOT (missing $ENV{VCPKG_ROOT}/overlay/ports)")
message(FATAL_ERROR "MIXXX_VCPKG_ROOT not correct (missing $ENV{MIXXX_VCPKG_ROOT}/overlay/ports)")
endif()
endif()

if(DEFINED VCPKG_ROOT)
if(NOT DEFINED VCPKG_OVERLAY_PORTS)
# required for manifest mode
set(VCPKG_OVERLAY_PORTS "${VCPKG_ROOT}/overlay/ports")
set(VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/ports")
if(APPLE)
list(APPEND VCPKG_OVERLAY_PORTS "${VCPKG_ROOT}/overlay/osx")
list(APPEND VCPKG_OVERLAY_PORTS "${MIXXX_VCPKG_ROOT}/overlay/osx")
elseif(WIN32)
list(APPEND VCPKG_OVERLAY_PORTS "${VCPKG_ROOT}/overlay/windows")
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 "${VCPKG_ROOT}/overlay/triplets")
set(VCPKG_OVERLAY_TRIPLETS "${MIXXX_VCPKG_ROOT}/overlay/triplets")
endif()

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

Expand Down
10 changes: 5 additions & 5 deletions tools/windows_buildenv.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM this í is just to force some editors to recognize this file as ANSI, not UTF8.
REM this is just to force some editors to recognize this file as ANSI, not UTF8.

CALL :REALPATH %~dp0\..
SET MIXXX_ROOT=%RETVAL%
Expand Down 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 0d9c522

Please sign in to comment.