blob: c86e0dea25042bc8af7540368a637769aaabb174 [file] [log] [blame]
Henry Schreinerdf115972020-07-31 22:45:19 -04001#[=============================================================================[.rst
2
3pybind11Config.cmake
4--------------------
5
6PYBIND11 cmake module.
7This 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
18Available components: None
19
20
21Exported targets::
22
23If pybind11 is found, this module defines the following :prop_tgt:`IMPORTED`
24interface library targets::
25
26 pybind11::module - for extension modules
27 pybind11::embed - for embedding the Python interpreter
28
29Python headers, libraries (as needed by platform), and the C++ standard
30are attached to the target.
31Classic mode::
32
33Set PythonLibsNew variables to influence python detection and
34CMAKE_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
47Suggested usage::
48
49find_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
55The 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. Burns5cafc992016-12-13 10:55:38 -050063
64@PACKAGE_INIT@
65
Henry Schreiner1b92cd12020-07-29 15:02:53 -040066# Location of pybind11/pybind11.h
67set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
Lori A. Burns5cafc992016-12-13 10:55:38 -050068
Henry Schreiner1b92cd12020-07-29 15:02:53 -040069set(pybind11_LIBRARY "")
70set(pybind11_DEFINITIONS USING_pybind11)
Henry Schreinerdf115972020-07-31 22:45:19 -040071set(pybind11_VERSION_TYPE "@pybind11_VERSION_TYPE@")
Lori A. Burns5cafc992016-12-13 10:55:38 -050072
Henry Schreiner1b92cd12020-07-29 15:02:53 -040073check_required_components(pybind11)
Lori A. Burns5cafc992016-12-13 10:55:38 -050074
Henry Schreinerdf115972020-07-31 22:45:19 -040075include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake")
Lori A. Burns5cafc992016-12-13 10:55:38 -050076
Lori A. Burns5cafc992016-12-13 10:55:38 -050077#-----------------------------------------------------------------------------
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 Schreiner1b92cd12020-07-29 15:02:53 -040081if(NOT TARGET pybind11::pybind11)
Henry Schreinerdf115972020-07-31 22:45:19 -040082 include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake")
Lori A. Burns5cafc992016-12-13 10:55:38 -050083
Henry Schreinerdf115972020-07-31 22:45:19 -040084 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. Burns5cafc992016-12-13 10:55:38 -050087
Henry Schreinered6de122020-08-01 23:47:47 -040088 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 Schreiner1b92cd12020-07-29 15:02:53 -040096
Henry Schreinered6de122020-08-01 23:47:47 -040097 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 Schreiner1b92cd12020-07-29 15:02:53 -0400108
Henry Schreinered6de122020-08-01 23:47:47 -0400109 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 Schreinerdf115972020-07-31 22:45:19 -0400117 set(pybind11_INCLUDE_DIRS ${_iid})
118 set(pybind11_LIBRARIES ${_ico} ${_ill})
119
120 include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake")
Lori A. Burns5cafc992016-12-13 10:55:38 -0500121endif()