Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / tools / cmake / Modules / pybind11Config.cmake
1 # pybind11Config.cmake
2 # --------------------
3 #
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.
6 #
7 # PYBIND11 cmake module.
8 # This module sets the following variables in your project::
9 #
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.
19 #
20 #
21 # Available components: None
22 #
23 #
24 # Exported targets::
25 #
26 # If pybind11 is found, this module defines the following :prop_tgt:`IMPORTED`
27 # interface library targets::
28 #
29 #   pybind11::module - for extension modules
30 #   pybind11::embed - for embedding the Python interpreter
31 #
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. ::
36 #
37 #   find_package(pybind11 CONFIG REQUIRED)
38 #   message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
39 #
40 #   # Create an extension module
41 #   add_library(mylib MODULE main.cpp)
42 #   target_link_libraries(mylib pybind11::module)
43 #
44 #   # Or embed the Python interpreter into an executable
45 #   add_executable(myexe main.cpp)
46 #   target_link_libraries(myexe pybind11::embed)
47 #
48 # Suggested usage::
49 #
50 # find_package with version info is not recommended except for release versions. ::
51 #
52 #   find_package(pybind11 CONFIG)
53 #   find_package(pybind11 2.0 EXACT CONFIG REQUIRED)
54 #
55 #
56 # The following variables can be set to guide the search for this package::
57 #
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
63
64
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                            ########
68
69 get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
70
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 !")
75   endif()
76 endmacro()
77
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)
83       endif()
84     endif()
85   endforeach()
86 endmacro()
87
88 ####################################################################################
89
90 set(PN pybind11)
91
92 # location of pybind11/pybind11.h
93 set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
94
95 set(${PN}_LIBRARY "")
96 set(${PN}_DEFINITIONS USING_${PN})
97
98 check_required_components(${PN})
99
100 # make detectable the FindPythonLibsNew.cmake module
101 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
102
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)
105
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")
113
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})
117     if(WIN32 OR CYGWIN)
118       set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
119     endif()
120
121     set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}")
122
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})
127 endif()
128 endif()
129 unset(found_pybind11tools)