From 673537b26bbc239bdaf4d8026d916fea020bc1a0 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 4 Dec 2024 13:33:16 -0700 Subject: [PATCH] CMake: Rename our triplets to their canonical names 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. --- .github/workflows/lagom-template.yml | 2 +- CMakePresets.json | 2 + ...-linux.cmake => arm64-linux-dynamic.cmake} | 0 ...rm64-osx.cmake => arm64-osx-dynamic.cmake} | 0 ...64-linux.cmake => x64-linux-dynamic.cmake} | 0 .../{x64-osx.cmake => x64-osx-dynamic.cmake} | 0 .../generate_vcpkg_toolchain_variables.cmake | 51 +++++++++++++++++++ ...-linux.cmake => arm64-linux-dynamic.cmake} | 0 ...rm64-osx.cmake => arm64-osx-dynamic.cmake} | 0 ...64-linux.cmake => x64-linux-dynamic.cmake} | 0 .../{x64-osx.cmake => x64-osx-dynamic.cmake} | 0 ...-linux.cmake => arm64-linux-dynamic.cmake} | 0 ...rm64-osx.cmake => arm64-osx-dynamic.cmake} | 0 ...64-linux.cmake => x64-linux-dynamic.cmake} | 0 .../{x64-osx.cmake => x64-osx-dynamic.cmake} | 0 15 files changed, 54 insertions(+), 1 deletion(-) rename Meta/CMake/vcpkg/debug-triplets/{arm64-linux.cmake => arm64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/debug-triplets/{arm64-osx.cmake => arm64-osx-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/debug-triplets/{x64-linux.cmake => x64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/debug-triplets/{x64-osx.cmake => x64-osx-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/release-triplets/{arm64-linux.cmake => arm64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/release-triplets/{arm64-osx.cmake => arm64-osx-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/release-triplets/{x64-linux.cmake => x64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/release-triplets/{x64-osx.cmake => x64-osx-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/sanitizer-triplets/{arm64-linux.cmake => arm64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/sanitizer-triplets/{arm64-osx.cmake => arm64-osx-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/sanitizer-triplets/{x64-linux.cmake => x64-linux-dynamic.cmake} (100%) rename Meta/CMake/vcpkg/sanitizer-triplets/{x64-osx.cmake => x64-osx-dynamic.cmake} (100%) diff --git a/.github/workflows/lagom-template.yml b/.github/workflows/lagom-template.yml index a0f4fec42df..0243b59006d 100644 --- a/.github/workflows/lagom-template.yml +++ b/.github/workflows/lagom-template.yml @@ -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 \ diff --git a/CMakePresets.json b/CMakePresets.json index b582a6866b3..26104bdb349 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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" } diff --git a/Meta/CMake/vcpkg/debug-triplets/arm64-linux.cmake b/Meta/CMake/vcpkg/debug-triplets/arm64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/debug-triplets/arm64-linux.cmake rename to Meta/CMake/vcpkg/debug-triplets/arm64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/debug-triplets/arm64-osx.cmake b/Meta/CMake/vcpkg/debug-triplets/arm64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/debug-triplets/arm64-osx.cmake rename to Meta/CMake/vcpkg/debug-triplets/arm64-osx-dynamic.cmake diff --git a/Meta/CMake/vcpkg/debug-triplets/x64-linux.cmake b/Meta/CMake/vcpkg/debug-triplets/x64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/debug-triplets/x64-linux.cmake rename to Meta/CMake/vcpkg/debug-triplets/x64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/debug-triplets/x64-osx.cmake b/Meta/CMake/vcpkg/debug-triplets/x64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/debug-triplets/x64-osx.cmake rename to Meta/CMake/vcpkg/debug-triplets/x64-osx-dynamic.cmake diff --git a/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake b/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake index a4c25bb9c56..99dce3beeb9 100644 --- a/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake +++ b/Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake @@ -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() diff --git a/Meta/CMake/vcpkg/release-triplets/arm64-linux.cmake b/Meta/CMake/vcpkg/release-triplets/arm64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/release-triplets/arm64-linux.cmake rename to Meta/CMake/vcpkg/release-triplets/arm64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/release-triplets/arm64-osx.cmake b/Meta/CMake/vcpkg/release-triplets/arm64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/release-triplets/arm64-osx.cmake rename to Meta/CMake/vcpkg/release-triplets/arm64-osx-dynamic.cmake diff --git a/Meta/CMake/vcpkg/release-triplets/x64-linux.cmake b/Meta/CMake/vcpkg/release-triplets/x64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/release-triplets/x64-linux.cmake rename to Meta/CMake/vcpkg/release-triplets/x64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/release-triplets/x64-osx.cmake b/Meta/CMake/vcpkg/release-triplets/x64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/release-triplets/x64-osx.cmake rename to Meta/CMake/vcpkg/release-triplets/x64-osx-dynamic.cmake diff --git a/Meta/CMake/vcpkg/sanitizer-triplets/arm64-linux.cmake b/Meta/CMake/vcpkg/sanitizer-triplets/arm64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/sanitizer-triplets/arm64-linux.cmake rename to Meta/CMake/vcpkg/sanitizer-triplets/arm64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/sanitizer-triplets/arm64-osx.cmake b/Meta/CMake/vcpkg/sanitizer-triplets/arm64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/sanitizer-triplets/arm64-osx.cmake rename to Meta/CMake/vcpkg/sanitizer-triplets/arm64-osx-dynamic.cmake diff --git a/Meta/CMake/vcpkg/sanitizer-triplets/x64-linux.cmake b/Meta/CMake/vcpkg/sanitizer-triplets/x64-linux-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/sanitizer-triplets/x64-linux.cmake rename to Meta/CMake/vcpkg/sanitizer-triplets/x64-linux-dynamic.cmake diff --git a/Meta/CMake/vcpkg/sanitizer-triplets/x64-osx.cmake b/Meta/CMake/vcpkg/sanitizer-triplets/x64-osx-dynamic.cmake similarity index 100% rename from Meta/CMake/vcpkg/sanitizer-triplets/x64-osx.cmake rename to Meta/CMake/vcpkg/sanitizer-triplets/x64-osx-dynamic.cmake