Warning, /jana2/src/python/externals/pybind11-2.10.3/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # CMakeLists.txt -- Build system for the pybind11 modules
0002 #
0003 # Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.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 cmake_minimum_required(VERSION 3.4)
0009
0010 # The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with
0011 # some versions of VS that have a patched CMake 3.11. This forces us to emulate
0012 # the behavior using the following workaround:
0013 if(${CMAKE_VERSION} VERSION_LESS 3.22)
0014 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
0015 else()
0016 cmake_policy(VERSION 3.22)
0017 endif()
0018
0019 # Avoid infinite recursion if tests include this as a subdirectory
0020 if(DEFINED PYBIND11_MASTER_PROJECT)
0021 return()
0022 endif()
0023
0024 # Extract project version from source
0025 file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
0026 pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
0027
0028 foreach(ver ${pybind11_version_defines})
0029 if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
0030 set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
0031 endif()
0032 endforeach()
0033
0034 if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]])
0035 set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}")
0036 endif()
0037 string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
0038
0039 project(
0040 pybind11
0041 LANGUAGES CXX
0042 VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}")
0043
0044 # Standard includes
0045 include(GNUInstallDirs)
0046 include(CMakePackageConfigHelpers)
0047 include(CMakeDependentOption)
0048
0049 if(NOT pybind11_FIND_QUIETLY)
0050 message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}")
0051 endif()
0052
0053 # Check if pybind11 is being used directly or via add_subdirectory
0054 if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
0055 ### Warn if not an out-of-source builds
0056 if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
0057 set(lines
0058 "You are building in-place. If that is not what you intended to "
0059 "do, you can clean the source directory with:\n"
0060 "rm -r CMakeCache.txt CMakeFiles/ cmake_uninstall.cmake pybind11Config.cmake "
0061 "pybind11ConfigVersion.cmake tests/CMakeFiles/\n")
0062 message(AUTHOR_WARNING ${lines})
0063 endif()
0064
0065 set(PYBIND11_MASTER_PROJECT ON)
0066
0067 if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
0068 # Bug in macOS CMake < 3.7 is unable to download catch
0069 message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
0070 elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
0071 # Only tested with 3.8+ in CI.
0072 message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
0073 endif()
0074
0075 message(STATUS "CMake ${CMAKE_VERSION}")
0076
0077 if(CMAKE_CXX_STANDARD)
0078 set(CMAKE_CXX_EXTENSIONS OFF)
0079 set(CMAKE_CXX_STANDARD_REQUIRED ON)
0080 endif()
0081
0082 set(pybind11_system "")
0083
0084 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
0085 else()
0086 set(PYBIND11_MASTER_PROJECT OFF)
0087 set(pybind11_system SYSTEM)
0088 endif()
0089
0090 # Options
0091 option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
0092 option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
0093 option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
0094 option(PYBIND11_SIMPLE_GIL_MANAGEMENT
0095 "Use simpler GIL management logic that does not support disassociation" OFF)
0096 set(PYBIND11_INTERNALS_VERSION
0097 ""
0098 CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
0099
0100 if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
0101 add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
0102 endif()
0103
0104 cmake_dependent_option(
0105 USE_PYTHON_INCLUDE_DIR
0106 "Install pybind11 headers in Python include directory instead of default installation prefix"
0107 OFF "PYBIND11_INSTALL" OFF)
0108
0109 cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
0110 "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
0111
0112 # NB: when adding a header don't forget to also add it to setup.py
0113 set(PYBIND11_HEADERS
0114 include/pybind11/detail/class.h
0115 include/pybind11/detail/common.h
0116 include/pybind11/detail/descr.h
0117 include/pybind11/detail/init.h
0118 include/pybind11/detail/internals.h
0119 include/pybind11/detail/type_caster_base.h
0120 include/pybind11/detail/typeid.h
0121 include/pybind11/attr.h
0122 include/pybind11/buffer_info.h
0123 include/pybind11/cast.h
0124 include/pybind11/chrono.h
0125 include/pybind11/common.h
0126 include/pybind11/complex.h
0127 include/pybind11/options.h
0128 include/pybind11/eigen.h
0129 include/pybind11/eigen/matrix.h
0130 include/pybind11/eigen/tensor.h
0131 include/pybind11/embed.h
0132 include/pybind11/eval.h
0133 include/pybind11/gil.h
0134 include/pybind11/iostream.h
0135 include/pybind11/functional.h
0136 include/pybind11/numpy.h
0137 include/pybind11/operators.h
0138 include/pybind11/pybind11.h
0139 include/pybind11/pytypes.h
0140 include/pybind11/stl.h
0141 include/pybind11/stl_bind.h
0142 include/pybind11/stl/filesystem.h)
0143
0144 # Compare with grep and warn if mismatched
0145 if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
0146 file(
0147 GLOB_RECURSE _pybind11_header_check
0148 LIST_DIRECTORIES false
0149 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
0150 CONFIGURE_DEPENDS "include/pybind11/*.h")
0151 set(_pybind11_here_only ${PYBIND11_HEADERS})
0152 set(_pybind11_disk_only ${_pybind11_header_check})
0153 list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check})
0154 list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS})
0155 if(_pybind11_here_only)
0156 message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only})
0157 endif()
0158 if(_pybind11_disk_only)
0159 message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only})
0160 endif()
0161 endif()
0162
0163 # CMake 3.12 added list(TRANSFORM <list> PREPEND
0164 # But we can't use it yet
0165 string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
0166 "${PYBIND11_HEADERS}")
0167
0168 # Cache variable so this can be used in parent projects
0169 set(pybind11_INCLUDE_DIR
0170 "${CMAKE_CURRENT_LIST_DIR}/include"
0171 CACHE INTERNAL "Directory where pybind11 headers are located")
0172
0173 # Backward compatible variable for add_subdirectory mode
0174 if(NOT PYBIND11_MASTER_PROJECT)
0175 set(PYBIND11_INCLUDE_DIR
0176 "${pybind11_INCLUDE_DIR}"
0177 CACHE INTERNAL "")
0178 endif()
0179
0180 # Note: when creating targets, you cannot use if statements at configure time -
0181 # you need generator expressions, because those will be placed in the target file.
0182 # You can also place ifs *in* the Config.in, but not here.
0183
0184 # This section builds targets, but does *not* touch Python
0185 # Non-IMPORT targets cannot be defined twice
0186 if(NOT TARGET pybind11_headers)
0187 # Build the headers-only target (no Python included):
0188 # (long name used here to keep this from clashing in subdirectory mode)
0189 add_library(pybind11_headers INTERFACE)
0190 add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
0191 add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
0192
0193 target_include_directories(
0194 pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
0195 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
0196
0197 target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
0198 cxx_right_angle_brackets)
0199 if(NOT "${PYBIND11_INTERNALS_VERSION}" STREQUAL "")
0200 target_compile_definitions(
0201 pybind11_headers INTERFACE "PYBIND11_INTERNALS_VERSION=${PYBIND11_INTERNALS_VERSION}")
0202 endif()
0203 else()
0204 # It is invalid to install a target twice, too.
0205 set(PYBIND11_INSTALL OFF)
0206 endif()
0207
0208 include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
0209 # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
0210 # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
0211 include("${CMAKE_CURRENT_SOURCE_DIR}/tools/JoinPaths.cmake")
0212
0213 # Relative directory setting
0214 if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
0215 file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS})
0216 elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
0217 file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
0218 endif()
0219
0220 if(PYBIND11_INSTALL)
0221 install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
0222 set(PYBIND11_CMAKECONFIG_INSTALL_DIR
0223 "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
0224 CACHE STRING "install path for pybind11Config.cmake")
0225
0226 if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
0227 set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
0228 else()
0229 set(pybind11_INCLUDEDIR "\$\{PACKAGE_PREFIX_DIR\}/${CMAKE_INSTALL_INCLUDEDIR}")
0230 endif()
0231
0232 configure_package_config_file(
0233 tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
0234 INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
0235
0236 if(CMAKE_VERSION VERSION_LESS 3.14)
0237 # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
0238 # not depend on architecture specific settings or libraries.
0239 set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
0240 unset(CMAKE_SIZEOF_VOID_P)
0241
0242 write_basic_package_version_file(
0243 ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
0244 VERSION ${PROJECT_VERSION}
0245 COMPATIBILITY AnyNewerVersion)
0246
0247 set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
0248 else()
0249 # CMake 3.14+ natively supports header-only libraries
0250 write_basic_package_version_file(
0251 ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
0252 VERSION ${PROJECT_VERSION}
0253 COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
0254 endif()
0255
0256 install(
0257 FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
0258 ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
0259 tools/FindPythonLibsNew.cmake
0260 tools/pybind11Common.cmake
0261 tools/pybind11Tools.cmake
0262 tools/pybind11NewTools.cmake
0263 DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
0264
0265 if(NOT PYBIND11_EXPORT_NAME)
0266 set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
0267 endif()
0268
0269 install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
0270
0271 install(
0272 EXPORT "${PYBIND11_EXPORT_NAME}"
0273 NAMESPACE "pybind11::"
0274 DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
0275
0276 # pkg-config support
0277 if(NOT prefix_for_pc_file)
0278 set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
0279 endif()
0280 join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
0281 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
0282 "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY)
0283 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
0284 DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
0285
0286 # Uninstall target
0287 if(PYBIND11_MASTER_PROJECT)
0288 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"
0289 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
0290
0291 add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
0292 ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
0293 endif()
0294 endif()
0295
0296 # BUILD_TESTING takes priority, but only if this is the master project
0297 if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING)
0298 if(BUILD_TESTING)
0299 if(_pybind11_nopython)
0300 message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
0301 else()
0302 add_subdirectory(tests)
0303 endif()
0304 endif()
0305 else()
0306 if(PYBIND11_TEST)
0307 if(_pybind11_nopython)
0308 message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
0309 else()
0310 add_subdirectory(tests)
0311 endif()
0312 endif()
0313 endif()
0314
0315 # Better symmetry with find_package(pybind11 CONFIG) mode.
0316 if(NOT PYBIND11_MASTER_PROJECT)
0317 set(pybind11_FOUND
0318 TRUE
0319 CACHE INTERNAL "True if pybind11 and all required components found on the system")
0320 endif()