Truly independent web browser
# 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 WIN32)
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()
elseif (CMAKE_C_COMPILER MATCHES "clang-cl")
find_program(clang_cl_path "${CMAKE_C_COMPILER}" NO_CACHE REQUIRED)
find_program(clang_cl_cxx_path "${CMAKE_CXX_COMPILER}" NO_CACHE REQUIRED)
string(APPEND EXTRA_VCPKG_VARIABLES "list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS \"-DCMAKE_C_COMPILER=${clang_cl_path}\" \"-DCMAKE_CXX_COMPILER=${clang_cl_cxx_path}\")\n")
# LLVM's manifest merging produces executables that Windows refuses to load when a port provides its own manifest,
# as Qt does: https://github.com/llvm/llvm-project/issues/57715
string(APPEND EXTRA_VCPKG_VARIABLES "cmake_path(SET ladybird_msvc_linker_path NORMALIZE \"\$ENV{VCToolsInstallDir}/bin/Hostx64/x64/link.exe\")\n")
string(APPEND EXTRA_VCPKG_VARIABLES "cmake_path(SET ladybird_windows_sdk_mt_path NORMALIZE \"\$ENV{WindowsSdkVerBinPath}/x64/mt.exe\")\n")
string(APPEND EXTRA_VCPKG_VARIABLES "list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS \"-DCMAKE_LINKER=\${ladybird_msvc_linker_path}\" \"-DCMAKE_MT=\${ladybird_windows_sdk_mt_path}\")\n")
# Meson looks up lld-link by name when it detects clang-cl.
cmake_path(GET clang_cl_path PARENT_PATH llvm_bin_directory)
string(APPEND EXTRA_VCPKG_VARIABLES "set(ENV{PATH} \"${llvm_bin_directory};\$ENV{PATH}\")\n")
# Scanning resource files' dependencies passes vcpkg's /c65001 RC flag to clang-cl, which rejects it.
string(APPEND EXTRA_VCPKG_VARIABLES "list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_NINJA_CMCLDEPS_RC=OFF)\n")
endif()
# Workaround for bad patchelf interaction with binutils 2.43.50
# https://github.com/LadybirdBrowser/ladybird/issues/2149
# https://github.com/microsoft/vcpkg/issues/41576
# https://github.com/NixOS/patchelf/issues/568
# https://bugzilla.redhat.com/show_bug.cgi?id=2319341
if (LINUX AND NOT LAGOM_USE_LINKER)
string(APPEND EXTRA_VCPKG_VARIABLES "set(ENV{LDFLAGS} -Wl,-z,noseparate-code)\n")
endif()
if (CMAKE_OSX_DEPLOYMENT_TARGET)
string(APPEND EXTRA_VCPKG_VARIABLES "set(VCPKG_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET})\n")
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/build-vcpkg-variables.cmake" "${EXTRA_VCPKG_VARIABLES}")
# Munge the VCPKG_TRIPLET to correspond to the right one for our presets
# Just make sure not to override if the developer is trying to cross-compile
# or the developer set it manually, or if this is not the first run of CMake
if (NOT DEFINED CACHE{VCPKG_TARGET_TRIPLET} AND NOT DEFINED CACHE{VCPKG_HOST_TRIPLET} AND NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
# Only tweak settings if there's custom triplets defined
if (NOT DEFINED CACHE{VCPKG_OVERLAY_TRIPLETS})
return()
endif()
# And then, only tweak settings if the triplets are ours
cmake_path(IS_PREFIX CMAKE_CURRENT_SOURCE_DIR "${VCPKG_OVERLAY_TRIPLETS}" NORMALIZE TRIPLET_IS_OURS)
if (NOT TRIPLET_IS_OURS)
return()
endif()
set(arch "")
set(os "")
# The CMake way to do uname -{m,s} checks
cmake_host_system_information(RESULT os_platform QUERY OS_PLATFORM)
cmake_host_system_information(RESULT os_name QUERY OS_NAME)
if(os_platform MATCHES "^(x86_64|AMD64|amd64)$")
set(arch x64)
elseif(os_platform STREQUAL "riscv64")
set(arch riscv64)
elseif(os_platform MATCHES "^(aarch64|arm64|ARM64)$")
set(arch arm64)
else()
message(FATAL_ERROR "Unable to automatically detect architecture for vcpkg, please set VCPKG_TARGET_TRIPLET manually")
endif()
if (os_name STREQUAL "Linux")
set(os linux)
elseif (os_name MATCHES "Darwin|macOS")
set(os osx)
elseif (os_name MATCHES "Windows")
set(os windows)
elseif (os_name MATCHES "FreeBSD")
set(os freebsd)
else()
message(FATAL_ERROR "Unable to automatically detect os name for vcpkg, please set VCPKG_TARGET_TRIPLET manually")
endif()
set(full_triplet "${arch}-${os}")
# NOTE: This will break if we start putting a trailing / on the triplet paths :|
cmake_path(GET VCPKG_OVERLAY_TRIPLETS FILENAME triplet_path)
string(REPLACE "-triplets" "" triplet_path ${triplet_path})
string(TOLOWER ${triplet_path} triplet_path)
if (NOT triplet_path STREQUAL "distribution")
if (NOT os_name MATCHES "Windows") #NOTE: Windows defaults to dynamic linking
set(full_triplet "${full_triplet}-dynamic")
endif()
elseif (os_name MATCHES "Windows")
set(full_triplet "${full_triplet}-static")
endif()
message(STATUS "Determined host VCPKG_TARGET_TRIPLET: ${full_triplet}")
set(VCPKG_TARGET_TRIPLET ${full_triplet} CACHE STRING "")
set(VCPKG_HOST_TRIPLET ${full_triplet} CACHE STRING "")
endif()