4 # Edited for simgrid so that we survive when pybind11Tools is not found,
5 # concluding that pybind11 is not installed. Original version was 2.2.4-2.
7 # PYBIND11 cmake module.
8 # This module sets the following variables in your project::
10 # pybind11_FOUND - true if pybind11 and all required components found on the system
11 # pybind11_VERSION - pybind11 version in format Major.Minor.Release
12 # pybind11_INCLUDE_DIRS - Directories where pybind11 and python headers are located.
13 # pybind11_INCLUDE_DIR - Directory where pybind11 headers are located.
14 # pybind11_DEFINITIONS - Definitions necessary to use pybind11, namely USING_pybind11.
15 # pybind11_LIBRARIES - compile flags and python libraries (as needed) to link against.
16 # pybind11_LIBRARY - empty.
17 # CMAKE_MODULE_PATH - appends location of accompanying FindPythonLibsNew.cmake and
18 # pybind11Tools.cmake modules.
21 # Available components: None
26 # If pybind11 is found, this module defines the following :prop_tgt:`IMPORTED`
27 # interface library targets::
29 # pybind11::module - for extension modules
30 # pybind11::embed - for embedding the Python interpreter
32 # Python headers, libraries (as needed by platform), and the C++ standard
33 # are attached to the target. Set PythonLibsNew variables to influence
34 # python detection and PYBIND11_CPP_STANDARD (-std=c++11 or -std=c++14) to
35 # influence standard setting. ::
37 # find_package(pybind11 CONFIG REQUIRED)
38 # message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
40 # # Create an extension module
41 # add_library(mylib MODULE main.cpp)
42 # target_link_libraries(mylib pybind11::module)
44 # # Or embed the Python interpreter into an executable
45 # add_executable(myexe main.cpp)
46 # target_link_libraries(myexe pybind11::embed)
50 # find_package with version info is not recommended except for release versions. ::
52 # find_package(pybind11 CONFIG)
53 # find_package(pybind11 2.0 EXACT CONFIG REQUIRED)
56 # The following variables can be set to guide the search for this package::
58 # pybind11_DIR - CMake variable, set to directory containing this Config file
59 # CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package
60 # PATH - environment variable, set to bin directory of this package
61 # CMAKE_DISABLE_FIND_PACKAGE_pybind11 - CMake variable, disables
62 # find_package(pybind11) when not REQUIRED, perhaps to force internal build
65 ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
66 ####### Any changes to this file will be overwritten by the next CMake run ####
67 ####### The input file was pybind11Config.cmake.in ########
69 get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
71 macro(set_and_check _var _file)
72 set(${_var} "${_file}")
73 if(NOT EXISTS "${_file}")
74 message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
78 macro(check_required_components _NAME)
79 foreach(comp ${${_NAME}_FIND_COMPONENTS})
80 if(NOT ${_NAME}_${comp}_FOUND)
81 if(${_NAME}_FIND_REQUIRED_${comp})
82 set(${_NAME}_FOUND FALSE)
88 ####################################################################################
92 # location of pybind11/pybind11.h
93 set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
96 set(${PN}_DEFINITIONS USING_${PN})
98 check_required_components(${PN})
100 # make detectable the FindPythonLibsNew.cmake module
101 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
103 # SimGrid edit: survive to the fact that pybind11Tools is not found, but stop searching when it happens
104 include(pybind11Tools OPTIONAL RESULT_VARIABLE found_pybind11_tools)
106 if((NOT (found_pybind11_tools STREQUAL "NOT_FOUND")) AND (NOT (CMAKE_VERSION VERSION_LESS 3.0)))
107 #-----------------------------------------------------------------------------
108 # Don't include targets if this file is being picked up by another
109 # project which has already built this as a subproject
110 #-----------------------------------------------------------------------------
111 if(NOT TARGET ${PN}::pybind11)
112 include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
114 find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED)
115 set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
116 set_property(TARGET ${PN}::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
118 set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
121 set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}")
123 get_property(_iid TARGET ${PN}::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
124 get_property(_ill TARGET ${PN}::module PROPERTY INTERFACE_LINK_LIBRARIES)
125 set(${PN}_INCLUDE_DIRS ${_iid})
126 set(${PN}_LIBRARIES ${_ico} ${_ill})
129 unset(found_pybind11tools)