Skip to content

Commit

Permalink
cmake: added feature for using external vcpkg installation
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Mar 11, 2024
1 parent b21810d commit d61ff65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ if(${CMAKE_VERSION} VERSION_LESS "3.0.2")
endmacro()
endif()

if(VCPKG_TARGET_ANDROID)
include(VcpkgAndroid)
endif()

include(VcpkgIntegration)
include(VcpkgAndroid)

option(BUILD_CLIENT "Build client library" ON)
option(BUILD_SERVER "Build server library" ON)
option(BUILD_UTILS "Build developer utilities (map/models compilers, etc.)" ON)
Expand Down
6 changes: 5 additions & 1 deletion cmake/VcpkgAndroid.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ if (VCPKG_TARGET_ANDROID)
# However, vcpkg provides a way to preload and additional toolchain,
# with the VCPKG_CHAINLOAD_TOOLCHAIN_FILE option.
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE $ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake)

set(VCPKG_INSTANCE_PATH "")
get_vcpkg_instance_path(VCPKG_INSTANCE_PATH)
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_INSTANCE_PATH})

message("VcpkgAndroid.cmake: CMAKE_TOOLCHAIN_FILE was set to ${CMAKE_TOOLCHAIN_FILE}")
message("VcpkgAndroid.cmake: VCPKG_CHAINLOAD_TOOLCHAIN_FILE was set to ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")

Expand Down
18 changes: 16 additions & 2 deletions cmake/VcpkgIntegration.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@

function(get_vcpkg_instance_path RESULT_VAR)
if(DEFINED ENV{VCPKG_ROOT})
set(${RESULT_VAR} "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" PARENT_SCOPE)
message(STATUS "External vcpkg installation found at path: $ENV{VCPKG_ROOT}")
else()
set(${RESULT_VAR} "${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake" PARENT_SCOPE)
message(STATUS "External vcpkg installation not found, submodule will be used")
endif()
endfunction()

# allows to transparently pass in custom toolchain file along with vcpkg toolchain
# include this module in main CMakeLists.txt script BEFORE project() directive
if(NOT VCPKG_TARGET_ANDROID)
set(VCPKG_INSTANCE_PATH "")
get_vcpkg_instance_path(VCPKG_INSTANCE_PATH)

if(CMAKE_TOOLCHAIN_FILE)
if (NOT CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg.cmake$")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_INSTANCE_PATH}")
endif()
else()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_INSTANCE_PATH}")
endif()
endif()

Expand Down

0 comments on commit d61ff65

Please sign in to comment.