From 93f394ba285472fdfd50e28c39b58cad50050074 Mon Sep 17 00:00:00 2001 From: Drew Risinger Date: Thu, 3 Mar 2022 11:16:49 -0500 Subject: [PATCH 1/2] cmake: allow using system pybind11 Defaults to pre-installed version of pybind11. The search was refactored to a cmake module. Will default to using the system pybind11, and fetch pybind11 via git if it is not installed --- pybind_interface/GetPybind11.cmake | 13 +++++++++++++ pybind_interface/avx2/CMakeLists.txt | 14 +------------- pybind_interface/avx512/CMakeLists.txt | 13 +------------ pybind_interface/basic/CMakeLists.txt | 13 +------------ pybind_interface/cuda/CMakeLists.txt | 14 +------------- pybind_interface/custatevec/CMakeLists.txt | 16 ++-------------- pybind_interface/decide/CMakeLists.txt | 13 +------------ pybind_interface/sse/CMakeLists.txt | 13 +------------ 8 files changed, 21 insertions(+), 88 deletions(-) create mode 100644 pybind_interface/GetPybind11.cmake diff --git a/pybind_interface/GetPybind11.cmake b/pybind_interface/GetPybind11.cmake new file mode 100644 index 00000000..ffeada3b --- /dev/null +++ b/pybind_interface/GetPybind11.cmake @@ -0,0 +1,13 @@ +include(FetchContent) + +FetchContent_Declare( + pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11 + GIT_TAG v2.2.4 +) +FetchContent_GetProperties(pybind11) +find_package(pybind11 CONFIG) +if((NOT pybind11_FOUND) AND (NOT pybind11_POPULATED)) # check first on system path, then attempt git fetch + FetchContent_Populate(pybind11) + add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) +endif() diff --git a/pybind_interface/avx2/CMakeLists.txt b/pybind_interface/avx2/CMakeLists.txt index 4382de95..eebba584 100644 --- a/pybind_interface/avx2/CMakeLists.txt +++ b/pybind_interface/avx2/CMakeLists.txt @@ -12,17 +12,5 @@ if(APPLE) include_directories("/usr/local/include" "/usr/local/opt/llvm/include") link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() - -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -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 705d39db..86cfdfa8 100644 --- a/pybind_interface/avx512/CMakeLists.txt +++ b/pybind_interface/avx512/CMakeLists.txt @@ -14,16 +14,5 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() +INCLUDE(../GetPybind11.cmake) pybind11_add_module(qsim_avx512 pybind_main_avx512.cpp) diff --git a/pybind_interface/basic/CMakeLists.txt b/pybind_interface/basic/CMakeLists.txt index 9380f02d..35347211 100644 --- a/pybind_interface/basic/CMakeLists.txt +++ b/pybind_interface/basic/CMakeLists.txt @@ -14,16 +14,5 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() +INCLUDE(../GetPybind11.cmake) pybind11_add_module(qsim_basic pybind_main_basic.cpp) diff --git a/pybind_interface/cuda/CMakeLists.txt b/pybind_interface/cuda/CMakeLists.txt index d7f5b836..7da45dac 100644 --- a/pybind_interface/cuda/CMakeLists.txt +++ b/pybind_interface/cuda/CMakeLists.txt @@ -14,19 +14,7 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() - +INCLUDE(../GetPybind11.cmake) find_package(PythonLibs 3.6 REQUIRED) find_package(CUDA REQUIRED) diff --git a/pybind_interface/custatevec/CMakeLists.txt b/pybind_interface/custatevec/CMakeLists.txt index 912f531c..687ac2be 100644 --- a/pybind_interface/custatevec/CMakeLists.txt +++ b/pybind_interface/custatevec/CMakeLists.txt @@ -27,23 +27,11 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() - +INCLUDE(../GetPybind11.cmake) find_package(PythonLibs 3.6 REQUIRED) find_package(CUDA REQUIRED) -include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) +include_directories(${pybind11_INCLUDE_DIRS}) include_directories($ENV{CUQUANTUM_DIR}/include) link_directories($ENV{CUQUANTUM_DIR}/lib $ENV{CUQUANTUM_DIR}/lib64) diff --git a/pybind_interface/decide/CMakeLists.txt b/pybind_interface/decide/CMakeLists.txt index 643ca9ad..0808ccf6 100644 --- a/pybind_interface/decide/CMakeLists.txt +++ b/pybind_interface/decide/CMakeLists.txt @@ -19,18 +19,7 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() +INCLUDE(../GetPybind11.cmake) if(has_nvcc STREQUAL "") pybind11_add_module(qsim_decide decide.cpp) diff --git a/pybind_interface/sse/CMakeLists.txt b/pybind_interface/sse/CMakeLists.txt index 6fa7201f..fe9b218e 100644 --- a/pybind_interface/sse/CMakeLists.txt +++ b/pybind_interface/sse/CMakeLists.txt @@ -14,16 +14,5 @@ if(APPLE) link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib") endif() -include(FetchContent) - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 -) -FetchContent_GetProperties(pybind11) -if(NOT pybind11_POPULATED) - FetchContent_Populate(pybind11) - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR}) -endif() +INCLUDE(../GetPybind11.cmake) pybind11_add_module(qsim_sse pybind_main_sse.cpp) From 1c54e70acb260e6caad9bb9ad160762222d7230c Mon Sep 17 00:00:00 2001 From: Drew Risinger Date: Thu, 3 Mar 2022 12:23:49 -0500 Subject: [PATCH 2/2] cmake: set minimum pybind11 version --- pybind_interface/GetPybind11.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pybind_interface/GetPybind11.cmake b/pybind_interface/GetPybind11.cmake index ffeada3b..f93c2bf6 100644 --- a/pybind_interface/GetPybind11.cmake +++ b/pybind_interface/GetPybind11.cmake @@ -1,12 +1,13 @@ include(FetchContent) +set(MIN_PYBIND_VERSION "2.2.4") FetchContent_Declare( pybind11 GIT_REPOSITORY https://github.com/pybind/pybind11 - GIT_TAG v2.2.4 + GIT_TAG "v${MIN_PYBIND_VERSION}" ) FetchContent_GetProperties(pybind11) -find_package(pybind11 CONFIG) +find_package(pybind11 "${MIN_PYBIND_VERSION}" CONFIG) if((NOT pybind11_FOUND) AND (NOT pybind11_POPULATED)) # check first on system path, then attempt git fetch FetchContent_Populate(pybind11) add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})