Skip to content

Commit

Permalink
CMake: Rename our triplets to their canonical names
Browse files Browse the repository at this point in the history
Becuase we're using dynamic libraries, our configuration is
classified as a "community triplet". To not confuse vcpkg
maintainers when developers create bug reports, name them
properly. This means that the default triplet detection is now
kind of useless, so we have to invent our own for these triplets.
  • Loading branch information
ADKaster committed Dec 22, 2024
1 parent 89061dd commit 673537b
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lagom-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
run: |
set -e
cmake --preset=CI -S Meta/Lagom -B ${{ github.workspace }}/Build/tools-build \
cmake --preset=Distribution_CI -S Meta/Lagom -B ${{ github.workspace }}/Build/tools-build \
-DLAGOM_TOOLS_ONLY=ON \
-DINSTALL_LAGOM_TOOLS=ON \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/Build/tools-install \
Expand Down
2 changes: 2 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@
"description": "Fuzzers build",
"binaryDir": "${fileDir}/Build/fuzzers",
"cacheVariables": {
"BUILD_SHARED_LIBS": "OFF",
"CMAKE_BUILD_TYPE": "",
"ENABLE_QT": "OFF",
"VCPKG_OVERLAY_TRIPLETS": "${fileDir}/Meta/CMake/vcpkg/distribution-triplets",
"ENABLE_FUZZERS_LIBFUZZER": "ON",
"ENABLE_ADDRESS_SANITIZER": "ON"
}
Expand Down
51 changes: 51 additions & 0 deletions Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,54 @@ if (LINUX AND NOT LAGOM_USE_LINKER)
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 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
if (NOT VCPKG_OVERLAY_TRIPLETS MATCHES "^${CMAKE_CURRENT_SOURCE_DIR}")
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 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)
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")
set(full_triplet "${full_triplet}-dynamic")
endif()

message(STATUS "Determined host VCPKG_TARGET_TRIPLET: ${full_triplet}")
set(VCPKG_TARGET_TRIPLET ${full_triplet} CACHE STRING "")
endif()

0 comments on commit 673537b

Please sign in to comment.