From 33e0e0feaa4db0de6114bcb55c7f2be4bf4b4e78 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 15 Aug 2024 03:47:14 -0500 Subject: [PATCH] Ensure Capstone is build for the architecture according to cibuildwheel --- CMakeLists.txt | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25fcab449c..150ee4ec7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,28 @@ option(CAPSTONE_INSTALL "Generate install target" ${PROJECT_IS_TOP_LEVEL}) # If building for OSX it's best to allow CMake to handle building both architectures if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN) - set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") + # The cibuildwheel on Github Actions sets this env variable + # with the architecture flags it wants to build for. + if(DEFINED ENV{ARCHFLAGS}) + if("$ENV{ARCHFLAGS}" STREQUAL "-arch arm64 -arch x86_64") + set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") + elseif("$ENV{ARCHFLAGS}" STREQUAL "-arch arm64") + set(CMAKE_OSX_ARCHITECTURES "arm64") + elseif("$ENV{ARCHFLAGS}" STREQUAL "-arch x86_64") + set(CMAKE_OSX_ARCHITECTURES "x86_64") + endif() + else() + set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") + endif() +endif() + +if (DEFINED ENV{VSCMD_ARG_TGT_ARCH}) + # The cibuildwheel on Github Actions sets this env variable + # with the architecture it wants to build for (for Windows). + # We need to handle the x86 case here. + if("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "x86") + set(CMAKE_GENERATOR_PLATFORM "Win32") + endif() endif() list(LENGTH SUPPORTED_ARCHITECTURES count)