Skip to content

Commit

Permalink
allow user defined vcpkg dir
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-h committed Apr 26, 2023
1 parent 7816410 commit 3fdd440
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ build-*/
build_*/
cmake-build-*/

# Bundled vcpkg
/vcpkg/

# In-source-build artifacts
/CMakeFiles/
/CMakeCache.txt
Expand Down
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
cmake_minimum_required(VERSION 3.15...3.24 FATAL_ERROR)

set(MEGAMOL_VCPKG_DIR "${CMAKE_CURRENT_BINARY_DIR}/vcpkg")
set(MEGAMOL_VCPKG_VERSION "2023.04.15") # Update default-registry baseline in vcpkg-configuration.json when changing!

include(cmake/megamol_vcpkg_download.cmake)
Expand All @@ -26,11 +25,11 @@ megamol_feature_option(OPENGL_DEBUGGROUPS "Automatically inject OpenGL debug gro
megamol_feature_option(VR_INTEROP "Enable MegaMol-Unity VR Interop via Spout2" OFF "MEGAMOL_USE_OPENGL")

# option(X_VCPKG_APPLOCAL_DEPS_INSTALL "" ON) # Does currently not not work as expected, see comment on manual install below!
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_ports")
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/cmake/vcpkg_triplets") # We are using triplets with VCPKG_DISABLE_COMPILER_TRACKING set (on Windows).
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/vcpkg_ports")
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/vcpkg_triplets") # We are using triplets with VCPKG_DISABLE_COMPILER_TRACKING set (on Windows).
set(VCPKG_BOOTSTRAP_OPTIONS "-disableMetrics") # Disable Telemetry
set(VCPKG_INSTALL_OPTIONS "--clean-after-build" "--no-print-usage") # Build dirs get quite large and are usually only needed for debugging new ports.
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_BINARY_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
set(CMAKE_TOOLCHAIN_FILE "${MEGAMOL_VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")

set(ENV{VCPKG_FORCE_DOWNLOADED_BINARIES} ON) # Vcpkg should always download tools (i.e. CMake) to have consistent versions over all systems.
option(MEGAMOL_DOWNLOAD_VCPKG_CACHE "Download prebuilt dependency binaries if available" OFF)
Expand Down
47 changes: 28 additions & 19 deletions cmake/megamol_vcpkg_download.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@
# All rights reserved.
#

include(FetchContent)
mark_as_advanced(FORCE
FETCHCONTENT_BASE_DIR
FETCHCONTENT_FULLY_DISCONNECTED
FETCHCONTENT_QUIET
FETCHCONTENT_UPDATES_DISCONNECTED)
# Allow user to specify custom vcpkg directory.
set(MEGAMOL_VCPKG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg" CACHE PATH "Path to vcpkg.")
mark_as_advanced(FORCE MEGAMOL_VCPKG_DIR)

# Require git for download
find_package(Git REQUIRED)
# Download vcpkg via FetchContent (this is the default option).
if (NOT IS_DIRECTORY "${MEGAMOL_VCPKG_DIR}")
set(MEGAMOL_VCPKG_DIR "${CMAKE_CURRENT_BINARY_DIR}/vcpkg" CACHE PATH "Path to vcpkg." FORCE)

FetchContent_Declare(vcpkg-download
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
GIT_TAG ${MEGAMOL_VCPKG_VERSION}
GIT_SHALLOW TRUE
SOURCE_DIR ${MEGAMOL_VCPKG_DIR})
FetchContent_GetProperties(vcpkg-download)
if (NOT vcpkg-download_POPULATED)
message(STATUS "Fetch vcpkg ...")
FetchContent_Populate(vcpkg-download)
include(FetchContent)
mark_as_advanced(FORCE
FETCHCONTENT_SOURCE_DIR_VCPKG-DOWNLOAD
FETCHCONTENT_UPDATES_DISCONNECTED_VCPKG-DOWNLOAD)
FETCHCONTENT_BASE_DIR
FETCHCONTENT_FULLY_DISCONNECTED
FETCHCONTENT_QUIET
FETCHCONTENT_UPDATES_DISCONNECTED)

# Require git for download
find_package(Git REQUIRED)

FetchContent_Declare(vcpkg-download
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
GIT_TAG ${MEGAMOL_VCPKG_VERSION}
GIT_SHALLOW TRUE
SOURCE_DIR ${MEGAMOL_VCPKG_DIR})
FetchContent_GetProperties(vcpkg-download)
if (NOT vcpkg-download_POPULATED)
message(STATUS "Fetch vcpkg ...")
FetchContent_Populate(vcpkg-download)
mark_as_advanced(FORCE
FETCHCONTENT_SOURCE_DIR_VCPKG-DOWNLOAD
FETCHCONTENT_UPDATES_DISCONNECTED_VCPKG-DOWNLOAD)
endif ()
endif ()

0 comments on commit 3fdd440

Please sign in to comment.