Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python_bindings-test-as-installed #8355

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions python_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.22...3.23)
project(Halide_Python)

if (PROJECT_IS_TOP_LEVEL)
enable_testing()
endif ()

include(CMakeDependentOption)

##
Expand All @@ -12,6 +16,11 @@ set(CMAKE_CXX_STANDARD 17 CACHE STRING "The minimum C++ standard to use")
option(CMAKE_CXX_STANDARD_REQUIRED "Prevent CMake C++ standard selection decay" ON)
option(CMAKE_CXX_EXTENSIONS "Enable C++ vendor extensions (e.g. GNU)" OFF)

# Support not actually building the bindings, but using the ones we find
# via `find_package(Halide)`. This allows running tests against the
# installed Halide package.
option(WITH_PYTHON_BINDINGS "Build Python bindings" ON)

# Duplicated options from parent project
option(WITH_TESTS "Build tests" ON)
option(WITH_TUTORIALS "Build tutorials" ON)
Expand Down Expand Up @@ -41,18 +50,22 @@ if (Python3_VERSION VERSION_LESS "3.8")
endif ()
message(STATUS "Found Python ${Python3_VERSION} at ${Python3_EXECUTABLE}")

if (PYBIND11_USE_FETCHCONTENT)
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v${PYBIND11_VER}
)
FetchContent_MakeAvailable(pybind11)
else ()
find_package(pybind11 ${PYBIND11_VER} REQUIRED)
if (WITH_PYTHON_BINDINGS)
# If we are actually going to build the bindings, we need pybind11.
if (PYBIND11_USE_FETCHCONTENT)
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v${PYBIND11_VER}
)
FetchContent_MakeAvailable(pybind11)
else ()
find_package(pybind11 ${PYBIND11_VER} REQUIRED)
endif ()
endif ()

# Note: this must happen, especially when WITH_PYTHON_BINDINGS is OFF.
find_package(Halide REQUIRED Halide)
if (NOT Halide_ENABLE_RTTI OR NOT Halide_ENABLE_EXCEPTIONS)
message(FATAL_ERROR "Python bindings require RTTI and exceptions to be enabled.")
Expand Down Expand Up @@ -91,9 +104,11 @@ endfunction()
# Add our sources to this sub-tree.
##

add_subdirectory(src)
if (WITH_PYTHON_BINDINGS)
add_subdirectory(src)
endif ()

if (WITH_PYTHON_STUBS)
if (WITH_PYTHON_BINDINGS AND WITH_PYTHON_STUBS)
add_subdirectory(stub)
endif ()

Expand Down