Commit Graph

199 Commits

Author SHA1 Message Date
Henry Schreiner df115977df chore: cleanup 2020-08-06 11:54:41 -04:00
Henry Schreiner b8047245bb
fix: uninstall cleanup (#2346) 2020-07-31 10:16:40 +02:00
Henry Schreiner 94db5c5ed1 format: apply cmake-format 2020-07-30 20:27:55 -04:00
Henry Schreiner 1b92cd1703 fix: address review points from @YannickJadoul 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
Henry Schreiner 1f53c373e4 fix: C++17 mode on Clang may error 2020-07-26 09:25:27 -04:00
tuxmaster5000 7e0a4fb7d0
Fix for #2168 (#2299) 2020-07-24 19:00:48 +02:00
Henry Schreiner 8b0ccf7657 style: adding pre-commit check-style.sh 2020-07-23 19:47:53 -04:00
Liam Keegan c4fd1fd987
CMake improvement: support windows python on msys (#2312)
- look for windows python lib when using mingw & msys
  - if not found, then look for system python lib as before
2020-07-21 19:17:22 +02:00
Henry Schreiner d8c7ee00a6
ci: GHA basic format & pre-commit (#2309) 2020-07-20 13:35:21 -04:00
Yannick Jadoul 964ab956e0
Fix DeprecationWarning about 'invalid escape sequence' in tools/docs Python scripts (#2281) 2020-07-10 16:30:44 +02:00
Nils Leif Fischer 141e8cc0af Fix uninitialized-variables cmake warnings 2020-07-01 00:19:25 +02:00
Takahiro Ishikawa 3618807dca Fix python.lib name
pybind11_add_module fails because FindPythonLibsNew.cmake try to link PythonXX.lib, but the first letter "p" should be lowercase.
2020-07-01 00:14:24 +02:00
MRocholl b14aeb7cfa fix typo in sorted function call argument reverse 2020-04-26 09:29:29 +02:00
MRocholl 9358e30d2a change set_path to set_file 2020-04-26 09:29:29 +02:00
MRocholl 00c462d149 find library path to libclang.so via glob command in /usr/lib/llvm-* and set it 2020-04-26 09:29:29 +02:00
Axel Huebl 6ebfc4b2b0 Document CMAKE_CXX_STANDARD
This variable is a CMake community standard to set the C++
standard of a build. Document it in favor of the previous variable,
which stays as a legacy flag for existing projects.

https://cmake.org/cmake/help/v3.17/variable/CMAKE_CXX_STANDARD.html
2020-04-26 09:17:10 +02:00
Chuck Atkins d730fbc0d5 Utilize CMake's language standards abstraction when possible 2020-04-26 09:17:10 +02:00
Wenzel Jakob bb9c91cce8 pybind11Tools.cmake: search for Python 3.9 2020-03-04 16:17:20 +01:00
Baljak 4f72ef846f Fix the use of MSVC in an MSYS environment (#2087) 2020-01-22 11:49:56 +01:00
Baljak 07e2259322 Fix compilation with MinGW only (#2053) 2020-01-05 15:49:59 +01:00
Matthew Dawkins 6f11347a30 Prevent cmake error when prefix empty (#1986) 2019-11-14 08:53:06 +01:00
Axel Huebl a6355b00f8 CMake: Add Python 3.8 to pybind11Tools (#1974)
Add Python 3.8 to considered versions in CMake for additional
hints.
https://cmake.org/cmake/help/v3.2/module/FindPythonLibs.html
2019-10-31 12:40:15 +01:00
Dmitry 8f5a8ab4ac Don't strip debug symbols in RelWithDebInfo mode (#1892) 2019-08-23 16:18:05 +02:00
Christoph Kahl 640b8fe6d9 fix #1406 add mingw compatibility (#1851) 2019-08-13 21:41:53 +02:00
Lori A. Burns 868d94fcb4 Apply c++ standard flag only to files of CXX language. (#1678) 2019-06-11 22:07:57 +02:00
Dan 41f29ccd9e Parse command-line args in a separate function. 2019-06-11 13:49:37 +02:00
Dan e0b8bbbce9 Use a file-local constant for non-prefixing nodes. 2019-06-11 13:49:37 +02:00
Dan 2c8c5c4ed3 Split into seperate functions for easier invocation from python. 2019-06-11 13:49:37 +02:00
Dan 590e7acedf Avoid storing global state. 2019-06-11 13:49:37 +02:00
Dan a163f8813e Delete partially-written file in the event of an error. 2019-06-11 13:49:37 +02:00
Dan ede328a784 Allow writing output to file instead of stdout. 2019-06-11 13:49:37 +02:00
Dan a33212df1f Wrap the main functionality of mkdoc in a function. 2019-06-11 13:49:37 +02:00
Dan b46bb64d39 Allow user to override default values of -x and -std=. 2019-06-11 13:49:37 +02:00
Dan 4612db54ac Try to autodetect the location of the clang standard libraries.
On some linuxes, /usr/include belongs to GCC and the standard
libraries that work with clang are in /usr/lib/clang/8.0.0 or
some variation thereof.

This results in errors such as:

```
/../lib64/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0/bits/cxxabi_init_exception.h:38:10: fatal error: 'stddef.h' file not found

```

during extraction.
2019-06-11 13:49:37 +02:00
Dan a175b21e4b Avoid decoding already-decoded strings from cindex.
Recent versions of clang.cindex include [code][1] that converts
the internal byte strings to python str for you.

  [1]: https://github.com/llvm-mirror/clang/blob/master/bindings/python/clang/cindex.py#L72
2019-06-11 13:49:37 +02:00
Jamie Snape a0b8f70df4 Ensure PythonLibsNew_FOUND is set in FindPythonLibsNew module (#1373)
Since the module is named FindPythonLibsNew, PythonLibsNew_FOUND should be set appropriately.
2019-05-12 19:43:44 +02:00
Rune Paamand 06d021b6e4 Issue #1532: Incompatible config options, /MP vs /Gm for MSVC in DEBUG (#1533)
* Issue #1532: Incompatible config options, /MP vs /Gm for MSVC in DEBUG
2018-10-25 01:35:33 +02:00
Ryota Suzuki 1377fbf73c Fix unintentional escaping of character on Windows (#1574) (#1575) 2018-10-24 11:18:04 +02:00
Davis E. King 9343e68b46 Fix cmake scripts so projects using CUDA .cu files build correctly. (#1441) 2018-09-14 14:28:54 +02:00
Axel Huebl 435dbdd114 add_module: allow include as SYSTEM (#1416)
pybind11 headers passed via the `pybind11_add_module` CMake
function can now be included as `SYSTEM` includes (`-isystem`).

This allows to set stricter (or experimental) warnings in
calling projects that might throw otherwise in headers
a user of pybind11 can not influence.
2018-08-29 13:20:11 +02:00
Axel Huebl 3a94561c4d Debug Builds: -DPy_DEBUG (#1438)
builds against a python debug library were unreliable and
could lead to symbol errors during linking.

Setting the `Py_DEBUG` define is necessary when linking
against a debug build:

https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib

https://docs.python.org/2/c-api/intro.html#debugging-builds

https://docs.python.org/3.6/c-api/intro.html#debugging-builds
2018-08-29 13:18:43 +02:00
luz.paz 28cb6764fc misc. typos
Found via `codespell`
2018-01-11 16:39:50 -04:00
Unknown 0b3f44ebdf Trivial typos
Non-user facing. 
Found using `codespell -q 3`
2017-11-01 22:48:36 -03:00
Henry Schreiner 43126201a6 Fix style script and add comment to failing blocks (#1045)
[skip appveyor]
2017-09-10 12:24:33 +02:00
Dean Moldovan 76e06c89e4 Avoid duplicate C++ standard flags if CMAKE_CXX_STANDARD is set
CMAKE_CXX_STANDARD is only available on CMake >= 3.1. If the flag is
set, we avoid initializing PYBIND11_CPP_STANDARD.
2017-08-17 03:04:44 +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 2e37fe09e1 Fix compatibility of FindPythonLibsNew.cmake and FindPythonLibs.cmake
Make sure `LibsNew` runs correctly if called after the old `Libs`.
2017-07-23 03:32:19 +02:00
Jason Rhinelander fad5d3386c Detect c++ standard unconditionally
Currently select_cxx_standard(), which sets PYBIND11_CPP_STANDARD when
not externally set, is only called from pybind11_add_module(), but the
embed target setup (which runs unconditionally) makes use of
${PYBIND11_CPP_STANDARD}, which isn't set yet.  This commit removes the
`select_cxx_standard` function completely and just always runs the
standard detection code.

This also tweaks the detection code to not bothering checking for the
`-std=c++11` flag when the `-std=c++14` detection succeeded.
2017-07-16 11:01:00 -04:00
Jason Rhinelander d080f833be Make check-style.sh work on stock macOS
./tools/check-style.sh fails on stock OS X currently; this fixes it:

- use pipes directly rather than exec redirection (macOS's ancient
  version of bash fails with the latter)
- macOS's ancient bash doesn't support '\e' escapes in `echo -e`;
  replace with \033 instead
- BSD grep doesn't support GREP_COLORS, but does allow GREP_COLOR.
  Adding both doesn't hurt GNU grep: GREP_COLOR is deprecated, and won't
  be used when GREP_COLORS is set.
- BSD grep doesn't collapse multiple /'s in the listed filename, so
  failures under `include/` would should up as
  `include//pybind11/whatever.h`.  This removes the / from the include
  directory argument.

Minor other changes:
- The CRLF detection runs with -l, so GREP_COLORS wasn't doing
  anything; removed it.
- The trailing whitespace test would trigger on CRLFs, but the CR would
  result in messed up output.  Changed the test to just match trailing
  spaces and tabs, rather than all whitespace.
2017-06-14 15:19:42 -04:00
Dean Moldovan 9693a5c78f Add Catch framework for testing embedding support and C++-side features
At this point, there is only a single test for interpreter basics.

Apart from embedding itself, having a C++ test framework will also
benefit the C++-side features by allowing them to be tested directly.
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 77710ff01c Make PYBIND11_CPP_STANDARD work under MSVC
Under MSVC we were ignoring PYBIND11_CPP_STANDARD and simply not
passing any standard (which makes MSVC default to its C++14 mode).

MSVC 2015u3 added the `/std:c++14` and `/std:c++latest` flags; the
latter, under MSVC 2017, enables some C++17 features (such as
`std::optional` and `std::variant`), so it is something we need to
start supporting under MSVC.

This makes the PYBIND11_CPP_STANDARD cmake variable work under MSVC,
defaulting it to /std:c++14 (matching the default -std=c++14 for
non-MSVC).

It also adds a new appveyor test running under MSVC 2017 with
/std:c++latest, which runs (and passes) the
`std::optional`/`std::variant` tests.

Also updated the documentation to clarify the c++ flags and add show
MSVC flag examples.
2017-05-09 16:41:47 -04:00
Wenzel Jakob 257df10ffe improve mkdoc.py determinism
When processing many files that contain top-level items with the same
name (e.g. "operator<<"), the output was non-deterministic and depended
on the order in which the different Clang processes finished. This
commit adds sorting that also accounts for the filename to prevent
random changes from run to run.
2017-04-12 11:09:47 +02:00
Wenzel Jakob 280470d80c updated cindex.py submodule to latest version 2017-03-30 13:14:33 +02:00
Dean Moldovan d361ea15fb Don't strip debug symbols in debug mode (#669) 2017-02-14 20:11:25 +01:00
Jason Rhinelander c137c0a87b Store LTO flags in PYBIND11_LTO_{CXX,LINKER}_FLAGS cache variables
This both lets us not bother rechecking LTO flags when cmake reinvokes
itself, and also lets the cmake invoker override to specify custom or
no LTO flags by setting the cache variable with
-DPYBIND11_LTO_CXX_FLAGS= when invoking cmake.
2017-02-14 10:59:59 +01:00
Jason Rhinelander 1bee6e7df8 Overhaul LTO flag detection
Clang on linux currently fails to run cmake:

    $ CC=clang CXX=clang++ cmake ..
    ...
    -- Configuring done
    CMake Error at tools/pybind11Tools.cmake:135 (target_compile_options):
      Error evaluating generator expression:

        $<:-flto>

      Expression did not evaluate to a known generator expression
    Call Stack (most recent call first):
      tests/CMakeLists.txt:68 (pybind11_add_module)

But investigating this led to various other -flto detection problems;
this commit thus overhauls LTO flag detection:

- -flto needs to be passed to the linker as well
- Also compile with -fno-fat-lto-objects under GCC
- Pass the equivalent flags to MSVC
- Enable LTO flags for via generator expressions (for non-debug builds
  only), so that multi-config builds (like on Windows) still work
  properly.  This seems reasonable, however, even on single-config
  builds (and simplifies the cmake code a bit).
- clang's lto linker plugins don't accept '-Os', so replace it with
  '-O3' when doing a MINSIZEREL build
- Enable trying ThinLTO by default for test suite (only affects clang)
- Match Clang$ rather than ^Clang$ because, for cmake with 3.0+
  policies in effect, the compiler ID will be AppleClang on macOS.
2017-02-14 10:59:59 +01:00
Lori A. Burns 53a338c05a fix one lingering ::pybind11 --> ::module target name (#603) 2017-01-13 11:10:22 +01:00
Dean Moldovan 5b5e3de369 Make Python version selection in CMake more convenient (#589)
This way a non-CACHE variable can also be used. For example:
```
set(PYBIND11_PYTHON_VERSION <value>)
add_subdirectory(...)
```
2017-01-06 23:38:00 +01:00
Wenzel Jakob a9730be73c use -x flag to strip shared libraries on OSX (fixes #595) 2017-01-06 14:20:26 +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 0cbec5c96e Add new options and docs for pybind11_add_module
See the documentation for a description of the options.
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
Wenzel Jakob de2c6df200 check-style.sh: check for accidentally committed CRLF line endings 2016-12-13 00:24:08 +01:00
Jason Rhinelander 2ac2d69418 Improve FindPythonLibsNew detection of python library directory (#523)
* Use LIBDIR and MULTIARCH on linux to find python library

* Remove apple-specific setting; the non-windows one should work fine on OS X

* Default LIBDIR/MULTIARCH to '' (to avoid getting None)

* Remove trailing whitespace from FindPythonLibsNew
2016-11-22 22:01:03 +01:00
Dean Moldovan d079f41c26 Always use return_value_policy::move for rvalues (#510)
Fixes #509.

The move policy was already set for rvalues in PR #473, but this only
applied to directly cast user-defined types. The problem is that STL
containers cast values indirectly and the rvalue information is lost.
Therefore the move policy was not set correctly. This commit fixes it.

This also makes an additional adjustment to remove the `copy` policy
exception: rvalues now always use the `move` policy. This is also safe
for copy-only rvalues because the `move` policy has an internal fallback
to copying.
2016-11-20 05:31:02 +01:00
Wenzel Jakob 2b92a49115 updated check-style.sh docs 2016-11-08 10:58:22 +01:00
Wenzel Jakob cc4efe69c2 more code style checks in Travis CI :) 2016-11-08 10:53:30 +01:00
Jason Rhinelander dc0b4bd2c9 Add debugging info about .so size to build output (#477)
* Add debugging info about so size to build output

This adds a small python script to tools that captures before-and-after
.so sizes between builds and outputs this in the build output via a
string such as:

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 924696 (decrease of 73680 bytes = 7.38%)

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (increase of 73680 bytes = 7.97%)

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376 (no change)

Or, if there was no .so during the build, just the .so size by itself:

------ pybind11_tests.cpython-35m-x86_64-linux-gnu.so file size: 998376

This allows you to, for example, build, checkout a different branch,
rebuild, and easily see exactly the change in the pybind11_tests.so
size.

It also allows looking at the travis and appveyor build logs to get an
idea of .so/.dll sizes across different build systems.

* Minor libsize.py script changes

- Use RAII open
- Remove unused libsize=-1
- Report change as [+-]xyz bytes = [+-]a.bc%
2016-11-04 14:47:41 +01:00
Wenzel Jakob f66610153f FindPythonLibsNew: wasn't actually setting PYTHONLIBS_FOUND contrary to specs 2016-10-09 14:12:24 +02:00
Wenzel Jakob fe34241e50 minor doc & style fixes 2016-09-06 13:02:29 +09:00
Wenzel Jakob 85f07e18cc minor code style checker update 2016-09-04 23:00:49 +09:00
Jason Rhinelander d472f0f058 Add line numbers; show and highlight found tabs
This makes the output considerably easier to use: it now highlights (in
red) matched tabs (instead of just listing the filenames), and adds
line numbers to both the tabs check and the space-less if check outputs.
2016-08-29 21:25:11 -04:00
Jason Rhinelander 5a3570c47c Fix check-style exit status
The check-style exit status wasn't being propagated properly because
the loops were running in a subshell (and so the change the the
`errors` variable wasn't in the active command shell).  This fixes it
by running the greps in subshells and the loops in the main shell.

This also avoids the if(/for(/while( style check on
tests/CMakeLists.txt, since it *does* have if() statements with no space
that are producing error messages, but that is (acceptable) CMake style.
2016-08-29 19:04:12 -04:00
Jason Rhinelander dbc4bf68ed check-style: also report no space in if(/for(/while( 2016-08-28 14:53:04 -04:00
Jason Rhinelander ac4278970c Check for tabs instead of spaces in the doc build
This adds a tool that checks style (currently just for tabs instead of
spaces in files under include/tests/docs) and produces a travis-ci build
failure if any problems are found.
2016-08-28 14:11:23 -04:00
Dean Moldovan 7b4f8dc048 Fix module file name when working with debug builds of Python
Fixes #365. `sysconfig.get_config_var('SO')` already returns the correct
PYTHON_MODULE_EXTENSION, even for debug builds, so there is no need to
add anything else manually.
2016-08-27 20:34:33 +02:00
Christian Ewald b81c500ce2 Fixed finding python libraries on windows in venv
When run on windows in a venv, PYTHON_LIBRARY pointet to a non-existant
location in the virtual environment directory.

This has been fixed by testing if the path exists and, if not, trying
an alternative path, relative to the PYTHON_INCLUDE_DIR.

If the alternative path doesn't exit as well, an error will be raised.
2016-08-08 08:31:08 +02:00
Wenzel Jakob 5766c3a609 cindex.py updated 2016-07-01 12:21:53 +02:00
Dean Moldovan e782eb86e9 Skip FindPythonLibsNew if PYTHONLIBS_FOUND is defined (fix #236)
Also:
- Update documented result variables
- Remove long-ago-deprecated variable
2016-06-12 11:06:08 +02:00
Dean Moldovan 928fff649f Include a more robust FindPythonLibs module for CMake 2016-05-22 20:49:35 +02:00
Wenzel Jakob f64ff575d7 mkdoc.py: improved formatting of code segments and enums 2016-05-20 16:37:13 +02:00
Wenzel Jakob 9e0a0568fe transparent conversion of dense and sparse Eigen types 2016-05-05 21:44:29 +02:00
Wenzel Jakob 65f0c2aeb7 mkdoc.py: handle conversion operators and template arguments in function names 2016-05-01 22:39:46 +02:00
Wenzel Jakob c993bcec19 mkdoc.py: document enumerations 2016-05-01 02:32:38 +02:00
Wenzel Jakob 87810d8e91 mkdoc.py: fixed DOC() macro 2016-04-30 23:55:10 +02:00
Wenzel Jakob 295acb2da0 mkdoc.py: handle \ingroup attributes 2016-04-30 23:36:57 +02:00
Wenzel Jakob f02f41656b support longer argument lists in expansion of variadic DOC() macro 2016-04-29 14:32:10 +02:00
Merlin Nimier-David 77173d6347 mkdoc.py: fix typo in `__DOC5` macro
This prevented `DOC(...)` calls with 5 arguments to resolve correctly.
2016-04-29 14:25:39 +02:00
Wenzel Jakob a57e51c5d8 mkdoc.py: sanitize_name fixes, PEP 8 cleanups 2016-04-27 00:35:06 +02:00
Wenzel Jakob d361a57863 minor mkdoc name sanitation fix 2016-04-26 00:12:22 +02:00
Wenzel Jakob afb9c1776a make mkdoc now works with the libclang distribution from Apple 2016-04-19 13:33:21 +02:00
Wenzel Jakob efd9e987f5 windows fixes 2015-08-04 18:53:18 +02:00
Wenzel Jakob 281aa0e668 nicer code separation, cleanup logic, std::function type caster 2015-07-31 04:10:38 +02:00
Wenzel Jakob fa70d30248 documentation extraction improvements 2015-07-23 14:43:34 +02:00
Wenzel Jakob ad06e76f9f Documentation extraction tool 2015-07-22 01:05:41 +02:00