From 516dc43c801472287de597c9516a18c21e1e8149 Mon Sep 17 00:00:00 2001 From: Lee Newberg Date: Wed, 22 Apr 2026 14:27:29 -0400 Subject: [PATCH] BUG: Depend upon Python / pybind11 only if requested --- CMakeLists.txt | 19 +++++++++---------- exputil/DiskDensityFunc.cc | 3 ++- include/DiskDensityFunc.H | 8 ++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee224bde3..24eca8e5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ if(ENABLE_MINIMAL) set(ENABLE_UTILS OFF) set(ENABLE_TESTS OFF) endif() - + # Metaflag for pyEXP only if(ENABLE_PYEXP_ONLY) @@ -86,7 +86,7 @@ if(ENABLE_PYEXP_ONLY) set(ENABLE_UTILS OFF) set(ENABLE_TESTS OFF) endif() - + # Set mpirun launcher for CTest set(EXP_MPI_LAUNCH "mpirun" CACHE STRING "Command to run an MPI application (for unit tests only)") @@ -297,13 +297,13 @@ if(ENABLE_TESTS) add_subdirectory(tests) endif() -# try to find pybind11 and build wrapper python module -find_package(Python3 COMPONENTS Interpreter Development) -message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") -if(Python3_FOUND) - set(HAVE_PYTHON3 TRUE) -else() - if(ENABLE_PYEXP) +if(ENABLE_PYEXP) + # try to find pybind11 and build wrapper python module + find_package(Python3 COMPONENTS Interpreter Development) + message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") + if(Python3_FOUND) + set(HAVE_PYTHON3 TRUE) + else() message(FATAL_ERROR "You asked for pyEXP but I cannot find a Python3 environment. Please make Python3 available or disable pyEXP. CMake will exit." ) endif() endif() @@ -404,4 +404,3 @@ set(CMAKE_CXX_FLAGS_UBSAN # from the same source. configure_file(${CMAKE_SOURCE_DIR}/config_cmake.h_in ${CMAKE_BINARY_DIR}/config_exp.h) include_directories(${PROJECT_BINARY_DIR}) - diff --git a/exputil/DiskDensityFunc.cc b/exputil/DiskDensityFunc.cc index 65418193e..c8dfd3587 100644 --- a/exputil/DiskDensityFunc.cc +++ b/exputil/DiskDensityFunc.cc @@ -1,3 +1,4 @@ +#include #include "DiskDensityFunc.H" #ifdef HAVE_PYTHON3 @@ -38,7 +39,7 @@ DiskDensityFunc::DiskDensityFunc(const std::string& modulename, const std::string& funcname) : funcname(funcname) { - throw std::runtime_error("DiskDensityFunc: you environoment does not have Python3 support. Use a built-in density target or install Python3 and recompile"); + throw std::runtime_error("DiskDensityFunc: your environoment does not have Python3 support. Use a built-in density target or install Python3 and recompile"); } DiskDensityFunc::~DiskDensityFunc() diff --git a/include/DiskDensityFunc.H b/include/DiskDensityFunc.H index 637d8cb14..ba874a3fe 100644 --- a/include/DiskDensityFunc.H +++ b/include/DiskDensityFunc.H @@ -2,9 +2,11 @@ #define _DiskDensityFunc_H_ #include +#include #include "config_exp.h" +#ifdef HAVE_PYTHON3 #include #include @@ -26,12 +28,14 @@ a = 1.0 # Scale radius h = 0.2 # Scale height f = math.exp(-0.5*math.fabs(z)/h) # Prevent overflows - sech = 2.0*f / (1.0 + f*f) # + sech = 2.0*f / (1.0 + f*f) # return math.exp(-R/a)*sech*sech/(8*math.pi*h*a*a) - + --------------------------cut here-------------------------------- */ +#endif + class __attribute__((visibility("default"))) DiskDensityFunc {