Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 1 | #[=============================================================================[.rst |
| 2 | |
| 3 | pybind11Config.cmake |
| 4 | -------------------- |
| 5 | |
| 6 | PYBIND11 cmake module. |
| 7 | This module sets the following variables in your project:: |
| 8 | |
| 9 | pybind11_FOUND - true if pybind11 and all required components found on the system |
| 10 | pybind11_VERSION - pybind11 version in format Major.Minor.Release |
| 11 | pybind11_INCLUDE_DIRS - Directories where pybind11 and python headers are located. |
| 12 | pybind11_INCLUDE_DIR - Directory where pybind11 headers are located. |
| 13 | pybind11_DEFINITIONS - Definitions necessary to use pybind11, namely USING_pybind11. |
| 14 | pybind11_LIBRARIES - compile flags and python libraries (as needed) to link against. |
| 15 | pybind11_LIBRARY - empty. |
| 16 | |
| 17 | |
| 18 | Available components: None |
| 19 | |
| 20 | |
| 21 | Exported targets:: |
| 22 | |
| 23 | If pybind11 is found, this module defines the following :prop_tgt:`IMPORTED` |
| 24 | interface library targets:: |
| 25 | |
| 26 | pybind11::module - for extension modules |
| 27 | pybind11::embed - for embedding the Python interpreter |
| 28 | |
| 29 | Python headers, libraries (as needed by platform), and the C++ standard |
| 30 | are attached to the target. |
| 31 | Classic mode:: |
| 32 | |
| 33 | Set PythonLibsNew variables to influence python detection and |
| 34 | CMAKE_CXX_STANDARD to influence standard setting. :: |
| 35 | |
| 36 | find_package(pybind11 CONFIG REQUIRED) |
| 37 | message(STATUS "Found pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}: ${pybind11_INCLUDE_DIRS}") |
| 38 | |
| 39 | # Create an extension module |
| 40 | add_library(mylib MODULE main.cpp) |
| 41 | target_link_libraries(mylib pybind11::module) |
| 42 | |
| 43 | # Or embed the Python interpreter into an executable |
| 44 | add_executable(myexe main.cpp) |
| 45 | target_link_libraries(myexe pybind11::embed) |
| 46 | |
| 47 | Suggested usage:: |
| 48 | |
| 49 | find_package with version info is not recommended except for release versions. :: |
| 50 | |
| 51 | find_package(pybind11 CONFIG) |
| 52 | find_package(pybind11 2.0 EXACT CONFIG REQUIRED) |
| 53 | |
| 54 | |
| 55 | The following variables can be set to guide the search for this package:: |
| 56 | |
| 57 | pybind11_DIR - CMake variable, set to directory containing this Config file |
| 58 | CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package |
| 59 | PATH - environment variable, set to bin directory of this package |
| 60 | CMAKE_DISABLE_FIND_PACKAGE_pybind11 - CMake variable, disables |
| 61 | find_package(pybind11) when not REQUIRED, perhaps to force internal build |
| 62 | #]=============================================================================] |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 63 | |
| 64 | @PACKAGE_INIT@ |
| 65 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 66 | # Location of pybind11/pybind11.h |
| 67 | set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 68 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 69 | set(pybind11_LIBRARY "") |
| 70 | set(pybind11_DEFINITIONS USING_pybind11) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 71 | set(pybind11_VERSION_TYPE "@pybind11_VERSION_TYPE@") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 72 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 73 | check_required_components(pybind11) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 74 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 75 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 76 | |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 77 | #----------------------------------------------------------------------------- |
| 78 | # Don't include targets if this file is being picked up by another |
| 79 | # project which has already built this as a subproject |
| 80 | #----------------------------------------------------------------------------- |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 81 | if(NOT TARGET pybind11::pybind11) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 82 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 83 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 84 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") |
| 85 | find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED) |
| 86 | list(REMOVE_AT CMAKE_MODULE_PATH -1) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 87 | |
Henry Schreiner | ed6de12 | 2020-08-01 23:47:47 -0400 | [diff] [blame^] | 88 | set_property( |
| 89 | TARGET pybind11::pybind11 |
| 90 | APPEND |
| 91 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
| 92 | set_property( |
| 93 | TARGET pybind11::pybind11 |
| 94 | APPEND |
| 95 | PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 96 | |
Henry Schreiner | ed6de12 | 2020-08-01 23:47:47 -0400 | [diff] [blame^] | 97 | set_property( |
| 98 | TARGET pybind11::embed |
| 99 | APPEND |
| 100 | PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) |
| 101 | set_property( |
| 102 | TARGET pybind11::module |
| 103 | APPEND |
| 104 | PROPERTY |
| 105 | INTERFACE_LINK_LIBRARIES |
| 106 | "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>" |
| 107 | ) |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 108 | |
Henry Schreiner | ed6de12 | 2020-08-01 23:47:47 -0400 | [diff] [blame^] | 109 | get_property( |
| 110 | _iid |
| 111 | TARGET pybind11::pybind11 |
| 112 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| 113 | get_property( |
| 114 | _ill |
| 115 | TARGET pybind11::module |
| 116 | PROPERTY INTERFACE_LINK_LIBRARIES) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 117 | set(pybind11_INCLUDE_DIRS ${_iid}) |
| 118 | set(pybind11_LIBRARIES ${_ico} ${_ill}) |
| 119 | |
| 120 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 121 | endif() |