Commit Graph

41 Commits

Author SHA1 Message Date
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 230fa53f16
fix: Don't override global settings for VISIBILITY if set (#2793)
Sometimes programmers want to control this, and while it can be changed after the fact, it's commonly set via a CMAKE_ variable; if that variable is set, we should respect that (like the CMAKE_INTERPROCEDURAL_OPTIMIZATION setting).
2021-01-14 08:31:48 -05:00
Yannick Jadoul f243450e89
ci: disable builds for 3.10.0a4, and enable a nightly 3.10-dev build (#2792)
* Disable builds for 3.10.0a4, and enable a nightly 3.10-dev build

* Fix job name

* Remove deadsnakes job for now

* Add deadsnakes jobs

* There's no deadsnakes 2.7

* Add 3.10 to versions to be discovered by legacy FindPython, and fix debug input to deadsnakes/action

* Try out branch with fix

* Update to deadsnakes/action@v2.1.1
2021-01-13 23:13:19 -05:00
Henry Schreiner ffb113d1d8
fix: regression with installed pybind11 overriding local one (#2716)
* fix: regression with installed pybind11 overriding discovered one

Closes #2709

* docs: wording incorrect
2020-12-15 21:55:14 -05:00
Henry Schreiner b8dc60ec8f
fix: Python include directory was missing from DIRS (#2636) 2020-11-02 20:45:54 -05:00
Henry Schreiner a42211536b fix: new line in PYPY_VERSION 2020-10-15 17:38:49 -04:00
Henry Schreiner 2a2f52201d
fix: find_import didn't work properly for classic tools (#2550)
* fix: find_import didn't work properly for classic tools

* ci: fix all files not being checked in style run
2020-10-05 15:31:00 -04:00
Henry Schreiner 3488494a81
refactor: import check as a common function (#2526)
* feat: import check as a common function

* docs: add cmake to docs
2020-10-02 22:34:22 -04:00
Wenzel Jakob 36c666f027 pybind11_add_module(): OPT_SIZE target 2020-09-06 16:46:38 +02:00
Henry Schreiner 9b8cb02030
fix: respect PYTHON_VERSION if set in classic mode (#2414)
* fix: respect PYTHON_VERSION if set in classic mode

* fix: add warning when using PYTHON_VERSION
2020-08-26 09:07:30 -04:00
Bjorn d4d7ef5d27
Update pybind11Tools.cmake (#2419)
CPython configured with `--with-pydebug` could not use `pybind11_add_module`
2020-08-21 14:52:38 -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
Henry Schreiner 0af7fe6c19
fix: typo in pybind11_add_module (#2374) 2020-08-08 17:34:38 -04:00
Henry Schreiner 227170dc2f fix: better handling of PYBIND11_CPP_STANDARD 2020-08-06 11:54:41 -04:00
Henry Schreiner df115977df chore: cleanup 2020-08-06 11:54:41 -04: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
Nils Leif Fischer 141e8cc0af Fix uninitialized-variables cmake warnings 2020-07-01 00:19:25 +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
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
Lori A. Burns 868d94fcb4 Apply c++ standard flag only to files of CXX language. (#1678) 2019-06-11 22:07:57 +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
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
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
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 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
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
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 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