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

Support read C++ standard via CMAKE_CXX_STANDARD when compiling Python bindings #275

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,10 @@ jobs:

pybind11-cmake:
needs: [build-ubuntu, build-mac]
# strategy:
# fail-fast: false
# matrix:
# python-version: [3.9]
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ubuntu-20.04, ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ option(BUILD_PYTHON_BINDINGS "Build Python bindings with pybind11." OFF)
option(BUILD_TESTING_PYTHON "Build Python tests only." OFF)

if (BUILD_PYTHON_BINDINGS)
# In theory this is not required, as CMake selects the appropriate C++ standard
# However, as long as we support pybind11 < 2.6 we need to make sure that CMAKE_CXX_STANDARD
# is defined before find_package(pybind11 REQUIRED) to avoid that the CMake standard
# command line option is set by pybind11 via the PYBIND11_CPP_STANDARD variable, in a way that could
# interfere with CMake, see https://github.com/pybind/pybind11/blob/v2.4.3/tools/pybind11Tools.cmake#L21
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

find_package(pybind11 REQUIRED)
add_subdirectory(python)
endif()
Expand Down
5 changes: 2 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
set(PYBIND11_CPP_STANDARD -std=c++11)
pybind11_add_module(manifpy MODULE
bindings_rn.cpp
bindings_so2.cpp
Expand All @@ -13,8 +12,8 @@ target_link_libraries(manifpy PRIVATE ${PROJECT_NAME})
# See e.g. https://pybind11.readthedocs.io/en/stable/advanced/cast/eigen.html#storage-orders
target_compile_definitions(manifpy PRIVATE EIGEN_DEFAULT_TO_ROW_MAJOR)

# Set required C++11 flag
set_property(TARGET manifpy PROPERTY CXX_STANDARD 11)
# Specify that C++11 features are required
target_compile_features(manifpy PRIVATE cxx_nullptr)
set_property(TARGET manifpy PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET manifpy PROPERTY CXX_EXTENSIONS OFF)

Expand Down