From a554a1dfb8a468d6df786acc0bb1ad045eb044e9 Mon Sep 17 00:00:00 2001 From: Rick Mark Date: Thu, 11 Jan 2024 18:05:45 -0800 Subject: [PATCH] By default compile as universal2 for macOS (#2221) --- CMakeLists.txt | 6 ++++++ bindings/python/setup.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81c9d711b4..b983339df8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ endif() # Don't edit the makefile! option(BUILD_SHARED_LIBS "Build shared library" OFF) option(CAPSTONE_BUILD_STATIC_RUNTIME "Embed static runtime" ${BUILD_SHARED_LIBS}) +option(CAPSTONE_BUILD_MACOS_THIN "Disable universal2 builds on macOS" OFF) option(CAPSTONE_BUILD_DIET "Build diet library" OFF) option(CAPSTONE_BUILD_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL}) option(CAPSTONE_BUILD_CSTOOL "Build cstool" ${PROJECT_IS_TOP_LEVEL}) @@ -57,6 +58,11 @@ option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by defau option(CAPSTONE_DEBUG "Whether to enable extra debug assertions" OFF) 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") +endif() + set(SUPPORTED_ARCHITECTURES ARM AARCH64 M68K MIPS PPC SPARC SYSZ XCORE X86 TMS320C64X M680X EVM MOS65XX WASM BPF RISCV SH TRICORE ALPHA) set(SUPPORTED_ARCHITECTURE_LABELS ARM AARCH64 M68K MIPS PowerPC Sparc SystemZ XCore x86 TMS320C64x M680x EVM MOS65XX WASM BPF RISCV SH TriCore Alpha) diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 09fc78645b..92ebf2d337 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -136,14 +136,19 @@ def build_libraries(): os.chdir(BUILD_DIR) # platform description refers at https://docs.python.org/2/library/sys.html#sys.platform - if SYSTEM == "win32": + # Use cmake for both Darwin and Windows since it can generate fat binaries + if SYSTEM == "win32" or SYSTEM == 'darwin': # Windows build: this process requires few things: # - CMake + MSVC installed # - Run this command in an environment setup for MSVC if not os.path.exists("build"): os.mkdir("build") os.chdir("build") - # Only build capstone.dll - os.system('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "NMake Makefiles" ..') + print("Build Directory: {}\n".format(os.getcwd())) + # Only build capstone.dll / libcapstone.dylib + if SYSTEM == "win32": + os.system('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "NMake Makefiles" ..') + else: + os.system('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCAPSTONE_BUILD_TESTS=OFF -DCAPSTONE_BUILD_CSTOOL=OFF -G "Unix Makefiles" ..') os.system("cmake --build .") else: # Unix incl. cygwin os.system("CAPSTONE_BUILD_CORE_ONLY=yes bash ./make.sh")