Back to home page

EIC code displayed by LXR

 
 

    


Warning, /jana2/src/python/externals/pybind11-2.10.3/tools/pybind11Tools.cmake is written in an unsupported language. File is not indexed.

0001 # tools/pybind11Tools.cmake -- Build system for the pybind11 modules
0002 #
0003 # Copyright (c) 2020 Wenzel Jakob <wenzel.jakob@epfl.ch>
0004 #
0005 # All rights reserved. Use of this source code is governed by a
0006 # BSD-style license that can be found in the LICENSE file.
0007 
0008 # include_guard(global) (pre-CMake 3.10)
0009 if(TARGET pybind11::python_headers)
0010   return()
0011 endif()
0012 
0013 # Built-in in CMake 3.5+
0014 include(CMakeParseArguments)
0015 
0016 if(pybind11_FIND_QUIETLY)
0017   set(_pybind11_quiet QUIET)
0018 else()
0019   set(_pybind11_quiet "")
0020 endif()
0021 
0022 # If this is the first run, PYTHON_VERSION can stand in for PYBIND11_PYTHON_VERSION
0023 if(NOT DEFINED PYBIND11_PYTHON_VERSION AND DEFINED PYTHON_VERSION)
0024   message(WARNING "Set PYBIND11_PYTHON_VERSION to search for a specific version, not "
0025                   "PYTHON_VERSION (which is an output). Assuming that is what you "
0026                   "meant to do and continuing anyway.")
0027   set(PYBIND11_PYTHON_VERSION
0028       "${PYTHON_VERSION}"
0029       CACHE STRING "Python version to use for compiling modules")
0030   unset(PYTHON_VERSION)
0031   unset(PYTHON_VERSION CACHE)
0032 elseif(DEFINED PYBIND11_PYTHON_VERSION)
0033   # If this is set as a normal variable, promote it
0034   set(PYBIND11_PYTHON_VERSION
0035       "${PYBIND11_PYTHON_VERSION}"
0036       CACHE STRING "Python version to use for compiling modules")
0037 else()
0038   # Make an empty cache variable.
0039   set(PYBIND11_PYTHON_VERSION
0040       ""
0041       CACHE STRING "Python version to use for compiling modules")
0042 endif()
0043 
0044 # A user can set versions manually too
0045 set(Python_ADDITIONAL_VERSIONS
0046     "3.11;3.10;3.9;3.8;3.7;3.6"
0047     CACHE INTERNAL "")
0048 
0049 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
0050 find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} MODULE REQUIRED ${_pybind11_quiet})
0051 list(REMOVE_AT CMAKE_MODULE_PATH -1)
0052 
0053 # Makes a normal variable a cached variable
0054 macro(_PYBIND11_PROMOTE_TO_CACHE NAME)
0055   set(_tmp_ptc "${${NAME}}")
0056   # CMake 3.21 complains if a cached variable is shadowed by a normal one
0057   unset(${NAME})
0058   set(${NAME}
0059       "${_tmp_ptc}"
0060       CACHE INTERNAL "")
0061 endmacro()
0062 
0063 # Cache variables so pybind11_add_module can be used in parent projects
0064 _pybind11_promote_to_cache(PYTHON_INCLUDE_DIRS)
0065 _pybind11_promote_to_cache(PYTHON_LIBRARIES)
0066 _pybind11_promote_to_cache(PYTHON_MODULE_PREFIX)
0067 _pybind11_promote_to_cache(PYTHON_MODULE_EXTENSION)
0068 _pybind11_promote_to_cache(PYTHON_VERSION_MAJOR)
0069 _pybind11_promote_to_cache(PYTHON_VERSION_MINOR)
0070 _pybind11_promote_to_cache(PYTHON_VERSION)
0071 _pybind11_promote_to_cache(PYTHON_IS_DEBUG)
0072 
0073 if(PYBIND11_MASTER_PROJECT)
0074   if(PYTHON_MODULE_EXTENSION MATCHES "pypy")
0075     if(NOT DEFINED PYPY_VERSION)
0076       execute_process(
0077         COMMAND ${PYTHON_EXECUTABLE} -c
0078                 [=[import sys; sys.stdout.write(".".join(map(str, sys.pypy_version_info[:3])))]=]
0079         OUTPUT_VARIABLE pypy_version)
0080       set(PYPY_VERSION
0081           ${pypy_version}
0082           CACHE INTERNAL "")
0083     endif()
0084     message(STATUS "PYPY ${PYPY_VERSION} (Py ${PYTHON_VERSION})")
0085   else()
0086     message(STATUS "PYTHON ${PYTHON_VERSION}")
0087   endif()
0088 endif()
0089 
0090 # Only add Python for build - must be added during the import for config since
0091 # it has to be re-discovered.
0092 #
0093 # This needs to be an target to it is included after the local pybind11
0094 # directory, just in case there are multiple versions of pybind11, we want the
0095 # one we expect.
0096 add_library(pybind11::python_headers INTERFACE IMPORTED)
0097 set_property(TARGET pybind11::python_headers PROPERTY INTERFACE_INCLUDE_DIRECTORIES
0098                                                       "$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>")
0099 set_property(
0100   TARGET pybind11::pybind11
0101   APPEND
0102   PROPERTY INTERFACE_LINK_LIBRARIES pybind11::python_headers)
0103 
0104 set(pybind11_INCLUDE_DIRS
0105     "${pybind11_INCLUDE_DIR}" "${PYTHON_INCLUDE_DIRS}"
0106     CACHE INTERNAL "Directories where pybind11 and possibly Python headers are located")
0107 
0108 # Python debug libraries expose slightly different objects before 3.8
0109 # https://docs.python.org/3.6/c-api/intro.html#debugging-builds
0110 # https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib
0111 if(PYTHON_IS_DEBUG)
0112   set_property(
0113     TARGET pybind11::pybind11
0114     APPEND
0115     PROPERTY INTERFACE_COMPILE_DEFINITIONS Py_DEBUG)
0116 endif()
0117 
0118 # The <3.11 code here does not support release/debug builds at the same time, like on vcpkg
0119 if(CMAKE_VERSION VERSION_LESS 3.11)
0120   set_property(
0121     TARGET pybind11::module
0122     APPEND
0123     PROPERTY
0124       INTERFACE_LINK_LIBRARIES
0125       pybind11::python_link_helper
0126       "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:$<BUILD_INTERFACE:${PYTHON_LIBRARIES}>>"
0127   )
0128 
0129   set_property(
0130     TARGET pybind11::embed
0131     APPEND
0132     PROPERTY INTERFACE_LINK_LIBRARIES pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
0133 else()
0134   # The IMPORTED INTERFACE library here is to ensure that "debug" and "release" get processed outside
0135   # of a generator expression - https://gitlab.kitware.com/cmake/cmake/-/issues/18424, as they are
0136   # target_link_library keywords rather than real libraries.
0137   add_library(pybind11::_ClassicPythonLibraries IMPORTED INTERFACE)
0138   target_link_libraries(pybind11::_ClassicPythonLibraries INTERFACE ${PYTHON_LIBRARIES})
0139   target_link_libraries(
0140     pybind11::module
0141     INTERFACE
0142       pybind11::python_link_helper
0143       "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
0144 
0145   target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
0146                                                   pybind11::_ClassicPythonLibraries)
0147 endif()
0148 
0149 function(pybind11_extension name)
0150   # The prefix and extension are provided by FindPythonLibsNew.cmake
0151   set_target_properties(${name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
0152                                            SUFFIX "${PYTHON_MODULE_EXTENSION}")
0153 endfunction()
0154 
0155 # Build a Python extension module:
0156 # pybind11_add_module(<name> [MODULE | SHARED] [EXCLUDE_FROM_ALL]
0157 #                     [NO_EXTRAS] [THIN_LTO] [OPT_SIZE] source1 [source2 ...])
0158 #
0159 function(pybind11_add_module target_name)
0160   set(options "MODULE;SHARED;EXCLUDE_FROM_ALL;NO_EXTRAS;SYSTEM;THIN_LTO;OPT_SIZE")
0161   cmake_parse_arguments(ARG "${options}" "" "" ${ARGN})
0162 
0163   if(ARG_MODULE AND ARG_SHARED)
0164     message(FATAL_ERROR "Can't be both MODULE and SHARED")
0165   elseif(ARG_SHARED)
0166     set(lib_type SHARED)
0167   else()
0168     set(lib_type MODULE)
0169   endif()
0170 
0171   if(ARG_EXCLUDE_FROM_ALL)
0172     set(exclude_from_all EXCLUDE_FROM_ALL)
0173   else()
0174     set(exclude_from_all "")
0175   endif()
0176 
0177   add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS})
0178 
0179   target_link_libraries(${target_name} PRIVATE pybind11::module)
0180 
0181   if(ARG_SYSTEM)
0182     message(
0183       STATUS
0184         "Warning: this does not have an effect - use NO_SYSTEM_FROM_IMPORTED if using imported targets"
0185     )
0186   endif()
0187 
0188   pybind11_extension(${target_name})
0189 
0190   # -fvisibility=hidden is required to allow multiple modules compiled against
0191   # different pybind versions to work properly, and for some features (e.g.
0192   # py::module_local).  We force it on everything inside the `pybind11`
0193   # namespace; also turning it on for a pybind module compilation here avoids
0194   # potential warnings or issues from having mixed hidden/non-hidden types.
0195   if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
0196     set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
0197   endif()
0198 
0199   if(NOT DEFINED CMAKE_CUDA_VISIBILITY_PRESET)
0200     set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
0201   endif()
0202 
0203   if(ARG_NO_EXTRAS)
0204     return()
0205   endif()
0206 
0207   if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
0208     if(ARG_THIN_LTO)
0209       target_link_libraries(${target_name} PRIVATE pybind11::thin_lto)
0210     else()
0211       target_link_libraries(${target_name} PRIVATE pybind11::lto)
0212     endif()
0213   endif()
0214 
0215   # Use case-insensitive comparison to match the result of $<CONFIG:cfgs>
0216   string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
0217   if(NOT MSVC AND NOT "${uppercase_CMAKE_BUILD_TYPE}" MATCHES DEBUG|RELWITHDEBINFO)
0218     pybind11_strip(${target_name})
0219   endif()
0220 
0221   if(MSVC)
0222     target_link_libraries(${target_name} PRIVATE pybind11::windows_extras)
0223   endif()
0224 
0225   if(ARG_OPT_SIZE)
0226     target_link_libraries(${target_name} PRIVATE pybind11::opt_size)
0227   endif()
0228 endfunction()
0229 
0230 # Provide general way to call common Python commands in "common" file.
0231 set(_Python
0232     PYTHON
0233     CACHE INTERNAL "" FORCE)