blob: a8b3cb1f1032a94d6b63de2fbdd2803b3a99d9a0 [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
Lori A. Burns5cafc992016-12-13 10:55:38 -050075
Henry Schreinerdf115972020-07-31 22:45:19 -040076include("${CMAKE_CURRENT_LIST_DIR}/pybind11Tools.cmake")
Lori A. Burns5cafc992016-12-13 10:55:38 -050077
Lori A. Burns5cafc992016-12-13 10:55:38 -050078#-----------------------------------------------------------------------------
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 Schreiner1b92cd12020-07-29 15:02:53 -040082if(NOT TARGET pybind11::pybind11)
Henry Schreinerdf115972020-07-31 22:45:19 -040083 include("${CMAKE_CURRENT_LIST_DIR}/pybind11Targets.cmake")
Lori A. Burns5cafc992016-12-13 10:55:38 -050084
Henry Schreinerdf115972020-07-31 22:45:19 -040085 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. Burns5cafc992016-12-13 10:55:38 -050088
Henry Schreinerdf115972020-07-31 22:45:19 -040089 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 Schreiner1b92cd12020-07-29 15:02:53 -040091
Henry Schreinerdf115972020-07-31 22:45:19 -040092 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 Schreiner1b92cd12020-07-29 15:02:53 -040095
Henry Schreinerdf115972020-07-31 22:45:19 -040096 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. Burns5cafc992016-12-13 10:55:38 -0500102endif()