Commit Graph

111 Commits

Author SHA1 Message Date
Henry Schreiner
130c99544d
fix: support basic dual includes (#2804) 2021-01-19 18:49:03 -05:00
Henry Schreiner
eb83feefff
style: avoid using unintialized variables (#2806)
* style: avoid using unintialized variables

Tested with cmake --warn-unintialized -S . -B build

* refactor: use function for possibly uninit vars
2021-01-19 18:48:22 -05:00
Henry Schreiner
b8dc60ec8f
fix: Python include directory was missing from DIRS (#2636) 2020-11-02 20:45:54 -05:00
Henry Schreiner
edda89ba68
fix: install to DATAROOTDIR instead of hardcoding share (#2584)
Closes #2571; this is defined to share, and unlike DATADIR, is not sometimes overwritten incorrectly for storing CMake files.
2020-10-13 13:08:54 -04:00
Henry Schreiner
fd61f5038e
feat: setup.py redesign and helpers (#2433)
* feat: setup.py redesign and helpers

* refactor: simpler design with two outputs

* refactor: helper file update and Windows support

* fix: review points from @YannickJadoul

* refactor: fixes to naming and more docs

* feat: more customization points

* feat: add entry point pybind11-config

* refactor: Try Extension-focused method

* refactor: rename alt/inplace to global

* fix: allow usage with git modules, better docs

* feat: global as an extra (@YannickJadoul's suggestion)

* feat: single version location

* fix: remove the requirement that setuptools must be imported first

* fix: some review points from @wjacob

* fix: use .in, add procedure to docs

* refactor: avoid monkeypatch copy

* docs: minor typos corrected

* fix: minor points from @YannickJadoul

* fix: typo on Windows C++ mode

* fix: MSVC 15 update 3+ have c++14 flag

See <https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2019>

* docs: discuss making SDists by hand

* ci: use pep517.build instead of manual setup.py

* refactor: more comments from @YannickJadoul

* docs: updates from @ktbarrett

* fix: change to newly recommended tool instead of pep517.build

This was intended as a proof of concept; build seems to be the correct replacement.

See https://github.com/pypa/pep517/pull/83

* docs: updates from @wjakob

* refactor: dual version locations

* docs: typo spotted by @wjakob
2020-09-16 17:13:41 -04:00
Wenzel Jakob
064a03a49b main CMakeLists.txt file: be less noisy 2020-09-06 16:46:38 +02:00
Henry Schreiner
c58f7b745b
fix: reduce target collision in add_submodule mode (#2423)
* fix: reduce target collision in add_submodule mode

Closes #2420

* fix: update CMakeLists.txt
2020-08-22 09:06:01 -04:00
Henry Schreiner
24dffe46af
fix: PYBIND11_MASTER_PROJECT always ON (#2412) 2020-08-19 16:49:08 -04:00
Henry Schreiner
04fdc44f50
tests: avoid putting build products into source directory (#2353)
* tests: keep source dir clean

* ci: make first build inplace

* ci: drop dev setting (wasn't doing anything)

* tests: warn if source directory is dirty
2020-08-19 13:11:57 -04:00
Henry Schreiner
1729aae96f
feat: new FindPython support (#2370)
* feat: FindPython support

* refactor: rename to PYBIND11_FINDPYTHON

* docs: Caps fixes

* feat: NOPYTHON mode

* test: check simple call

* docs: add changelog/upgrade guide

* feat: Support Python3 and Python2

* refactor: Use targets in tests

* fix: support CMake 3.4+

* feat: classic search also finds virtual environments

* docs: some updates from @wjakob's review

* fix: wrong name for QUIET mode variable, reported by @skoslowski

* refactor: cleaner output messaging

* fix: support debug Python's in FindPython mode too

* fixup! refactor: cleaner output messaging

* fix: missing pybind11_FOUND and pybind11_INCLUDE_DIR restored to subdir mode

* fix: nicer reporting of Python / PyPy

* fix: out-of-order variable fix

* docs: minor last-minute cleanup
2020-08-19 12:26:26 -04:00
Paul Fultz II
69821d9e75
Disable testing when using BUILD_TESTING (#1682) 2020-08-18 08:34:18 -04:00
Henry Schreiner
df115977df chore: cleanup 2020-08-06 11:54:41 -04:00
Henry Schreiner
1caf1d0613
fix: check list validity and add missing file (#2352)
Added a check on CMake 3.12+ to make sure the file listing is up to date. And caught a missing file with it!
2020-08-01 15:24:30 -04:00
Henry Schreiner
b8047245bb
fix: uninstall cleanup (#2346) 2020-07-31 10:16:40 +02:00
acxz
6f6e9394ce
feat: add uninstall target for CMake (#2265)
* add uninstall target for cmake

* only add target when built as master project

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2020-07-30 21:16:50 -04:00
Henry Schreiner
94db5c5ed1 format: apply cmake-format 2020-07-30 20:27:55 -04:00
Henry Schreiner
1651c32492 update: address review points 2020-07-30 20:27:55 -04:00
Henry Schreiner
f64d5aa6da fix: typo for warning on C++17, support Win + 2.7 2020-07-30 20:27:55 -04:00
Henry Schreiner
6ec1775fff feat: drop CMake 3.6 and below, modernize CMake
fix: include PYTHON_IS_DEBUG
2020-07-30 20:27:55 -04:00
Axel Huebl
97b20e537a CMake: Remember Python Version (#1434)
It is useful not only to remember the python libs and includes but
also the interpreter version in cache.

If users call pybind11 throught `add_subdirectories` they will
otherwise have no access to the selected interpreter version.
The interpreter version is useful for downstream projects, e.g.
to select default `lib/pythonX.Y/site-packages/` install paths.
2018-06-24 15:22:41 +02:00
Dean Moldovan
a80af9557d Add a dummy common.h header with a deprecation warning 2017-09-06 15:22:26 +02:00
Florian Apolloner
29b99a11a4 Specify CXX as project language for CMake >= 3.4 (#1027) 2017-08-30 14:17:54 +02:00
Dean Moldovan
024932b379 Move everything related to internals into a separate detail header 2017-08-23 10:44:52 +02:00
Jason Rhinelander
464d98962d Allow binding factory functions as constructors
This allows you to use:

    cls.def(py::init(&factory_function));

where `factory_function` returns a pointer, holder, or value of the
class type (or a derived type).  Various compile-time checks
(static_asserts) are performed to ensure the function is valid, and
various run-time type checks where necessary.

Some other details of this feature:
- The `py::init` name doesn't conflict with the templated no-argument
  `py::init<...>()`, but keeps the naming consistent: the existing
  templated, no-argument one wraps constructors, the no-template,
  function-argument one wraps factory functions.
- If returning a CppClass (whether by value or pointer) when an CppAlias
  is required (i.e. python-side inheritance and a declared alias), a
  dynamic_cast to the alias is attempted (for the pointer version); if
  it fails, or if returned by value, an Alias(Class &&) constructor
  is invoked.  If this constructor doesn't exist, a runtime error occurs.
- for holder returns when an alias is required, we try a dynamic_cast of
  the wrapped pointer to the alias to see if it is already an alias
  instance; if it isn't, we raise an error.
- `py::init(class_factory, alias_factory)` is also available that takes
  two factories: the first is called when an alias is not needed, the
  second when it is.
- Reimplement factory instance clearing.  The previous implementation
  failed under python-side multiple inheritance: *each* inherited
  type's factory init would clear the instance instead of only setting
  its own type value.  The new implementation here clears just the
  relevant value pointer.
- dealloc is updated to explicitly set the leftover value pointer to
  nullptr and the `holder_constructed` flag to false so that it can be
  used to clear preallocated value without needing to rebuild the
  instance internals data.
- Added various tests to test out new allocation/deallocation code.
- With preallocation now done lazily, init factory holders can
  completely avoid the extra overhead of needing an extra
  allocation/deallocation.
- Updated documentation to make factory constructors the default
  advanced constructor style.
- If an `__init__` is called a second time, we have two choices: we can
  throw away the first instance, replacing it with the second; or we can
  ignore the second call.  The latter is slightly easier, so do that.
2017-08-17 09:33:27 -04:00
Jason Rhinelander
0d703f6e7c Don't force hidden visibility on the embed target, just the module target
Embedding may well be used in places where hidden visibility isn't
desired.  It should be relatively safe to allow it there; any potential
conflict would come in if modules are loaded into that embedded
interpreter, but as long as the modules are compiled with hidden
visibility they shouldn't conflict.

There could still be warnings if the embedded code attempts to export
classes with internal (hidden) pybind members, but that seems a
legitimate warning (and already has a FAQ entry).
2017-08-17 01:57:31 -04:00
Dean Moldovan
f580649871 Move internal headers into detail subdirectory 2017-08-17 04:06:35 +02:00
Jason Rhinelander
97aa54fefa Compile with hidden visibility always; set via cmake property rather than compiler flag
This updates the compilation to always apply hidden visibility to
resolve the issues with default visibility causing problems under debug
compilations.  Moreover using the cmake property makes it easier for a
caller to override if absolutely needed for some reason.

For `pybind11_add_module` we use cmake to set the property; for the
targets, we append to compilation option to non-MSVC compilers.
2017-08-14 11:44:17 -04:00
Dean Moldovan
3dde6ddc53 Add test for custom CMake export group 2017-08-07 23:08:20 +02:00
Ben Boeckel
017a747da6 CMake: support a custom export group (#970)
When Pybind11 is used via `add_subdirectory`, when targets are installed
from the parent project, CMake wants all of the dependencies built by
the project in the same export set. Projects may now set
`PYBIND11_EXPORT_NAME` to have Pybind11 put it targets into the
project's export set. If so, do not install Pybind11's export file.
2017-08-07 22:32:35 +02:00
Dean Moldovan
22c413b196 Add C++ interface for the Python interpreter 2017-05-28 02:12:24 +02:00
Dean Moldovan
7f5c85c861 Add CMake target for embedding the Python interpreter
All targets provided by pybind11:

* pybind11::module - the existing target for creating extension modules
* pybind11::embed - new target for embedding the interpreter
* pybind11::pybind11 - common "base" target (headers only)
2017-05-28 02:12:24 +02:00
Jason Rhinelander
2b941b38b4 Add missing header to setup.py 2017-05-07 12:19:19 -04:00
Jason Rhinelander
dbb4c5b531 Move buffer_info to its own header
Upcoming changes to buffer_info make it need some things declared in
common.h; it also feels a bit misplaced in common.h (which is arguably
too large already), so move it out.  (Separating this and the subsequent
changes into separate commits to make the changes easier to distinguish
from the move.)
2017-04-13 09:57:02 -04:00
Ghislain Antony Vaillant
5b50376490 Arch-indep CMake packaging (#764)
* Arch-indep CMake packaging

Since pybind11 is a header-only library, the CMake packaging does not have to carry any architecture specific checks. Without this patch, the detection of pybind11 will fail on 32-bit architectures if the project was built on a 64-bit machine and vice-versa. This fix is similar to what is applied to `Eigen` and other header-only C++ libraries.
2017-03-24 23:09:38 +01:00
Jason Rhinelander
60d0e0db3e 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 23:07:53 +01:00
Dean Moldovan
c91f8bd627 Reimplement static properties by extending PyProperty_Type
Instead of creating a new unique metaclass for each type, the builtin
`property` type is subclassed to support static properties. The new
setter/getters always pass types instead of instances in their `self`
argument. A metaclass is still required to support this behavior, but
it doesn't store any data anymore, so a new one doesn't need to be
created for each class. There is now only one common metaclass which
is shared by all pybind11 types.
2017-02-23 15:45:26 +01:00
Sylvain Corlay
d5ce82b6f5 CMake installation path consistency (#652)
* Add flag for installation of headers under python include directory

* Allow the disabling of distutils install_headers
2017-02-14 13:16:14 +01:00
Matthew Woehlke
e15fa9f99a Avoid C-style const casts (#659)
* Avoid C-style const casts

Replace C-style casts that discard `const` with `const_cast` (and, where
necessary, `reinterpret_cast` as well).

* Warn about C-style const-discarding casts

Change pybind11_enable_warnings to also enable `-Wcast-qual` (warn if a
C-style cast discards `const`) by default. The previous commit should
have gotten rid of all of these (at least, all the ones that tripped in
my build, which included the tests), and this should discourage more
from newly appearing.
2017-02-08 23:43:08 +01:00
Jason Rhinelander
a3fec901b8 Avoid CMP0048 warning (#570)
Fixes #567.

If pybind's CMakeLists gets loaded via an include_directory from another
CMakeLists with a higher minimum version (e.g. 3.0), the project()
command without a version produces a CMP0048 warning.

This commit explicitly requests the new behaviour if the policy exists,
as it won't cause problems (we set VERSION later).
2016-12-26 11:26:21 +01:00
Dean Moldovan
71e8a7962c Rename target from pybind11::pybind11 to pybind11::module
Makes room for an eventual pybind11::embedded target.
2016-12-19 16:34:48 +01:00
Dean Moldovan
b0f3885c95 Make sure add_subdirectory and find_package behave identically
Add a BUILD_INTERFACE and a pybind11::pybind11 alias for the interface
library to match the installed target.

Add new cmake tests for add_subdirectory and consolidates the
.cpp and .py files needed for the cmake build tests:

Before:
tests
|-- test_installed_module
|   |-- CMakeLists.txt
|   |-- main.cpp
|   \-- test.py
\-- test_installed_target
    |-- CMakeLists.txt
    |-- main.cpp
    \-- test.py

After:
tests
\-- test_cmake_build
    |-- installed_module/CMakeLists.txt
    |-- installed_target/CMakeLists.txt
    |-- subdirectory_module/CMakeLists.txt
    |-- subdirectory_target/CMakeLists.txt
    |-- main.cpp
    \-- test.py
2016-12-19 16:34:48 +01:00
Lori A. Burns
545b4dbc19 separate main CMakeLists.txt into Tools file also available upon installation 2016-12-13 21:44:19 +01:00
Lori A. Burns
5cafc99884 add CMake exported interface library and Config detection file 2016-12-13 21:44:19 +01:00
Lori A. Burns
44d7c59c55 make installation include and Config dirs configurable. set CMake project version from source. 2016-12-13 21:44:19 +01:00
Alexander Stukowski
9a110e6da8 Provide more control over automatic generation of docstrings (#486)
Added the docstring_options class, which gives global control over the generation of docstrings and function signatures.
2016-11-15 12:38:05 +01:00
Wenzel Jakob
26df852392 removed forgotten message() stmt from CMakeLists.txt 2016-10-10 01:35:27 +02:00
Wenzel Jakob
6a1734af23 minor cmake cleanups 2016-10-09 20:14:23 +02:00
Wenzel Jakob
dac3858e7d Make header files viewable in IDEs (fixes #424) 2016-09-29 21:30:00 +02:00
Trent Houliston
352149e892 Refactor the chrono cast functions into chrono.h.
Add unit tests and documentation for the chrono cast.
2016-09-13 19:58:05 +10:00
Dean Moldovan
b62a896f31 Add barebones build to Travis CI
This build makes sure everything still works without optional
dependencies (numpy/scipy/eigen) and also tests the automatic
discovery functions in CMake (Python version, C++ standard).

[skip appveyor]
2016-08-26 11:41:27 +02:00