Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 1 | # pybind11Config.cmake |
| 2 | # -------------------- |
| 3 | # |
| 4 | # PYBIND11 cmake module. |
| 5 | # This module sets the following variables in your project:: |
| 6 | # |
| 7 | # pybind11_FOUND - true if pybind11 and all required components found on the system |
| 8 | # pybind11_VERSION - pybind11 version in format Major.Minor.Release |
| 9 | # pybind11_INCLUDE_DIRS - Directories where pybind11 and python headers are located. |
| 10 | # pybind11_INCLUDE_DIR - Directory where pybind11 headers are located. |
| 11 | # pybind11_DEFINITIONS - Definitions necessary to use pybind11, namely USING_pybind11. |
| 12 | # pybind11_LIBRARIES - compile flags and python libraries (as needed) to link against. |
| 13 | # pybind11_LIBRARY - empty. |
| 14 | # CMAKE_MODULE_PATH - appends location of accompanying FindPythonLibsNew.cmake and |
| 15 | # pybind11Tools.cmake modules. |
| 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` |
Dean Moldovan | 7f5c85c | 2017-03-23 13:32:54 +0100 | [diff] [blame] | 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 |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 30 | # are attached to the target. Set PythonLibsNew variables to influence |
Axel Huebl | 6ebfc4b | 2020-04-25 18:10:53 -0700 | [diff] [blame] | 31 | # python detection and CMAKE_CXX_STANDARD (11 or 14) to influence standard |
| 32 | # setting. :: |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 33 | # |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 34 | # find_package(pybind11 CONFIG REQUIRED) |
Dean Moldovan | 7f5c85c | 2017-03-23 13:32:54 +0100 | [diff] [blame] | 35 | # message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") |
| 36 | # |
| 37 | # # Create an extension module |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 38 | # add_library(mylib MODULE main.cpp) |
Dean Moldovan | 71e8a79 | 2016-12-17 21:38:57 +0100 | [diff] [blame] | 39 | # target_link_libraries(mylib pybind11::module) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 40 | # |
Dean Moldovan | 7f5c85c | 2017-03-23 13:32:54 +0100 | [diff] [blame] | 41 | # # Or embed the Python interpreter into an executable |
| 42 | # add_executable(myexe main.cpp) |
| 43 | # target_link_libraries(myexe pybind11::embed) |
| 44 | # |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 45 | # Suggested usage:: |
| 46 | # |
| 47 | # find_package with version info is not recommended except for release versions. :: |
| 48 | # |
| 49 | # find_package(pybind11 CONFIG) |
| 50 | # find_package(pybind11 2.0 EXACT CONFIG REQUIRED) |
| 51 | # |
| 52 | # |
| 53 | # The following variables can be set to guide the search for this package:: |
| 54 | # |
| 55 | # pybind11_DIR - CMake variable, set to directory containing this Config file |
| 56 | # CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package |
| 57 | # PATH - environment variable, set to bin directory of this package |
| 58 | # CMAKE_DISABLE_FIND_PACKAGE_pybind11 - CMake variable, disables |
| 59 | # find_package(pybind11) when not REQUIRED, perhaps to force internal build |
| 60 | |
| 61 | @PACKAGE_INIT@ |
| 62 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame^] | 63 | # Location of pybind11/pybind11.h |
| 64 | set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 65 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame^] | 66 | set(pybind11_LIBRARY "") |
| 67 | set(pybind11_DEFINITIONS USING_pybind11) |
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 | check_required_components(pybind11) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 70 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame^] | 71 | # Make the FindPythonLibsNew.cmake module available |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 72 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) |
| 73 | |
| 74 | include(pybind11Tools) |
| 75 | |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 76 | #----------------------------------------------------------------------------- |
| 77 | # Don't include targets if this file is being picked up by another |
| 78 | # project which has already built this as a subproject |
| 79 | #----------------------------------------------------------------------------- |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame^] | 80 | if(NOT TARGET pybind11::pybind11) |
| 81 | include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake") |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 82 | |
| 83 | find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 84 | |
Henry Schreiner | 1b92cd1 | 2020-07-29 15:02:53 -0400 | [diff] [blame^] | 85 | set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
| 86 | set_property(TARGET pybind11::pybind11 APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS}) |
| 87 | |
| 88 | set_property(TARGET pybind11::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES}) |
| 89 | set_property(TARGET pybind11::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES |
| 90 | "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>") |
| 91 | |
| 92 | get_property(_iid TARGET pybind11::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) |
| 93 | get_property(_ill TARGET pybind11::module PROPERTY INTERFACE_LINK_LIBRARIES) |
| 94 | set(pybind11_INCLUDE_DIRS ${_iid}) |
| 95 | set(pybind11_LIBRARIES ${_ico} ${_ill}) |
Lori A. Burns | 5cafc99 | 2016-12-13 10:55:38 -0500 | [diff] [blame] | 96 | endif() |