Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
# CMakeLists.txt -- Build system for the pybind11 test suite
|
|
|
|
#
|
|
|
|
# Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
|
|
|
#
|
|
|
|
# All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2023-07-12 18:10:24 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2020-07-28 04:43:12 +00:00
|
|
|
|
2023-12-14 19:36:45 +00:00
|
|
|
# The `cmake_minimum_required(VERSION 3.5...3.27)` syntax does not work with
|
2020-08-01 02:45:19 +00:00
|
|
|
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
|
|
|
|
# the behavior using the following workaround:
|
2023-12-14 19:36:45 +00:00
|
|
|
if(${CMAKE_VERSION} VERSION_LESS 3.27)
|
2020-07-30 20:20:10 +00:00
|
|
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
2020-07-28 04:43:12 +00:00
|
|
|
else()
|
2023-12-14 19:36:45 +00:00
|
|
|
cmake_policy(VERSION 3.27)
|
2020-07-28 04:43:12 +00:00
|
|
|
endif()
|
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# Filter out items; print an optional message if any items filtered. This ignores extensions.
|
2020-09-12 02:06:52 +00:00
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# pybind11_filter_tests(LISTNAME file1.cpp file2.cpp ... MESSAGE "")
|
|
|
|
#
|
2021-01-19 23:48:22 +00:00
|
|
|
macro(pybind11_filter_tests LISTNAME)
|
2020-09-12 02:06:52 +00:00
|
|
|
cmake_parse_arguments(ARG "" "MESSAGE" "" ${ARGN})
|
|
|
|
set(PYBIND11_FILTER_TESTS_FOUND OFF)
|
2022-01-12 01:31:19 +00:00
|
|
|
# Make a list of the test without any extensions, for easier filtering.
|
|
|
|
set(_TMP_ACTUAL_LIST "${${LISTNAME}};") # enforce ';' at the end to allow matching last item.
|
|
|
|
string(REGEX REPLACE "\\.[^.;]*;" ";" LIST_WITHOUT_EXTENSIONS "${_TMP_ACTUAL_LIST}")
|
2020-09-12 02:06:52 +00:00
|
|
|
foreach(filename IN LISTS ARG_UNPARSED_ARGUMENTS)
|
2022-01-12 01:31:19 +00:00
|
|
|
string(REGEX REPLACE "\\.[^.]*$" "" filename_no_ext ${filename})
|
|
|
|
# Search in the list without extensions.
|
|
|
|
list(FIND LIST_WITHOUT_EXTENSIONS ${filename_no_ext} _FILE_FOUND)
|
2020-09-12 02:06:52 +00:00
|
|
|
if(_FILE_FOUND GREATER -1)
|
2022-01-12 01:31:19 +00:00
|
|
|
list(REMOVE_AT ${LISTNAME} ${_FILE_FOUND}) # And remove from the list with extensions.
|
|
|
|
list(REMOVE_AT LIST_WITHOUT_EXTENSIONS ${_FILE_FOUND}
|
|
|
|
)# And our search list, to ensure it is in sync.
|
2020-09-12 02:06:52 +00:00
|
|
|
set(PYBIND11_FILTER_TESTS_FOUND ON)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(PYBIND11_FILTER_TESTS_FOUND AND ARG_MESSAGE)
|
|
|
|
message(STATUS "${ARG_MESSAGE}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2021-01-19 23:48:22 +00:00
|
|
|
macro(possibly_uninitialized)
|
|
|
|
foreach(VARNAME ${ARGN})
|
|
|
|
if(NOT DEFINED "${VARNAME}")
|
|
|
|
set("${VARNAME}" "")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# Function to add additional targets if any of the provided tests are found.
|
|
|
|
# Needles; Specifies the test names to look for.
|
|
|
|
# Additions; Specifies the additional test targets to add when any of the needles are found.
|
|
|
|
macro(tests_extra_targets needles additions)
|
|
|
|
# Add the index for this relation to the index extra targets map.
|
|
|
|
list(LENGTH PYBIND11_TEST_EXTRA_TARGETS PYBIND11_TEST_EXTRA_TARGETS_LEN)
|
|
|
|
list(APPEND PYBIND11_TEST_EXTRA_TARGETS ${PYBIND11_TEST_EXTRA_TARGETS_LEN})
|
|
|
|
# Add the test names to look for, and the associated test target additions.
|
|
|
|
set(PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${PYBIND11_TEST_EXTRA_TARGETS_LEN} ${needles})
|
|
|
|
set(PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${PYBIND11_TEST_EXTRA_TARGETS_LEN} ${additions})
|
|
|
|
endmacro()
|
|
|
|
|
2020-08-19 16:26:26 +00:00
|
|
|
# New Python support
|
|
|
|
if(DEFINED Python_EXECUTABLE)
|
|
|
|
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
|
|
|
|
set(PYTHON_VERSION "${Python_VERSION}")
|
|
|
|
endif()
|
|
|
|
|
2020-07-28 04:43:12 +00:00
|
|
|
# There's no harm in including a project in a project
|
|
|
|
project(pybind11_tests CXX)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
|
2020-08-01 02:45:19 +00:00
|
|
|
# Access FindCatch and more
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../tools")
|
|
|
|
|
2020-07-30 20:20:10 +00:00
|
|
|
option(PYBIND11_WERROR "Report all warnings as errors" OFF)
|
2020-07-28 04:43:12 +00:00
|
|
|
option(DOWNLOAD_EIGEN "Download EIGEN (requires CMake 3.11+)" OFF)
|
2020-09-10 15:49:26 +00:00
|
|
|
option(PYBIND11_CUDA_TESTS "Enable building CUDA tests (requires CMake 3.12+)" OFF)
|
2020-07-30 20:20:10 +00:00
|
|
|
set(PYBIND11_TEST_OVERRIDE
|
|
|
|
""
|
|
|
|
CACHE STRING "Tests from ;-separated list of *.cpp files will be built instead of all tests")
|
2020-09-12 02:06:52 +00:00
|
|
|
set(PYBIND11_TEST_FILTER
|
|
|
|
""
|
|
|
|
CACHE STRING "Tests from ;-separated list of *.cpp files will be removed from all tests")
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
|
2020-07-28 04:43:12 +00:00
|
|
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2020-07-30 20:20:10 +00:00
|
|
|
# We're being loaded directly, i.e. not via add_subdirectory, so make this
|
|
|
|
# work as its own project and load the pybind11Config to get the tools we need
|
|
|
|
find_package(pybind11 REQUIRED CONFIG)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-19 23:48:22 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
|
2016-08-12 11:50:00 +00:00
|
|
|
message(STATUS "Setting tests build type to MinSizeRel as none was specified")
|
2020-07-30 20:20:10 +00:00
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
MinSizeRel
|
|
|
|
CACHE STRING "Choose the type of build." FORCE)
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
|
|
|
|
"RelWithDebInfo")
|
2016-08-12 11:50:00 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
if(PYBIND11_CUDA_TESTS)
|
|
|
|
enable_language(CUDA)
|
|
|
|
if(DEFINED CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
|
|
|
|
endif()
|
|
|
|
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# Full set of test files (you can override these; see below, overrides ignore extension)
|
|
|
|
# Any test that has no extension is both .py and .cpp, so 'foo' will add 'foo.cpp' and 'foo.py'.
|
|
|
|
# Any test that has an extension is exclusively that and handled as such.
|
2016-08-12 11:50:00 +00:00
|
|
|
set(PYBIND11_TEST_FILES
|
2022-01-12 01:31:19 +00:00
|
|
|
test_async
|
|
|
|
test_buffers
|
|
|
|
test_builtin_casters
|
|
|
|
test_call_policies
|
|
|
|
test_callbacks
|
|
|
|
test_chrono
|
|
|
|
test_class
|
|
|
|
test_const_name
|
|
|
|
test_constants_and_functions
|
|
|
|
test_copy_move
|
|
|
|
test_custom_type_casters
|
|
|
|
test_custom_type_setup
|
|
|
|
test_docstring_options
|
First draft of Eigen::Tensor support (#4201)
* First draft of Eigen::Tensor support
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix build errors
* Weird allocator stuff?
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove unused + additional allocator junk
* Disable warning
* Use constexpr
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clang tidy fixes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve comments
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove auto constexpr function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Try again for older C++
* Oops forgot constexpr
* Move to new files as suggested
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix weird tests
* Fix nits
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Oops, forgot import
* Fix clang 3.6 bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* More comprehensive test suite
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor allocators to make things more clear
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to std::copy
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to DSizes instead of array
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address feedback
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix python + dummy c++ change to trigger build
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Alignment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add include guard
* Forgot inline
* Fix compiler warning
* Remove bad test
* Better type signatures
* Add guards to make compiler requirements more explicit
* style: pre-commit fixes
* Force rerun of tests due to flake
* style: pre-commit fixes
* Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC
* Move headers out of detail
* style: pre-commit fixes
* Fix cmake
* Improve casting
* style: pre-commit fixes
* Add a ton more tests + refactor
* Improve names
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* Fix tests
* style: pre-commit fixes
* Update
* Add a test to verify that strange numpy arrays work
* Fix dumb compiler warning
* Better tests
* Better tests
* Fix tests
* style: pre-commit fixes
* More test fixes
* style: pre-commit fixes
* A ton more test coverage
* Fix tests
* style: pre-commit fixes
* style: pre-commit fixes
* Add back constexpr
* Another test
* style: pre-commit fixes
* Improve tests
* Whoops
* Less magic numbers
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* style: pre-commit fixes
* Fix tests
* style: pre-commit fixes
* Fix memory leak
* style: pre-commit fixes
* Fix order
* style: pre-commit fixes
* Add test to make sure unsafe casts fail
* Minor bug fix to work on 32 bit machines
* Implement convert flag
* style: pre-commit fixes
* Switch to correct TensorMap const use
* style: pre-commit fixes
* Support older versions of eigen
* Weird c++ compilers
* Fix Eigen bug
* Fix another eigen bug
* Yet another eigen bug
* Potential flakes?
* style: pre-commit fixes
* Rerun tests with dummy exception to find out what is going on
* Another dummy test run
* Ablate more
* Found the broken test?
* One step closer
* one step further
* Double check
* one thing at a time
* Give up and disable the test
* Clang lies about being gcc
* Oops, fix matrix test
* style: pre-commit fixes
* Add tests to verify scalar conversions
* style: pre-commit fixes
* Fix nits
* Support no_array
* Fix tests
* style: pre-commit fixes
* Silence compiler warning
* Improve build system for ancient compilers
* Make clang happy
* Make gcc happy
* Implement Skylion's suggestions
* Fix warning
* Inline const pointer check
* Implement suggestions
* style: pre-commit fixes
* Improve tests
* Typo
* style: pre-commit fixes
* Support Google's build environment
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* style: pre-commit fixes
* Test cleanup per Skylion
* Switch to remvove_cv_t
* Cleaner test
* style: pre-commit fixes
* Remove tensor from eigen.h, update tests
* style: pre-commit fixes
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
|
|
|
test_eigen_matrix
|
|
|
|
test_eigen_tensor
|
2022-01-12 01:31:19 +00:00
|
|
|
test_enum
|
|
|
|
test_eval
|
|
|
|
test_exceptions
|
|
|
|
test_factory_constructors
|
|
|
|
test_gil_scoped
|
|
|
|
test_iostream
|
|
|
|
test_kwargs_and_defaults
|
|
|
|
test_local_bindings
|
|
|
|
test_methods_and_attributes
|
|
|
|
test_modules
|
|
|
|
test_multiple_inheritance
|
|
|
|
test_numpy_array
|
|
|
|
test_numpy_dtypes
|
2022-01-13 03:34:03 +00:00
|
|
|
test_numpy_scalars
|
2022-01-12 01:31:19 +00:00
|
|
|
test_numpy_vectorize
|
|
|
|
test_opaque_types
|
|
|
|
test_operator_overloading
|
|
|
|
test_pickling
|
Fix a long-standing bug in the handling of Python multiple inheritance (#4762)
* Equivalent of https://github.com/google/clif/commit/5718e4d0807fd3b6a8187dde140069120b81ecef
* Resolve clang-tidy errors.
* Moving test_PPCCInit() first changes the behavior!
* Resolve new Clang dev C++11 errors:
```
The CXX compiler identification is Clang 17.0.0
```
```
pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```
```
cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
```
* Resolve gcc 4.8.5 error:
```
pytypes.h:1615:12: error: missing space between '""' and suffix identifier
```
* Specifically exclude `__clang__`
* Snapshot of debugging code (does NOT pass pre-commit checks).
* Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."
This reverts commit 1d4f9ff2632b32ddcb0dc7ecd0ab7a4ce4c15a4e.
* [ci skip] Order Dependence Demo
* Revert "[ci skip] Order Dependence Demo"
This reverts commit d37b5409d4e5b835620ccbb321a4e1ba89af315c.
* One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.
* Move test_PC() first again.
* Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()`
* Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept."
This reverts commit eb09c6c1b978208ceee40f05bbe75491b6ff8ad6.
* clang-tidy fixes (automatic)
* Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed.
* Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152
The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
which was actually found in the wild: the mock returned `None` for `self`.
This was inconsequential because `inst` is currently cast straight back to
`PyObject *` to compute `all_type_info()`, which is empty if `self` is not
a pybind11 `instance`, and then `inst` is never dereferenced. However, the
unsafe detour through `instance *` is easily avoided and the updated
implementation is less prone to accidents while debugging or refactoring.
* Fix actual undefined behavior exposed by previous changes.
It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:
https://github.com/pybind/pybind11/blob/f3e0602802c7840992c97f4960515777cad6a5c7/include/pybind11/detail/type_caster_base.h#L262-L263
```
259 // Main constructor for a found value/holder:
260 value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
261 : inst{i}, index{index}, type{type},
262 vh{inst->simple_layout ? inst->simple_value_holder
263 : &inst->nonsimple.values_and_holders[vpos]} {}
```
* Add test_mock_new()
* Experiment: specify indirect bases
* Revert "Experiment: specify indirect bases"
This reverts commit 4f90d85f9fc15290d6be54d5ae9417bd131b84d9.
* Add `all_type_info_check_for_divergence()` and some tests.
* Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`
* Resolve clang-tidy error:
```
include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
if (matching_bases.size() != 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~
!matching_bases.empty()
```
* Revert "Resolve clang-tidy error:"
This reverts commit df27188dc6d6cf333145755543f56b2f6657aa5e.
* Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"
This reverts commit 5f5fd6a68e3cff1726628f6dea8e1c0754636a23.
* Revert "Add `all_type_info_check_for_divergence()` and some tests."
This reverts commit 0a9599f775bfd3ca196c5e23a3fcf2890cbf6e82.
2023-11-08 20:44:04 +00:00
|
|
|
test_python_multiple_inheritance
|
2022-01-12 01:31:19 +00:00
|
|
|
test_pytypes
|
|
|
|
test_sequences_and_iterators
|
|
|
|
test_smart_ptr
|
|
|
|
test_stl
|
|
|
|
test_stl_binders
|
|
|
|
test_tagbased_polymorphic
|
|
|
|
test_thread
|
Add `type_caster<PyObject>` (#4601)
* Add `type_caster<PyObject>` (tests are still incomplete).
* Fix oversight (`const PyObject *`).
* Ensure `type_caster<PyObject>` only works for `PyObject *`
* Move `is_same_ignoring_cvref` into `detail` namespace.
* Add test_cast_nullptr
* Change is_same_ignoring_cvref from variable template to using.
```
test_type_caster_pyobject_ptr.cpp:8:23: error: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Werror]
8 | static constexpr bool is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>::value;
| ^~~~~~~~~~~~~~~~~~~~~~
```
* Remove `return_value_policy::reference_internal` `keep_alive` feature (because of doubts about it actually being useful).
* Add missing test, fix bug (missing `throw error_already_set();`), various cosmetic changes.
* Move `type_caster<PyObject>` from test to new include (pybind11/type_caster_pyobject_ptr.h)
* Add new header file to CMakeLists.txt and tests/extra_python_package/test_files.py
* Backport changes from https://github.com/google/pywrapcc/pull/30021 to https://github.com/pybind/pybind11/pull/4601
* Fix oversight in test (to resolve a valgrind leak detection error) and add a related comment in cast.h.
No production code changes.
Make tests more sensitive by using `ValueHolder` instead of empty tuples and dicts.
Manual leak checks with `while True:` & top command repeated for all tests.
* Add tests for interop with stl.h `list_caster`
(No production code changes.)
* Bug fix in test. Minor comment enhancements.
* Change `type_caster<PyObject>::name` to `object`, as suggested by @Skylion007
* Expand comment for the new `T cast(const handle &handle)` [`T` = `PyObject *`]
* Add `T cast(object &&obj)` overload as suggested by @Skylion007
The original suggestion leads to `error: call to 'cast' is ambiguous` (full error message below), therefore SFINAE guarding is needed.
```
clang++ -o pybind11/tests/test_type_caster_pyobject_ptr.os -c -std=c++17 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.10 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp
In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:1:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:12:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:13:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/class.h:12:
In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/attr.h:14:
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1165:12: error: call to 'cast' is ambiguous
return pybind11::cast<T>(std::move(*this));
^~~~~~~~~~~~~~~~~
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:109:70: note: in instantiation of function template specialization 'pybind11::object::cast<_object *>' requested here
return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:103:16: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load(pybind11::handle, bool)::func_wrapper::operator()' requested here
struct func_wrapper {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1456:47: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load' requested here
if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1434:50: note: in instantiation of function template specialization 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_impl_sequence<0UL, 1UL>' requested here
bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:227:33: note: in instantiation of member function 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_args' requested here
if (!args_converter.load_args(call)) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:101:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), _object *, const std::function<_object *(int)> &, int, pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy>' requested here
initialize(
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1163:22: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy, void>' requested here
cpp_function func(std::forward<Func>(f),
^
/usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:48:7: note: in instantiation of function template specialization 'pybind11::module_::def<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::return_value_policy>' requested here
m.def(
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1077:3: note: candidate function [with T = _object *, $1 = 0]
T cast(object &&obj) {
^
/usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1149:1: note: candidate function [with T = _object *]
cast(object &&object) {
^
1 error generated.
```
2023-05-07 17:15:53 +00:00
|
|
|
test_type_caster_pyobject_ptr
|
2022-01-12 01:31:19 +00:00
|
|
|
test_union
|
Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319)
* Try using `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere.
From PR #4316 we know that types in the unnamed namespace in different translation units do not compare equal, as desired.
But do types in named namespaces compare equal, as desired?
* Revert "Try using `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere."
This reverts commit a06949a9265014b3c581396c4f37c45ccc03dea6.
* Use "our own name-based hash and equality functions" for `std::type_index` only under macOS, based on results shown under https://github.com/pybind/pybind11/pull/4316#issuecomment-1305097879
* Patch in PR #4313: Minimal reproducer for clash when binding types defined in the unnamed namespace.
* test_unnamed_namespace_b xfail for clang
* `PYBIND11_INTERNALS_VERSION 5`
* Add a note to docs/classes.rst
* For compatibility with Google-internal testing, test_unnamed_namespace_a & test_unnamed_namespace_b need to work when imported in any order.
* Trying "__GLIBCXX__ or Windows", based on observations from Google-internal testing.
* Try _LIBCPP_VERSION
* Account for libc++ behavior in tests and documentation.
* Adjust expectations for Windows Clang (and make code less redundant).
* Add WindowsClang to ci.yml
Added block transferred from PR #4321
* Add clang-latest to name that appears in the GitHub Actions web view.
* Tweak the note in classes.rst again.
* Add `pip install --upgrade pip`, Show env, cosmetic changes
Already tested under PR #4321
* Add macos_brew_install_llvm to ci.yml
Added block transferred from PR #4324
* `test_cross_module_exception_translator` xfail 'Homebrew Clang'
* Revert back to base version of .github/workflows/ci.yml (the ci.yml changes were merged under #4323 and #4326)
* Fixes for ruff
* Make updated condition in internals.h dependent on ABI version.
* Remove PYBIND11_TEST_OVERRIDE when testing with PYBIND11_INTERNALS_VERSION=10000000
* Selectively exercise cmake `-DPYBIND11_TEST_OVERRIDE`: ubuntu, macos, windows
Extra work added to quick jobs, based on timings below, to not increase the GHA start-to-last-job-finished time.
```
Duration
^ Number of pytest runs
^ ^ Job identifier
^ ^ ^
0:03:48.024227 1 1___3___Clang_3.6___C++11___x64.txt
0:03:58.992814 1 2___3___Clang_3.7___C++11___x64.txt
0:04:25.758942 1 1___3.7___Debian___x86____Install.txt
0:04:50.148276 1 4___3___Clang_7___C++11___x64.txt
0:04:55.784558 1 13___3___Clang_15___C++20___x64.txt
0:04:57.048754 1 6___3___Clang_dev___C++11___x64.txt
0:05:00.485181 1 7___3___Clang_5___C++14___x64.txt
0:05:03.744964 1 2___3___almalinux8___x64.txt
0:05:06.222752 1 5___3___Clang_9___C++11___x64.txt
0:05:11.767022 1 2___3___GCC_7___C++17__x64.txt
0:05:18.634930 1 2___3.11__deadsnakes____x64.txt
0:05:22.810995 1 1___3___GCC_7___C++11__x64.txt
0:05:25.275317 1 12___3___Clang_14___C++20___x64.txt
0:05:32.058174 1 5___3___GCC_10___C++17__x64.txt
0:05:39.381351 1 7___3___GCC_12___C++20__x64.txt
0:05:40.502252 1 8___3___Clang_10___C++17___x64.txt
0:05:59.344905 1 3___3___Clang_3.9___C++11___x64.txt
0:06:10.825147 1 6___3___GCC_11___C++20__x64.txt
0:06:20.655443 1 3___3___almalinux9___x64.txt
0:06:22.472061 1 3___3___GCC_8___C++14__x64.txt
0:06:42.647406 1 11___3___Clang_13___C++20___x64.txt
0:06:53.352720 1 1___3.10___CUDA_11.7___Ubuntu_22.04.txt
0:07:07.357801 1 2___3.7___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=14.txt
0:07:09.057603 1 1___3___centos7___x64.txt
0:07:15.546282 1 1___3.8___MSVC_2019__Debug____x86_-DCMAKE_CXX_STANDARD=17.txt
0:07:22.566022 1 4___3___GCC_8___C++17__x64.txt
0:08:13.592674 1 2___3.9___MSVC_2019__Debug____x86_-DCMAKE_CXX_STANDARD=20.txt
0:08:16.422768 1 9___3___Clang_11___C++20___x64.txt
0:08:21.168457 1 3___3.8___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=17.txt
0:08:27.129468 1 10___3___Clang_12___C++20___x64.txt
0:09:35.045470 1 1___3.10___windows-latest___clang-latest.txt
0:09:57.361843 1 1___3.9___MSVC_2022_C++20___x64.txt
0:10:35.187767 1 1___3.6___MSVC_2019___x86.txt
0:11:14.691200 4 2___3.9___ubuntu-20.04___x64.txt
0:11:37.701167 1 1_macos-latest___brew_install_llvm.txt
0:11:38.688299 4 4___3.11___ubuntu-20.04___x64.txt
0:11:52.720216 1 4___3.9___MSVC_2019___x86_-DCMAKE_CXX_STANDARD=20.txt
0:13:23.456591 4 6___pypy-3.8___ubuntu-20.04___x64_-DPYBIND11_FINDPYTHON=ON.txt
0:13:25.863592 2 1___3___ICC_latest___x64.txt
0:13:32.411758 3 9___3.9___windows-2022___x64.txt
0:13:45.473377 4 3___3.10___ubuntu-20.04___x64.txt
0:13:55.366447 4 5___pypy-3.7___ubuntu-20.04___x64.txt
0:13:57.969502 3 10___3.10___windows-2022___x64.txt
0:14:19.837475 3 11___3.11___windows-2022___x64.txt
0:14:33.316770 4 1___3.6___ubuntu-20.04___x64_-DPYBIND11_FINDPYTHON=ON_-DCMA.txt
0:15:34.449278 4 22___3.6___windows-2019___x64_-DPYBIND11_FINDPYTHON=ON.txt
0:16:25.189055 2 1___3.9-dbg__deadsnakes____Valgrind___x64.txt
0:17:20.956667 4 15___3.6___macos-latest___x64.txt
0:17:27.513891 4 23___3.9___windows-2019___x64.txt
0:17:58.783286 3 8___3.6___windows-2022___x64.txt
0:18:25.917828 4 7___pypy-3.9___ubuntu-20.04___x64.txt
0:19:17.399820 3 13___pypy-3.8___windows-2022___x64.txt
0:19:45.002122 3 12___pypy-3.7___windows-2022___x64.txt
0:20:03.201926 4 16___3.9___macos-latest___x64.txt
0:20:15.415178 4 17___3.10___macos-latest___x64.txt
0:20:20.263216 4 20___pypy-3.8___macos-latest___x64.txt
0:20:31.998226 3 1___3___windows-latest___mingw64.txt
0:20:40.812286 4 18___3.11___macos-latest___x64.txt
0:22:47.714749 4 19___pypy-3.7___macos-latest___x64.txt
0:23:04.435859 3 2___3___windows-latest___mingw32.txt
0:25:48.719597 3 14___pypy-3.9___windows-2022___x64.txt
0:26:01.211688 4 21___pypy-3.9___macos-latest___x64.txt
0:28:19.971015 1 1___3___CentOS7__PGI_22.9___x64.txt
```
* Update skipif for Python 3.12a7 (the WIP needs to be handled in a separate PR).
2023-04-25 21:03:24 +00:00
|
|
|
test_unnamed_namespace_a
|
|
|
|
test_unnamed_namespace_b
|
2023-04-24 07:19:21 +00:00
|
|
|
test_vector_unique_ptr_member
|
2022-01-12 01:31:19 +00:00
|
|
|
test_virtual_functions)
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2016-11-13 00:10:53 +00:00
|
|
|
# Invoking cmake with something like:
|
2020-08-17 14:14:23 +00:00
|
|
|
# cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" ..
|
2016-11-13 00:10:53 +00:00
|
|
|
# lets you override the tests that get compiled and run. You can restore to all tests with:
|
|
|
|
# cmake -DPYBIND11_TEST_OVERRIDE= ..
|
2020-07-30 20:20:10 +00:00
|
|
|
if(PYBIND11_TEST_OVERRIDE)
|
2022-01-12 01:31:19 +00:00
|
|
|
# Instead of doing a direct override here, we iterate over the overrides without extension and
|
|
|
|
# match them against entries from the PYBIND11_TEST_FILES, anything that not matches goes into the filter list.
|
|
|
|
string(REGEX REPLACE "\\.[^.;]*;" ";" TEST_OVERRIDE_NO_EXT "${PYBIND11_TEST_OVERRIDE};")
|
|
|
|
string(REGEX REPLACE "\\.[^.;]*;" ";" TEST_FILES_NO_EXT "${PYBIND11_TEST_FILES};")
|
|
|
|
# This allows the override to be done with extensions, preserving backwards compatibility.
|
|
|
|
foreach(test_name ${TEST_FILES_NO_EXT})
|
|
|
|
if(NOT ${test_name} IN_LIST TEST_OVERRIDE_NO_EXT
|
2023-02-09 18:11:01 +00:00
|
|
|
)# If not in the allowlist, add to be filtered out.
|
2022-01-12 01:31:19 +00:00
|
|
|
list(APPEND PYBIND11_TEST_FILTER ${test_name})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2016-11-13 00:10:53 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-12 02:06:52 +00:00
|
|
|
# You can also filter tests:
|
|
|
|
if(PYBIND11_TEST_FILTER)
|
|
|
|
pybind11_filter_tests(PYBIND11_TEST_FILES ${PYBIND11_TEST_FILTER})
|
|
|
|
endif()
|
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
# Skip tests for CUDA check:
|
|
|
|
# /pybind11/tests/test_constants_and_functions.cpp(125):
|
|
|
|
# error: incompatible exception specifications
|
2020-09-12 02:06:52 +00:00
|
|
|
if(PYBIND11_CUDA_TESTS)
|
|
|
|
pybind11_filter_tests(
|
|
|
|
PYBIND11_TEST_FILES test_constants_and_functions.cpp MESSAGE
|
|
|
|
"Skipping test_constants_and_functions due to incompatible exception specifications")
|
2020-09-10 15:49:26 +00:00
|
|
|
endif()
|
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# Now that the test filtering is complete, we need to split the list into the test for PYTEST
|
|
|
|
# and the list for the cpp targets.
|
|
|
|
set(PYBIND11_CPPTEST_FILES "")
|
|
|
|
set(PYBIND11_PYTEST_FILES "")
|
|
|
|
|
|
|
|
foreach(test_name ${PYBIND11_TEST_FILES})
|
|
|
|
if(test_name MATCHES "\\.py$") # Ends in .py, purely python test.
|
|
|
|
list(APPEND PYBIND11_PYTEST_FILES ${test_name})
|
|
|
|
elseif(test_name MATCHES "\\.cpp$") # Ends in .cpp, purely cpp test.
|
|
|
|
list(APPEND PYBIND11_CPPTEST_FILES ${test_name})
|
|
|
|
elseif(NOT test_name MATCHES "\\.") # No extension specified, assume both, add extension.
|
|
|
|
list(APPEND PYBIND11_PYTEST_FILES ${test_name}.py)
|
|
|
|
list(APPEND PYBIND11_CPPTEST_FILES ${test_name}.cpp)
|
|
|
|
else()
|
|
|
|
message(WARNING "Unhanded test extension in test: ${test_name}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(PYBIND11_TEST_FILES ${PYBIND11_CPPTEST_FILES})
|
|
|
|
list(SORT PYBIND11_PYTEST_FILES)
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
# Contains the set of test files that require pybind11_cross_module_tests to be
|
|
|
|
# built; if none of these are built (i.e. because TEST_OVERRIDE is used and
|
|
|
|
# doesn't include them) the second module doesn't get built.
|
2022-01-12 01:31:19 +00:00
|
|
|
tests_extra_targets("test_exceptions.py;test_local_bindings.py;test_stl.py;test_stl_binders.py"
|
|
|
|
"pybind11_cross_module_tests")
|
2017-07-29 00:57:57 +00:00
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# And add additional targets for other tests.
|
2022-05-31 18:51:13 +00:00
|
|
|
tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already_set")
|
2022-01-12 01:31:19 +00:00
|
|
|
tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils")
|
2019-07-15 14:47:02 +00:00
|
|
|
|
2021-10-04 16:31:53 +00:00
|
|
|
set(PYBIND11_EIGEN_REPO
|
|
|
|
"https://gitlab.com/libeigen/eigen.git"
|
|
|
|
CACHE STRING "Eigen repository to use for tests")
|
2021-10-26 18:50:34 +00:00
|
|
|
# Always use a hash for reconfigure speed and security reasons
|
|
|
|
# Include the version number for pretty printing (keep in sync)
|
|
|
|
set(PYBIND11_EIGEN_VERSION_AND_HASH
|
|
|
|
"3.4.0;929bc0e191d0927b1735b9a1ddc0e8b77e3a25ec"
|
|
|
|
CACHE STRING "Eigen version to use for tests, format: VERSION;HASH")
|
|
|
|
|
|
|
|
list(GET PYBIND11_EIGEN_VERSION_AND_HASH 0 PYBIND11_EIGEN_VERSION_STRING)
|
|
|
|
list(GET PYBIND11_EIGEN_VERSION_AND_HASH 1 PYBIND11_EIGEN_VERSION_HASH)
|
2021-10-04 16:31:53 +00:00
|
|
|
|
2016-09-03 18:54:22 +00:00
|
|
|
# Check if Eigen is available; if not, remove from PYBIND11_TEST_FILES (but
|
|
|
|
# keep it in PYBIND11_PYTEST_FILES, so that we get the "eigen is not installed"
|
|
|
|
# skip message).
|
First draft of Eigen::Tensor support (#4201)
* First draft of Eigen::Tensor support
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix build errors
* Weird allocator stuff?
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove unused + additional allocator junk
* Disable warning
* Use constexpr
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clang tidy fixes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve comments
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove auto constexpr function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Try again for older C++
* Oops forgot constexpr
* Move to new files as suggested
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix weird tests
* Fix nits
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Oops, forgot import
* Fix clang 3.6 bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* More comprehensive test suite
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor allocators to make things more clear
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to std::copy
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to DSizes instead of array
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address feedback
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix python + dummy c++ change to trigger build
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Alignment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add include guard
* Forgot inline
* Fix compiler warning
* Remove bad test
* Better type signatures
* Add guards to make compiler requirements more explicit
* style: pre-commit fixes
* Force rerun of tests due to flake
* style: pre-commit fixes
* Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC
* Move headers out of detail
* style: pre-commit fixes
* Fix cmake
* Improve casting
* style: pre-commit fixes
* Add a ton more tests + refactor
* Improve names
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* Fix tests
* style: pre-commit fixes
* Update
* Add a test to verify that strange numpy arrays work
* Fix dumb compiler warning
* Better tests
* Better tests
* Fix tests
* style: pre-commit fixes
* More test fixes
* style: pre-commit fixes
* A ton more test coverage
* Fix tests
* style: pre-commit fixes
* style: pre-commit fixes
* Add back constexpr
* Another test
* style: pre-commit fixes
* Improve tests
* Whoops
* Less magic numbers
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* style: pre-commit fixes
* Fix tests
* style: pre-commit fixes
* Fix memory leak
* style: pre-commit fixes
* Fix order
* style: pre-commit fixes
* Add test to make sure unsafe casts fail
* Minor bug fix to work on 32 bit machines
* Implement convert flag
* style: pre-commit fixes
* Switch to correct TensorMap const use
* style: pre-commit fixes
* Support older versions of eigen
* Weird c++ compilers
* Fix Eigen bug
* Fix another eigen bug
* Yet another eigen bug
* Potential flakes?
* style: pre-commit fixes
* Rerun tests with dummy exception to find out what is going on
* Another dummy test run
* Ablate more
* Found the broken test?
* One step closer
* one step further
* Double check
* one thing at a time
* Give up and disable the test
* Clang lies about being gcc
* Oops, fix matrix test
* style: pre-commit fixes
* Add tests to verify scalar conversions
* style: pre-commit fixes
* Fix nits
* Support no_array
* Fix tests
* style: pre-commit fixes
* Silence compiler warning
* Improve build system for ancient compilers
* Make clang happy
* Make gcc happy
* Implement Skylion's suggestions
* Fix warning
* Inline const pointer check
* Implement suggestions
* style: pre-commit fixes
* Improve tests
* Typo
* style: pre-commit fixes
* Support Google's build environment
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* style: pre-commit fixes
* Test cleanup per Skylion
* Switch to remvove_cv_t
* Cleaner test
* style: pre-commit fixes
* Remove tensor from eigen.h, update tests
* style: pre-commit fixes
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
|
|
|
list(FIND PYBIND11_TEST_FILES test_eigen_matrix.cpp PYBIND11_TEST_FILES_EIGEN_I)
|
|
|
|
if(PYBIND11_TEST_FILES_EIGEN_I EQUAL -1)
|
|
|
|
list(FIND PYBIND11_TEST_FILES test_eigen_tensor.cpp PYBIND11_TEST_FILES_EIGEN_I)
|
|
|
|
endif()
|
2016-09-03 18:54:22 +00:00
|
|
|
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
# Try loading via newer Eigen's Eigen3Config first (bypassing tools/FindEigen3.cmake).
|
|
|
|
# Eigen 3.3.1+ exports a cmake 3.0+ target for handling dependency requirements, but also
|
|
|
|
# produces a fatal error if loaded from a pre-3.0 cmake.
|
2020-07-26 17:44:10 +00:00
|
|
|
if(DOWNLOAD_EIGEN)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.11)
|
|
|
|
message(FATAL_ERROR "CMake 3.11+ required when using DOWNLOAD_EIGEN")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include(FetchContent)
|
|
|
|
FetchContent_Declare(
|
|
|
|
eigen
|
2021-10-04 16:31:53 +00:00
|
|
|
GIT_REPOSITORY "${PYBIND11_EIGEN_REPO}"
|
2021-10-26 18:50:34 +00:00
|
|
|
GIT_TAG "${PYBIND11_EIGEN_VERSION_HASH}")
|
2020-07-26 17:44:10 +00:00
|
|
|
|
|
|
|
FetchContent_GetProperties(eigen)
|
|
|
|
if(NOT eigen_POPULATED)
|
2021-10-26 18:50:34 +00:00
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Downloading Eigen ${PYBIND11_EIGEN_VERSION_STRING} (${PYBIND11_EIGEN_VERSION_HASH}) from ${PYBIND11_EIGEN_REPO}"
|
|
|
|
)
|
2020-07-26 17:44:10 +00:00
|
|
|
FetchContent_Populate(eigen)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
|
|
|
|
set(EIGEN3_FOUND TRUE)
|
2021-10-26 18:50:34 +00:00
|
|
|
# When getting locally, the version is not visible from a superprojet,
|
|
|
|
# so just force it.
|
|
|
|
set(EIGEN3_VERSION "${PYBIND11_EIGEN_VERSION_STRING}")
|
2020-08-19 16:26:26 +00:00
|
|
|
|
2020-07-26 17:44:10 +00:00
|
|
|
else()
|
2020-07-28 04:43:12 +00:00
|
|
|
find_package(Eigen3 3.2.7 QUIET CONFIG)
|
|
|
|
|
2020-07-30 20:20:10 +00:00
|
|
|
if(NOT EIGEN3_FOUND)
|
2020-07-26 17:44:10 +00:00
|
|
|
# Couldn't load via target, so fall back to allowing module mode finding, which will pick up
|
|
|
|
# tools/FindEigen3.cmake
|
|
|
|
find_package(Eigen3 3.2.7 QUIET)
|
|
|
|
endif()
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
endif()
|
2016-09-03 18:54:22 +00:00
|
|
|
|
|
|
|
if(EIGEN3_FOUND)
|
2020-08-19 16:26:26 +00:00
|
|
|
if(NOT TARGET Eigen3::Eigen)
|
|
|
|
add_library(Eigen3::Eigen IMPORTED INTERFACE)
|
|
|
|
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
|
|
|
"${EIGEN3_INCLUDE_DIR}")
|
|
|
|
endif()
|
|
|
|
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
# Eigen 3.3.1+ cmake sets EIGEN3_VERSION_STRING (and hard codes the version when installed
|
|
|
|
# rather than looking it up in the cmake script); older versions, and the
|
|
|
|
# tools/FindEigen3.cmake, set EIGEN3_VERSION instead.
|
|
|
|
if(NOT EIGEN3_VERSION AND EIGEN3_VERSION_STRING)
|
|
|
|
set(EIGEN3_VERSION ${EIGEN3_VERSION_STRING})
|
|
|
|
endif()
|
2016-09-03 18:54:22 +00:00
|
|
|
message(STATUS "Building tests with Eigen v${EIGEN3_VERSION}")
|
2022-12-20 13:34:00 +00:00
|
|
|
|
|
|
|
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
|
|
|
|
tests_extra_targets("test_eigen_tensor.py" "eigen_tensor_avoid_stl_array")
|
|
|
|
endif()
|
|
|
|
|
2016-09-03 18:54:22 +00:00
|
|
|
else()
|
First draft of Eigen::Tensor support (#4201)
* First draft of Eigen::Tensor support
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix build errors
* Weird allocator stuff?
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove unused + additional allocator junk
* Disable warning
* Use constexpr
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clang tidy fixes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve comments
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove auto constexpr function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Try again for older C++
* Oops forgot constexpr
* Move to new files as suggested
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix weird tests
* Fix nits
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Oops, forgot import
* Fix clang 3.6 bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* More comprehensive test suite
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor allocators to make things more clear
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to std::copy
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to DSizes instead of array
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address feedback
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix python + dummy c++ change to trigger build
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Alignment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add include guard
* Forgot inline
* Fix compiler warning
* Remove bad test
* Better type signatures
* Add guards to make compiler requirements more explicit
* style: pre-commit fixes
* Force rerun of tests due to flake
* style: pre-commit fixes
* Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC
* Move headers out of detail
* style: pre-commit fixes
* Fix cmake
* Improve casting
* style: pre-commit fixes
* Add a ton more tests + refactor
* Improve names
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* Fix tests
* style: pre-commit fixes
* Update
* Add a test to verify that strange numpy arrays work
* Fix dumb compiler warning
* Better tests
* Better tests
* Fix tests
* style: pre-commit fixes
* More test fixes
* style: pre-commit fixes
* A ton more test coverage
* Fix tests
* style: pre-commit fixes
* style: pre-commit fixes
* Add back constexpr
* Another test
* style: pre-commit fixes
* Improve tests
* Whoops
* Less magic numbers
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* style: pre-commit fixes
* Fix tests
* style: pre-commit fixes
* Fix memory leak
* style: pre-commit fixes
* Fix order
* style: pre-commit fixes
* Add test to make sure unsafe casts fail
* Minor bug fix to work on 32 bit machines
* Implement convert flag
* style: pre-commit fixes
* Switch to correct TensorMap const use
* style: pre-commit fixes
* Support older versions of eigen
* Weird c++ compilers
* Fix Eigen bug
* Fix another eigen bug
* Yet another eigen bug
* Potential flakes?
* style: pre-commit fixes
* Rerun tests with dummy exception to find out what is going on
* Another dummy test run
* Ablate more
* Found the broken test?
* One step closer
* one step further
* Double check
* one thing at a time
* Give up and disable the test
* Clang lies about being gcc
* Oops, fix matrix test
* style: pre-commit fixes
* Add tests to verify scalar conversions
* style: pre-commit fixes
* Fix nits
* Support no_array
* Fix tests
* style: pre-commit fixes
* Silence compiler warning
* Improve build system for ancient compilers
* Make clang happy
* Make gcc happy
* Implement Skylion's suggestions
* Fix warning
* Inline const pointer check
* Implement suggestions
* style: pre-commit fixes
* Improve tests
* Typo
* style: pre-commit fixes
* Support Google's build environment
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* style: pre-commit fixes
* Test cleanup per Skylion
* Switch to remvove_cv_t
* Cleaner test
* style: pre-commit fixes
* Remove tensor from eigen.h, update tests
* style: pre-commit fixes
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
|
|
|
list(FIND PYBIND11_TEST_FILES test_eigen_matrix.cpp PYBIND11_TEST_FILES_EIGEN_I)
|
|
|
|
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
|
|
|
|
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(FIND PYBIND11_TEST_FILES test_eigen_tensor.cpp PYBIND11_TEST_FILES_EIGEN_I)
|
|
|
|
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
|
|
|
|
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I})
|
|
|
|
endif()
|
2021-02-12 22:11:23 +00:00
|
|
|
message(
|
|
|
|
STATUS "Building tests WITHOUT Eigen, use -DDOWNLOAD_EIGEN=ON on CMake 3.11+ to download")
|
2016-09-03 18:54:22 +00:00
|
|
|
endif()
|
2016-08-12 11:50:00 +00:00
|
|
|
endif()
|
|
|
|
|
First draft of Eigen::Tensor support (#4201)
* First draft of Eigen::Tensor support
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix build errors
* Weird allocator stuff?
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove unused + additional allocator junk
* Disable warning
* Use constexpr
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clang tidy fixes
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Resolve comments
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Remove auto constexpr function
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Try again for older C++
* Oops forgot constexpr
* Move to new files as suggested
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix weird tests
* Fix nits
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Oops, forgot import
* Fix clang 3.6 bug
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* More comprehensive test suite
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor allocators to make things more clear
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to std::copy
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Switch to DSizes instead of array
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Address feedback
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix python + dummy c++ change to trigger build
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Alignment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add include guard
* Forgot inline
* Fix compiler warning
* Remove bad test
* Better type signatures
* Add guards to make compiler requirements more explicit
* style: pre-commit fixes
* Force rerun of tests due to flake
* style: pre-commit fixes
* Keep pragmas & all related comments together, add PLEASE KEEP IN SYNC
* Move headers out of detail
* style: pre-commit fixes
* Fix cmake
* Improve casting
* style: pre-commit fixes
* Add a ton more tests + refactor
* Improve names
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* Fix tests
* style: pre-commit fixes
* Update
* Add a test to verify that strange numpy arrays work
* Fix dumb compiler warning
* Better tests
* Better tests
* Fix tests
* style: pre-commit fixes
* More test fixes
* style: pre-commit fixes
* A ton more test coverage
* Fix tests
* style: pre-commit fixes
* style: pre-commit fixes
* Add back constexpr
* Another test
* style: pre-commit fixes
* Improve tests
* Whoops
* Less magic numbers
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* Update tests/test_eigen_tensor.py
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
* style: pre-commit fixes
* Fix tests
* style: pre-commit fixes
* Fix memory leak
* style: pre-commit fixes
* Fix order
* style: pre-commit fixes
* Add test to make sure unsafe casts fail
* Minor bug fix to work on 32 bit machines
* Implement convert flag
* style: pre-commit fixes
* Switch to correct TensorMap const use
* style: pre-commit fixes
* Support older versions of eigen
* Weird c++ compilers
* Fix Eigen bug
* Fix another eigen bug
* Yet another eigen bug
* Potential flakes?
* style: pre-commit fixes
* Rerun tests with dummy exception to find out what is going on
* Another dummy test run
* Ablate more
* Found the broken test?
* One step closer
* one step further
* Double check
* one thing at a time
* Give up and disable the test
* Clang lies about being gcc
* Oops, fix matrix test
* style: pre-commit fixes
* Add tests to verify scalar conversions
* style: pre-commit fixes
* Fix nits
* Support no_array
* Fix tests
* style: pre-commit fixes
* Silence compiler warning
* Improve build system for ancient compilers
* Make clang happy
* Make gcc happy
* Implement Skylion's suggestions
* Fix warning
* Inline const pointer check
* Implement suggestions
* style: pre-commit fixes
* Improve tests
* Typo
* style: pre-commit fixes
* Support Google's build environment
* style: pre-commit fixes
* Update include/pybind11/eigen/tensor.h
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
* style: pre-commit fixes
* Test cleanup per Skylion
* Switch to remvove_cv_t
* Cleaner test
* style: pre-commit fixes
* Remove tensor from eigen.h, update tests
* style: pre-commit fixes
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Sergiu Deitsch <sergiud@users.noreply.github.com>
2022-10-18 23:54:16 +00:00
|
|
|
# Some code doesn't support gcc 4
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
|
|
|
|
list(FIND PYBIND11_TEST_FILES test_eigen_tensor.cpp PYBIND11_TEST_FILES_EIGEN_I)
|
|
|
|
if(PYBIND11_TEST_FILES_EIGEN_I GREATER -1)
|
|
|
|
list(REMOVE_AT PYBIND11_TEST_FILES ${PYBIND11_TEST_FILES_EIGEN_I})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-08-25 19:11:36 +00:00
|
|
|
# Optional dependency for some tests (boost::variant is only supported with version >= 1.56)
|
|
|
|
find_package(Boost 1.56)
|
2017-08-08 14:02:31 +00:00
|
|
|
|
2020-08-19 16:26:26 +00:00
|
|
|
if(Boost_FOUND)
|
|
|
|
if(NOT TARGET Boost::headers)
|
2020-10-19 00:42:48 +00:00
|
|
|
add_library(Boost::headers IMPORTED INTERFACE)
|
2020-08-19 16:26:26 +00:00
|
|
|
if(TARGET Boost::boost)
|
|
|
|
# Classic FindBoost
|
2020-10-19 00:42:48 +00:00
|
|
|
set_property(TARGET Boost::boost PROPERTY INTERFACE_LINK_LIBRARIES Boost::boost)
|
2020-08-19 16:26:26 +00:00
|
|
|
else()
|
|
|
|
# Very old FindBoost, or newer Boost than CMake in older CMakes
|
|
|
|
set_property(TARGET Boost::headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
|
|
|
${Boost_INCLUDE_DIRS})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-02 14:00:50 +00:00
|
|
|
# Check if we need to add -lstdc++fs or -lc++fs or nothing
|
fix: the types for return_value_policy_override in optional_caster (#3376)
* fix: the types for return_value_policy_override in optional_caster
`return_value_policy_override` was not being applied correctly in
`optional_caster` in two ways:
- The `is_lvalue_reference` condition referenced `T`, which was the
`optional<T>` type parameter from the class, when it should have used `T_`,
which was the parameter to the `cast` function. `T_` can potentially be a
reference type, but `T` will never be.
- The type parameter passed to `return_value_policy_override` should be
`T::value_type`, not `T`. This matches the way that the other STL container
type casters work.
The result of these issues was that a method/property definition which used a
`reference` or `reference_internal` return value policy would create a Python
value that's bound by reference to a temporary C++ object, resulting in
undefined behavior. For reasons that I was not able to figure out fully, it
seems like this causes problems when using old versions of `boost::optional`,
but not with recent versions of `boost::optional` or the `libstdc++`
implementation of `std::optional`. The issue (that the override to
`return_value_policy::move` is never being applied) is present for all
implementations, it just seems like that somehow doesn't result in problems for
the some implementation of `optional`. This change includes a regression type
with a custom optional-like type which was able to reproduce the issue.
Part of the issue with using the wrong types may have stemmed from the type
variables `T` and `T_` having very similar names. This also changes the type
variables in `optional_caster` to use slightly more descriptive names, which
also more closely follow the naming convention used by the other STL casters.
Fixes #3330
* Fix clang-tidy complaints
* Add missing NOLINT
* Apply a couple more fixes
* fix: support GCC 4.8
* tests: avoid warning about unknown compiler for compilers missing C++17
* Remove unneeded test module attribute
* Change test enum to have more unique int values
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-26 02:04:45 +00:00
|
|
|
if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS 17)
|
|
|
|
set(STD_FS_NO_LIB_NEEDED TRUE)
|
|
|
|
elseif(MSVC)
|
2021-07-02 14:00:50 +00:00
|
|
|
set(STD_FS_NO_LIB_NEEDED TRUE)
|
|
|
|
else()
|
|
|
|
file(
|
|
|
|
WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
|
|
|
"#include <filesystem>\nint main(int argc, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}"
|
|
|
|
)
|
|
|
|
try_compile(
|
|
|
|
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
|
|
|
COMPILE_DEFINITIONS -std=c++17)
|
|
|
|
try_compile(
|
|
|
|
STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
|
|
|
COMPILE_DEFINITIONS -std=c++17
|
|
|
|
LINK_LIBRARIES stdc++fs)
|
|
|
|
try_compile(
|
|
|
|
STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
|
|
|
COMPILE_DEFINITIONS -std=c++17
|
|
|
|
LINK_LIBRARIES c++fs)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${STD_FS_NEEDS_STDCXXFS})
|
|
|
|
set(STD_FS_LIB stdc++fs)
|
|
|
|
elseif(${STD_FS_NEEDS_CXXFS})
|
|
|
|
set(STD_FS_LIB c++fs)
|
|
|
|
elseif(${STD_FS_NO_LIB_NEEDED})
|
|
|
|
set(STD_FS_LIB "")
|
|
|
|
else()
|
fix: the types for return_value_policy_override in optional_caster (#3376)
* fix: the types for return_value_policy_override in optional_caster
`return_value_policy_override` was not being applied correctly in
`optional_caster` in two ways:
- The `is_lvalue_reference` condition referenced `T`, which was the
`optional<T>` type parameter from the class, when it should have used `T_`,
which was the parameter to the `cast` function. `T_` can potentially be a
reference type, but `T` will never be.
- The type parameter passed to `return_value_policy_override` should be
`T::value_type`, not `T`. This matches the way that the other STL container
type casters work.
The result of these issues was that a method/property definition which used a
`reference` or `reference_internal` return value policy would create a Python
value that's bound by reference to a temporary C++ object, resulting in
undefined behavior. For reasons that I was not able to figure out fully, it
seems like this causes problems when using old versions of `boost::optional`,
but not with recent versions of `boost::optional` or the `libstdc++`
implementation of `std::optional`. The issue (that the override to
`return_value_policy::move` is never being applied) is present for all
implementations, it just seems like that somehow doesn't result in problems for
the some implementation of `optional`. This change includes a regression type
with a custom optional-like type which was able to reproduce the issue.
Part of the issue with using the wrong types may have stemmed from the type
variables `T` and `T_` having very similar names. This also changes the type
variables in `optional_caster` to use slightly more descriptive names, which
also more closely follow the naming convention used by the other STL casters.
Fixes #3330
* Fix clang-tidy complaints
* Add missing NOLINT
* Apply a couple more fixes
* fix: support GCC 4.8
* tests: avoid warning about unknown compiler for compilers missing C++17
* Remove unneeded test module attribute
* Change test enum to have more unique int values
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-26 02:04:45 +00:00
|
|
|
message(WARNING "Unknown C++17 compiler - not passing -lstdc++fs")
|
2021-07-02 14:00:50 +00:00
|
|
|
set(STD_FS_LIB "")
|
|
|
|
endif()
|
|
|
|
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
# Compile with compiler warnings turned on
|
|
|
|
function(pybind11_enable_warnings target_name)
|
|
|
|
if(MSVC)
|
2022-05-16 21:27:19 +00:00
|
|
|
target_compile_options(${target_name} PRIVATE /W4 /wd4189)
|
2020-09-10 15:49:26 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Intel|Clang)" AND NOT PYBIND11_CUDA_TESTS)
|
2020-10-29 13:12:14 +00:00
|
|
|
target_compile_options(
|
|
|
|
${target_name}
|
|
|
|
PRIVATE -Wall
|
|
|
|
-Wextra
|
|
|
|
-Wconversion
|
|
|
|
-Wcast-qual
|
|
|
|
-Wdeprecated
|
|
|
|
-Wundef
|
|
|
|
-Wnon-virtual-dtor)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(PYBIND11_WERROR)
|
|
|
|
if(MSVC)
|
|
|
|
target_compile_options(${target_name} PRIVATE /WX)
|
2020-09-10 15:49:26 +00:00
|
|
|
elseif(PYBIND11_CUDA_TESTS)
|
|
|
|
target_compile_options(${target_name} PRIVATE "SHELL:-Werror all-warnings")
|
2021-04-14 18:01:27 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang|IntelLLVM)")
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
target_compile_options(${target_name} PRIVATE -Werror)
|
2021-04-14 18:01:27 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
2022-01-11 20:13:02 +00:00
|
|
|
if(CMAKE_CXX_STANDARD EQUAL 17) # See PR #3570
|
|
|
|
target_compile_options(${target_name} PRIVATE -Wno-conversion)
|
|
|
|
endif()
|
2021-04-14 18:01:27 +00:00
|
|
|
target_compile_options(
|
|
|
|
${target_name}
|
|
|
|
PRIVATE
|
|
|
|
-Werror-all
|
|
|
|
# "Inlining inhibited by limit max-size", "Inlining inhibited by limit max-total-size"
|
|
|
|
-diag-disable 11074,11076)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
set(test_targets pybind11_tests)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
|
2022-01-12 01:31:19 +00:00
|
|
|
# Check if any tests need extra targets by iterating through the mappings registered.
|
|
|
|
foreach(i ${PYBIND11_TEST_EXTRA_TARGETS})
|
|
|
|
foreach(needle ${PYBIND11_TEST_EXTRA_TARGETS_NEEDLES_${i}})
|
|
|
|
if(needle IN_LIST PYBIND11_PYTEST_FILES)
|
|
|
|
# Add all the additional targets to the test list. List join in newer cmake.
|
|
|
|
foreach(extra_target ${PYBIND11_TEST_EXTRA_TARGETS_ADDITION_${i}})
|
|
|
|
list(APPEND test_targets ${extra_target})
|
|
|
|
endforeach()
|
|
|
|
break() # Breaks out of the needle search, continues with the next mapping.
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-07-15 14:47:02 +00:00
|
|
|
endforeach()
|
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
# Support CUDA testing by forcing the target file to compile with NVCC
|
|
|
|
if(PYBIND11_CUDA_TESTS)
|
|
|
|
set_property(SOURCE ${PYBIND11_TEST_FILES} PROPERTY LANGUAGE CUDA)
|
|
|
|
endif()
|
|
|
|
|
2017-08-08 14:02:31 +00:00
|
|
|
foreach(target ${test_targets})
|
2017-07-29 00:57:57 +00:00
|
|
|
set(test_files ${PYBIND11_TEST_FILES})
|
2020-07-29 20:42:07 +00:00
|
|
|
if(NOT "${target}" STREQUAL "pybind11_tests")
|
2017-07-29 00:57:57 +00:00
|
|
|
set(test_files "")
|
|
|
|
endif()
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
# Support CUDA testing by forcing the target file to compile with NVCC
|
|
|
|
if(PYBIND11_CUDA_TESTS)
|
|
|
|
set_property(SOURCE ${target}.cpp PROPERTY LANGUAGE CUDA)
|
|
|
|
endif()
|
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
# Create the binding library
|
2017-08-08 14:02:31 +00:00
|
|
|
pybind11_add_module(${target} THIN_LTO ${target}.cpp ${test_files} ${PYBIND11_HEADERS})
|
|
|
|
pybind11_enable_warnings(${target})
|
2017-07-29 00:57:57 +00:00
|
|
|
|
2020-08-19 17:11:57 +00:00
|
|
|
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
|
|
|
|
get_property(
|
|
|
|
suffix
|
|
|
|
TARGET ${target}
|
|
|
|
PROPERTY SUFFIX)
|
|
|
|
set(source_output "${CMAKE_CURRENT_SOURCE_DIR}/${target}${suffix}")
|
|
|
|
if(suffix AND EXISTS "${source_output}")
|
|
|
|
message(WARNING "Output file also in source directory; "
|
|
|
|
"please remove to avoid confusion: ${source_output}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
if(MSVC)
|
2017-08-08 14:02:31 +00:00
|
|
|
target_compile_options(${target} PRIVATE /utf-8)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
endif()
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
if(EIGEN3_FOUND)
|
2020-08-19 16:26:26 +00:00
|
|
|
target_link_libraries(${target} PRIVATE Eigen3::Eigen)
|
2017-08-08 14:02:31 +00:00
|
|
|
target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_EIGEN)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(Boost_FOUND)
|
2020-08-19 16:26:26 +00:00
|
|
|
target_link_libraries(${target} PRIVATE Boost::headers)
|
2017-08-08 14:02:31 +00:00
|
|
|
target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_BOOST)
|
2017-07-29 00:57:57 +00:00
|
|
|
endif()
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2021-07-02 14:00:50 +00:00
|
|
|
target_link_libraries(${target} PRIVATE ${STD_FS_LIB})
|
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
# Always write the output file directly into the 'tests' directory (even on MSVC)
|
|
|
|
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
2020-08-19 17:11:57 +00:00
|
|
|
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
2021-01-19 23:48:22 +00:00
|
|
|
|
|
|
|
if(DEFINED CMAKE_CONFIGURATION_TYPES)
|
|
|
|
foreach(config ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
string(TOUPPER ${config} config)
|
|
|
|
set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2017-07-29 00:57:57 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2016-08-12 11:50:00 +00:00
|
|
|
|
2021-11-18 15:01:24 +00:00
|
|
|
# Provide nice organisation in IDEs
|
|
|
|
if(NOT CMAKE_VERSION VERSION_LESS 3.8)
|
|
|
|
source_group(
|
|
|
|
TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include"
|
|
|
|
PREFIX "Header Files"
|
|
|
|
FILES ${PYBIND11_HEADERS})
|
|
|
|
endif()
|
|
|
|
|
2020-09-12 02:06:52 +00:00
|
|
|
# Make sure pytest is found or produce a warning
|
2020-10-03 02:34:22 +00:00
|
|
|
pybind11_find_import(pytest VERSION 3.1)
|
2016-08-13 00:44:56 +00:00
|
|
|
|
2020-08-19 17:11:57 +00:00
|
|
|
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
|
|
|
|
# This is not used later in the build, so it's okay to regenerate each time.
|
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pytest.ini" "${CMAKE_CURRENT_BINARY_DIR}/pytest.ini"
|
|
|
|
COPYONLY)
|
|
|
|
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/pytest.ini"
|
|
|
|
"\ntestpaths = \"${CMAKE_CURRENT_SOURCE_DIR}\"")
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# cmake 3.12 added list(transform <list> prepend
|
|
|
|
# but we can't use it yet
|
2020-09-22 16:01:15 +00:00
|
|
|
string(REPLACE "test_" "${CMAKE_CURRENT_SOURCE_DIR}/test_" PYBIND11_ABS_PYTEST_FILES
|
2020-08-19 17:11:57 +00:00
|
|
|
"${PYBIND11_PYTEST_FILES}")
|
|
|
|
|
2021-01-15 20:07:31 +00:00
|
|
|
set(PYBIND11_TEST_PREFIX_COMMAND
|
|
|
|
""
|
|
|
|
CACHE STRING "Put this before pytest, use for checkers and such")
|
|
|
|
|
2016-08-12 11:50:00 +00:00
|
|
|
# A single command to compile and run the tests
|
2020-07-30 20:20:10 +00:00
|
|
|
add_custom_target(
|
|
|
|
pytest
|
2021-01-15 20:07:31 +00:00
|
|
|
COMMAND ${PYBIND11_TEST_PREFIX_COMMAND} ${PYTHON_EXECUTABLE} -m pytest
|
|
|
|
${PYBIND11_ABS_PYTEST_FILES}
|
2020-07-30 20:20:10 +00:00
|
|
|
DEPENDS ${test_targets}
|
2021-01-15 20:07:31 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
2020-07-30 20:20:10 +00:00
|
|
|
USES_TERMINAL)
|
2016-11-04 13:47:41 +00:00
|
|
|
|
2016-11-13 00:10:53 +00:00
|
|
|
if(PYBIND11_TEST_OVERRIDE)
|
2020-07-30 20:20:10 +00:00
|
|
|
add_custom_command(
|
|
|
|
TARGET pytest
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Note: not all tests run: -DPYBIND11_TEST_OVERRIDE is in effect")
|
2016-11-13 00:10:53 +00:00
|
|
|
endif()
|
|
|
|
|
2021-01-15 20:07:31 +00:00
|
|
|
# cmake-format: off
|
|
|
|
add_custom_target(
|
|
|
|
memcheck
|
|
|
|
COMMAND
|
|
|
|
PYTHONMALLOC=malloc
|
|
|
|
valgrind
|
|
|
|
--leak-check=full
|
|
|
|
--show-leak-kinds=definite,indirect
|
|
|
|
--errors-for-leak-kinds=definite,indirect
|
|
|
|
--error-exitcode=1
|
|
|
|
--read-var-info=yes
|
|
|
|
--track-origins=yes
|
|
|
|
--suppressions="${CMAKE_CURRENT_SOURCE_DIR}/valgrind-python.supp"
|
|
|
|
--suppressions="${CMAKE_CURRENT_SOURCE_DIR}/valgrind-numpy-scipy.supp"
|
|
|
|
--gen-suppressions=all
|
|
|
|
${PYTHON_EXECUTABLE} -m pytest ${PYBIND11_ABS_PYTEST_FILES}
|
|
|
|
DEPENDS ${test_targets}
|
|
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
USES_TERMINAL)
|
|
|
|
# cmake-format: on
|
|
|
|
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
# Add a check target to run all the tests, starting with pytest (we add dependencies to this below)
|
|
|
|
add_custom_target(check DEPENDS pytest)
|
|
|
|
|
|
|
|
# The remaining tests only apply when being built as part of the pybind11 project, but not if the
|
|
|
|
# tests are being built independently.
|
2020-07-28 04:43:12 +00:00
|
|
|
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
Independent tests (#665)
* Make tests buildable independently
This makes "tests" buildable as a separate project that uses
find_package(pybind11 CONFIG) when invoked independently.
This also moves the WERROR option into tests/CMakeLists.txt, as that's
the only place it is used.
* Use Eigen 3.3.1's cmake target, if available
This changes the eigen finding code to attempt to use Eigen's
system-installed Eigen3Config first. In Eigen 3.3.1, it exports a cmake
Eigen3::Eigen target to get dependencies from (rather than setting the
include path directly).
If it fails, we fall back to the trying to load allowing modules (i.e.
allowing our tools/FindEigen3.cmake). If we either fallback, or the
eigen version is older than 3.3.1 (or , we still set the include
directory manually; otherwise, for CONFIG + new Eigen, we get it via
the target.
This is also needed to allow 'tests' to be built independently, when
the find_package(Eigen3) is going to find via the system-installed
Eigen3Config.cmake.
* Add a install-then-build test, using clang on linux
This tests that `make install` to the actual system, followed by a build
of the tests (without the main pybind11 repository available) works as
expected.
To also expand the testing variety a bit, it also builds using
clang-3.9 instead of gcc.
* Don't try loading Eigen3Config in cmake < 3.0
It could FATAL_ERROR as the newer cmake includes a cmake 3.0 required
line.
If doing an independent, out-of-tree "tests" build, the regular
find_package(Eigen3) is likely to fail with the same error, but I think
we can just let that be: if you want a recent Eigen with proper cmake
loading support *and* want to do an independent tests build, you'll
need at least cmake 3.0.
2017-02-24 22:07:53 +00:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2017-07-29 00:57:57 +00:00
|
|
|
# Add a post-build comment to show the primary test suite .so size and, if a previous size, compare it:
|
2020-07-28 04:43:12 +00:00
|
|
|
add_custom_command(
|
2020-07-30 20:20:10 +00:00
|
|
|
TARGET pybind11_tests
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND
|
|
|
|
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../tools/libsize.py
|
2020-07-28 04:43:12 +00:00
|
|
|
$<TARGET_FILE:pybind11_tests>
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/sosize-$<TARGET_FILE_NAME:pybind11_tests>.txt)
|
2016-12-14 00:43:39 +00:00
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
if(NOT PYBIND11_CUDA_TESTS)
|
|
|
|
# Test embedding the interpreter. Provides the `cpptest` target.
|
|
|
|
add_subdirectory(test_embed)
|
2017-03-23 16:27:32 +00:00
|
|
|
|
2020-09-10 15:49:26 +00:00
|
|
|
# Test CMake build using functions and targets from subdirectory or installed location
|
|
|
|
add_subdirectory(test_cmake_build)
|
|
|
|
endif()
|