From 6bc36ee715a69d4f51200800ce93db7cac358732 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Wed, 25 Dec 2024 19:45:02 +0100 Subject: [PATCH] Add GenerateTriplet function --- cmake/functions/GenerateTriplet.cmake | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cmake/functions/GenerateTriplet.cmake diff --git a/cmake/functions/GenerateTriplet.cmake b/cmake/functions/GenerateTriplet.cmake new file mode 100644 index 0000000..885aa8e --- /dev/null +++ b/cmake/functions/GenerateTriplet.cmake @@ -0,0 +1,43 @@ +function(GenerateTriplet OUTPUT_VARIABLE) + # Determine system architecture + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCH "x64") + elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(ARCH "x86") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch)64$") + set(ARCH "arm64") + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch).*") + set(ARCH "arm") + else() + message(FATAL_ERROR "Unsupported architecture") + return() + endif() + + # Determine OS and create vcpkg-compatible triplet + if(WIN32) + # Windows triplets: x64-windows, x64-windows-static, x64-windows-dynamic + if(BUILD_SHARED_LIBS) + set(TRIPLET "${ARCH}-windows-dynamic") + else() + set(TRIPLET "${ARCH}-windows-static") + endif() + elseif(APPLE) + if (IOS) + set(TRIPLET "${ARCH}-ios") + else () + # macOS triplets: x64-osx, arm64-osx + set(TRIPLET "${ARCH}-osx") + endif () + elseif(UNIX) + # Linux triplets: x64-linux, arm64-linux + set(TRIPLET "${ARCH}-linux") + else() + message(FATAL_ERROR "Unsupported operating system") + return() + endif() + + message(STATUS "Generated vcpkg-compatible triplet: ${TRIPLET}") + + # Set the output variable in the parent scope + set(${OUTPUT_VARIABLE} ${TRIPLET} PARENT_SCOPE) +endfunction() \ No newline at end of file