From 8f7d6a3cad815335ac8c56b4755b6bbd512a2c93 Mon Sep 17 00:00:00 2001 From: mhucka Date: Thu, 12 Jun 2025 17:56:28 +0000 Subject: [PATCH 1/5] Need to set cmake version before project Some version of cmake doesn't like project() begin called at the very start. Changing the order around seems to work better. --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 703e13081..7fb348049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,17 @@ -project(qsim) - set(CMAKE_CXX_STANDARD 11) cmake_minimum_required(VERSION 3.31) -# Check if CMAKE_SYSTEM_NAME is Darwin (macOS) and CMAKE_SYSTEM_PROCESSOR is arm64 +# Set prelimary value so that other variables we need are defined +project(qsim) + +# Darwin + Arm64 => Apple Silicon, where we can't build Cuda, AVX or SSE features. if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") set(APPLE_ARM TRUE) else() set(APPLE_ARM FALSE) endif() -# Set the project name and language +# Set the project name and language more precisely if(APPLE) project(qsim LANGUAGES CXX) else() From 30fcf02c9f4c9942bc979b6dca9fdc7b30145cae Mon Sep 17 00:00:00 2001 From: mhucka Date: Thu, 12 Jun 2025 17:59:28 +0000 Subject: [PATCH 2/5] Rewrite GetPybind11.cmake to be more robust On some platforms, the previous pybind-finding code either found the wrong one, or didn't set certain cmake variables. --- pybind_interface/GetPybind11.cmake | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/pybind_interface/GetPybind11.cmake b/pybind_interface/GetPybind11.cmake index a9b4f527d..b914086a1 100644 --- a/pybind_interface/GetPybind11.cmake +++ b/pybind_interface/GetPybind11.cmake @@ -1,28 +1,40 @@ -include(FetchContent) - set(MIN_PYBIND_VERSION "2.13.6") -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG "v${MIN_PYBIND_VERSION}" -) -FetchContent_GetProperties(pybind11) -find_package(pybind11 "${MIN_PYBIND_VERSION}" CONFIG) -if (pybind11_FOUND) - message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") - # The pybind11_add_module doesn't correctly set the CXX_INCLUDES properly if a system pybind11 is found. - # Using `include_directories(${pybind11_INCLUDE_DIRS})` doesn't result in anything in - # CXX_INCLUDES. e.g., `pybind_interface/basic/CMakeFiles/qsim_basic.dir/flags.make` would only - # have `CXX_INCLUDES = -isystem $PREFIX/include/python3.11` and would miss `$PREFIX/include`. - # This problem would result in `fatal error: pybind11/complex.h: No such file or directory` - # This is a hack to get around that by passing `-I/path/to/include` to CXX_FLAGS - # Iterate over each include directory and add it as a compile option - foreach(INCLUDE_DIR ${pybind11_INCLUDE_DIRS}) - add_compile_options("-I${INCLUDE_DIR}") - endforeach() +# First, try to find pybind11 using the modern find_package() way. +find_package(pybind11 ${MIN_PYBIND_VERSION} QUIET) + +# If that doesn't work, try to use pybind11-config to find the CMake directory. +if(NOT pybind11_FOUND) + find_program(PYBIND11_CONFIG_EXECUTABLE pybind11-config) + + if(PYBIND11_CONFIG_EXECUTABLE) + # Get the CMake directory from pybind11-config + execute_process( + COMMAND ${PYBIND11_CONFIG_EXECUTABLE} --cmakedir + OUTPUT_VARIABLE pybind11_CMAKE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + # Add the discovered path to the CMake search paths and try again. + if(pybind11_CMAKE_DIR AND IS_DIRECTORY ${pybind11_CMAKE_DIR}) + list(APPEND CMAKE_PREFIX_PATH ${pybind11_CMAKE_DIR}) + find_package(pybind11 ${MIN_PYBIND_VERSION} QUIET) + endif() + endif() endif() -if((NOT pybind11_FOUND) AND (NOT pybind11_POPULATED)) # check first on system path, then attempt git fetch +# If pybind11 is still not found, use FetchContent to download it. +if(NOT pybind11_FOUND) + message(STATUS "pybind11 not found. Fetching from source.") + include(FetchContent) + + FetchContent_Declare( + pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11 + GIT_TAG "v${MIN_PYBIND_VERSION}" + OVERRIDE_FIND_PACKAGE + ) FetchContent_MakeAvailable(pybind11) +else() + message(STATUS "Found pybind11: ${pybind11_VERSION} (found version: ${pybind11_VERSION})") endif() From 383a275aa41972a68e855536ee484eadb3047660 Mon Sep 17 00:00:00 2001 From: mhucka Date: Thu, 12 Jun 2025 18:03:27 +0000 Subject: [PATCH 3/5] Add more paths to the include and link directories On MacOS, we need to tell cmake to look in /opt/homebrew for include files and libraries. --- pybind_interface/avx2/CMakeLists.txt | 15 +++++++++++++-- pybind_interface/avx512/CMakeLists.txt | 14 ++++++++++++-- pybind_interface/basic/CMakeLists.txt | 14 ++++++++++++-- pybind_interface/cuda/CMakeLists.txt | 15 ++++++++++++--- pybind_interface/custatevec/CMakeLists.txt | 14 ++++++++++++-- pybind_interface/decide/CMakeLists.txt | 16 +++++++++++++--- pybind_interface/sse/CMakeLists.txt | 15 ++++++++++++--- 7 files changed, 86 insertions(+), 17 deletions(-) diff --git a/pybind_interface/avx2/CMakeLists.txt b/pybind_interface/avx2/CMakeLists.txt index 54ceb30c7..bd299c1d7 100644 --- a/pybind_interface/avx2/CMakeLists.txt +++ b/pybind_interface/avx2/CMakeLists.txt @@ -9,9 +9,20 @@ ENDIF() if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() + INCLUDE(../GetPybind11.cmake) pybind11_add_module(qsim_avx2 pybind_main_avx2.cpp) diff --git a/pybind_interface/avx512/CMakeLists.txt b/pybind_interface/avx512/CMakeLists.txt index 3523b3553..acd960ca6 100644 --- a/pybind_interface/avx512/CMakeLists.txt +++ b/pybind_interface/avx512/CMakeLists.txt @@ -10,8 +10,18 @@ ENDIF() if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() INCLUDE(../GetPybind11.cmake) diff --git a/pybind_interface/basic/CMakeLists.txt b/pybind_interface/basic/CMakeLists.txt index f148f855c..5bff46386 100644 --- a/pybind_interface/basic/CMakeLists.txt +++ b/pybind_interface/basic/CMakeLists.txt @@ -10,8 +10,18 @@ endif() if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() INCLUDE(../GetPybind11.cmake) diff --git a/pybind_interface/cuda/CMakeLists.txt b/pybind_interface/cuda/CMakeLists.txt index 129e3077c..5a6486d8a 100644 --- a/pybind_interface/cuda/CMakeLists.txt +++ b/pybind_interface/cuda/CMakeLists.txt @@ -7,11 +7,20 @@ else() set(CMAKE_CXX_FLAGS "-O3") endif() - if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() INCLUDE(../GetPybind11.cmake) diff --git a/pybind_interface/custatevec/CMakeLists.txt b/pybind_interface/custatevec/CMakeLists.txt index fab71e03e..3c6c72711 100644 --- a/pybind_interface/custatevec/CMakeLists.txt +++ b/pybind_interface/custatevec/CMakeLists.txt @@ -23,8 +23,18 @@ endif() if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() INCLUDE(../GetPybind11.cmake) diff --git a/pybind_interface/decide/CMakeLists.txt b/pybind_interface/decide/CMakeLists.txt index 6ca7f8f03..17ec933e9 100644 --- a/pybind_interface/decide/CMakeLists.txt +++ b/pybind_interface/decide/CMakeLists.txt @@ -6,10 +6,20 @@ else() set(CMAKE_CXX_FLAGS "-O3") endif() -if(APPLE AND NOT APPLE_ARM) +if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() include(../GetPybind11.cmake) diff --git a/pybind_interface/sse/CMakeLists.txt b/pybind_interface/sse/CMakeLists.txt index a5868e521..2877d6e02 100644 --- a/pybind_interface/sse/CMakeLists.txt +++ b/pybind_interface/sse/CMakeLists.txt @@ -7,11 +7,20 @@ ELSE() set(CMAKE_CXX_FLAGS "-msse4.1 -O3") ENDIF() - if(APPLE) set(CMAKE_CXX_STANDARD 14) - include_directories("/usr/local/include" "/usr/local/opt/llvm/include") - link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") + include_directories( + "/usr/local/include" + "/usr/local/opt/llvm/include" + "/opt/homebrew/include" + "/opt/homebrew/opt/llvm@19/include" + ) + link_directories( + "/usr/local/lib" + "/usr/local/opt/llvm/lib" + "/opt/homebrew/lib" + "/opt/homebrew/opt/llvm@19/lib" + ) endif() INCLUDE(../GetPybind11.cmake) From 0ead153aaef1ac96669f093f0a4a8d3eb0785a38 Mon Sep 17 00:00:00 2001 From: mhucka Date: Thu, 12 Jun 2025 18:08:51 +0000 Subject: [PATCH 4/5] Increase minimum version of CMake needed --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e571aa12f..868c8fca0 100644 --- a/setup.py +++ b/setup.py @@ -32,8 +32,8 @@ def run(self): cmake_version = parse( re.search(r"version\s*([\d.]+)", out.decode()).group(1) ) - if cmake_version < parse("3.1.0"): - raise RuntimeError("CMake >= 3.1.0 is required on Windows") + if cmake_version < parse("3.31.0"): + raise RuntimeError("CMake >= 3.31.0 is required on Windows") for ext in self.extensions: self.build_extension(ext) From 028cb337687f346fbb2b20a551ca6da52b5ae3a7 Mon Sep 17 00:00:00 2001 From: mhucka Date: Fri, 13 Jun 2025 04:38:03 +0000 Subject: [PATCH 5/5] Revert GetPybind11.cmake This caused the cibuildwheel workflow to fail on GitHub Windows runners. --- pybind_interface/GetPybind11.cmake | 48 ++++++------------------------ 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/pybind_interface/GetPybind11.cmake b/pybind_interface/GetPybind11.cmake index b914086a1..d2f14efc7 100644 --- a/pybind_interface/GetPybind11.cmake +++ b/pybind_interface/GetPybind11.cmake @@ -1,40 +1,10 @@ -set(MIN_PYBIND_VERSION "2.13.6") - -# First, try to find pybind11 using the modern find_package() way. -find_package(pybind11 ${MIN_PYBIND_VERSION} QUIET) - -# If that doesn't work, try to use pybind11-config to find the CMake directory. -if(NOT pybind11_FOUND) - find_program(PYBIND11_CONFIG_EXECUTABLE pybind11-config) - - if(PYBIND11_CONFIG_EXECUTABLE) - # Get the CMake directory from pybind11-config - execute_process( - COMMAND ${PYBIND11_CONFIG_EXECUTABLE} --cmakedir - OUTPUT_VARIABLE pybind11_CMAKE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) +include(FetchContent) - # Add the discovered path to the CMake search paths and try again. - if(pybind11_CMAKE_DIR AND IS_DIRECTORY ${pybind11_CMAKE_DIR}) - list(APPEND CMAKE_PREFIX_PATH ${pybind11_CMAKE_DIR}) - find_package(pybind11 ${MIN_PYBIND_VERSION} QUIET) - endif() - endif() -endif() - -# If pybind11 is still not found, use FetchContent to download it. -if(NOT pybind11_FOUND) - message(STATUS "pybind11 not found. Fetching from source.") - include(FetchContent) - - FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG "v${MIN_PYBIND_VERSION}" - OVERRIDE_FIND_PACKAGE - ) - FetchContent_MakeAvailable(pybind11) -else() - message(STATUS "Found pybind11: ${pybind11_VERSION} (found version: ${pybind11_VERSION})") -endif() +set(MIN_PYBIND_VERSION "2.13.6") +FetchContent_Declare( + pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11 + GIT_TAG "v${MIN_PYBIND_VERSION}" + OVERRIDE_FIND_PACKAGE +) +FetchContent_MakeAvailable(pybind11)