diff --git a/CMakeLists.txt b/CMakeLists.txt index 60f01ea7f48..a9dbc967ef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ if (VCPKG_TARGET_ANDROID) include("Ladybird/Android/vcpkg_android.cmake") endif() +# Pass additional information to vcpkg toolchain files if we are using vcpkg. +if (CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg.cmake$") + set(CMAKE_PROJECT_ladybird_INCLUDE_BEFORE "Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake") +endif() + project(ladybird VERSION 0.1.0 LANGUAGES C CXX diff --git a/Meta/CMake/vcpkg/base-triplets/arm64-linux.cmake b/Meta/CMake/vcpkg/base-triplets/arm64-linux.cmake index 8c993d71e58..a5e57a1ec7d 100644 --- a/Meta/CMake/vcpkg/base-triplets/arm64-linux.cmake +++ b/Meta/CMake/vcpkg/base-triplets/arm64-linux.cmake @@ -2,4 +2,4 @@ set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_TARGET_ARCHITECTURE arm64) set(VCPKG_CRT_LINKAGE dynamic) -include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL) +include(${CMAKE_CURRENT_LIST_DIR}/base.cmake) diff --git a/Meta/CMake/vcpkg/base-triplets/arm64-osx.cmake b/Meta/CMake/vcpkg/base-triplets/arm64-osx.cmake index 9d0bb3e55c6..312c49acc42 100644 --- a/Meta/CMake/vcpkg/base-triplets/arm64-osx.cmake +++ b/Meta/CMake/vcpkg/base-triplets/arm64-osx.cmake @@ -3,4 +3,4 @@ set(VCPKG_TARGET_ARCHITECTURE arm64) set(VCPKG_OSX_ARCHITECTURES arm64) set(VCPKG_CRT_LINKAGE dynamic) -include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL) +include(${CMAKE_CURRENT_LIST_DIR}/base.cmake) diff --git a/Meta/CMake/vcpkg/base-triplets/base.cmake b/Meta/CMake/vcpkg/base-triplets/base.cmake new file mode 100644 index 00000000000..6e00403cfc9 --- /dev/null +++ b/Meta/CMake/vcpkg/base-triplets/base.cmake @@ -0,0 +1,2 @@ +include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL) +include(${_VCPKG_INSTALLED_DIR}/../build-vcpkg-variables.cmake OPTIONAL) diff --git a/Meta/CMake/vcpkg/base-triplets/x64-linux.cmake b/Meta/CMake/vcpkg/base-triplets/x64-linux.cmake index 6e161607a2a..2365fba7d98 100644 --- a/Meta/CMake/vcpkg/base-triplets/x64-linux.cmake +++ b/Meta/CMake/vcpkg/base-triplets/x64-linux.cmake @@ -2,4 +2,4 @@ set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) -include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL) +include(${CMAKE_CURRENT_LIST_DIR}/base.cmake) diff --git a/Meta/CMake/vcpkg/base-triplets/x64-osx.cmake b/Meta/CMake/vcpkg/base-triplets/x64-osx.cmake index 5e3bd5316d1..ce125bc4ede 100644 --- a/Meta/CMake/vcpkg/base-triplets/x64-osx.cmake +++ b/Meta/CMake/vcpkg/base-triplets/x64-osx.cmake @@ -3,4 +3,4 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_OSX_ARCHITECTURES x86_64) set(VCPKG_CRT_LINKAGE dynamic) -include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL) +include(${CMAKE_CURRENT_LIST_DIR}/base.cmake) diff --git a/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake b/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake new file mode 100644 index 00000000000..a43a4493d69 --- /dev/null +++ b/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake @@ -0,0 +1,11 @@ +# The generated file here is read by vcpkg/base-triplets/base.cmake to ensure consistency between the project +# build and the vcpkg build. +set(EXTRA_VCPKG_VARIABLES "") +if (NOT "${CMAKE_C_COMPILER}" STREQUAL "") + string(APPEND EXTRA_VCPKG_VARIABLES "set(ENV{CC} ${CMAKE_C_COMPILER})\n") +endif() +if (NOT "${CMAKE_CXX_COMPILER}" STREQUAL "") + string(APPEND EXTRA_VCPKG_VARIABLES "set(ENV{CXX} ${CMAKE_CXX_COMPILER})\n") +endif() + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/build-vcpkg-variables.cmake" "${EXTRA_VCPKG_VARIABLES}")