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 | |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 75 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 76 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 77 | |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 78 | #----------------------------------------------------------------------------- |
| 79 | # Don't include targets if this file is being picked up by another |
| 80 | # project which has already built this as a subproject |
| 81 | #----------------------------------------------------------------------------- |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 82 | if(NOT TARGET pybind11::pybind11) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 83 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 84 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 85 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") |
| 86 | find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED) |
| 87 | list(REMOVE_AT CMAKE_MODULE_PATH -1) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 88 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 89 | set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
| 90 | set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 91 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 92 | set_property(TARGET pybind11::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) |
| 93 | set_property(TARGET pybind11::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES |
| 94 | "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>") |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame] | 95 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame^] | 96 | get_property(_iid TARGET pybind11::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| 97 | get_property(_ill TARGET pybind11::module PROPERTY INTERFACE_LINK_LIBRARIES) |
| 98 | set(pybind11_INCLUDE_DIRS ${_iid}) |
| 99 | set(pybind11_LIBRARIES ${_ico} ${_ill}) |
| 100 | |
| 101 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 102 | endif() |