Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics
[simgrid.git] / tools / cmake / Modules / pybind11Config.cmake
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`
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
30 # are attached to the target. Set PythonLibsNew variables to influence
31 # python detection and PYBIND11_CPP_STANDARD (-std=c++11 or -std=c++14) to
32 # influence standard setting. ::
33 #
34 #   find_package(pybind11 CONFIG REQUIRED)
35 #   message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
36 #
37 #   # Create an extension module
38 #   add_library(mylib MODULE main.cpp)
39 #   target_link_libraries(mylib pybind11::module)
40 #
41 #   # Or embed the Python interpreter into an executable
42 #   add_executable(myexe main.cpp)
43 #   target_link_libraries(myexe pybind11::embed)
44 #
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
62 ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
63 ####### Any changes to this file will be overwritten by the next CMake run ####
64 ####### The input file was pybind11Config.cmake.in                            ########
65
66 get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
67
68 macro(set_and_check _var _file)
69   set(${_var} "${_file}")
70   if(NOT EXISTS "${_file}")
71     message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
72   endif()
73 endmacro()
74
75 macro(check_required_components _NAME)
76   foreach(comp ${${_NAME}_FIND_COMPONENTS})
77     if(NOT ${_NAME}_${comp}_FOUND)
78       if(${_NAME}_FIND_REQUIRED_${comp})
79         set(${_NAME}_FOUND FALSE)
80       endif()
81     endif()
82   endforeach()
83 endmacro()
84
85 ####################################################################################
86
87 set(PN pybind11)
88
89 # location of pybind11/pybind11.h
90 set(${PN}_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
91
92 set(${PN}_LIBRARY "")
93 set(${PN}_DEFINITIONS USING_${PN})
94
95 check_required_components(${PN})
96
97 # make detectable the FindPythonLibsNew.cmake module
98 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
99
100 include(pybind11Tools)
101
102 if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
103 #-----------------------------------------------------------------------------
104 # Don't include targets if this file is being picked up by another
105 # project which has already built this as a subproject
106 #-----------------------------------------------------------------------------
107 if(NOT TARGET ${PN}::pybind11)
108     include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
109
110     find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED)
111     set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_DIRS})
112     set_property(TARGET ${PN}::embed APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
113     if(WIN32 OR CYGWIN)
114       set_property(TARGET ${PN}::module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${PYTHON_LIBRARIES})
115     endif()
116
117     set_property(TARGET ${PN}::pybind11 APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "${PYBIND11_CPP_STANDARD}")
118
119     get_property(_iid TARGET ${PN}::pybind11 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
120     get_property(_ill TARGET ${PN}::module PROPERTY INTERFACE_LINK_LIBRARIES)
121     set(${PN}_INCLUDE_DIRS ${_iid})
122     set(${PN}_LIBRARIES ${_ico} ${_ill})
123 endif()
124 endif()