github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/pybind11/CMakeLists.txt (about)

     1  # CMakeLists.txt -- Build system for the pybind11 modules
     2  #
     3  # Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
     4  #
     5  # All rights reserved. Use of this source code is governed by a
     6  # BSD-style license that can be found in the LICENSE file.
     7  
     8  cmake_minimum_required(VERSION 3.4)
     9  
    10  # The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with
    11  # some versions of VS that have a patched CMake 3.11. This forces us to emulate
    12  # the behavior using the following workaround:
    13  if(${CMAKE_VERSION} VERSION_LESS 3.22)
    14    cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
    15  else()
    16    cmake_policy(VERSION 3.22)
    17  endif()
    18  
    19  # Avoid infinite recursion if tests include this as a subdirectory
    20  if(DEFINED PYBIND11_MASTER_PROJECT)
    21    return()
    22  endif()
    23  
    24  # Extract project version from source
    25  file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h"
    26       pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
    27  
    28  foreach(ver ${pybind11_version_defines})
    29    if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]])
    30      set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}")
    31    endif()
    32  endforeach()
    33  
    34  if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]])
    35    set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}")
    36  endif()
    37  string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}")
    38  
    39  project(
    40    pybind11
    41    LANGUAGES CXX
    42    VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}")
    43  
    44  # Standard includes
    45  include(GNUInstallDirs)
    46  include(CMakePackageConfigHelpers)
    47  include(CMakeDependentOption)
    48  
    49  if(NOT pybind11_FIND_QUIETLY)
    50    message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}")
    51  endif()
    52  
    53  # Check if pybind11 is being used directly or via add_subdirectory
    54  if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
    55    ### Warn if not an out-of-source builds
    56    if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
    57      set(lines
    58          "You are building in-place. If that is not what you intended to "
    59          "do, you can clean the source directory with:\n"
    60          "rm -r CMakeCache.txt CMakeFiles/ cmake_uninstall.cmake pybind11Config.cmake "
    61          "pybind11ConfigVersion.cmake tests/CMakeFiles/\n")
    62      message(AUTHOR_WARNING ${lines})
    63    endif()
    64  
    65    set(PYBIND11_MASTER_PROJECT ON)
    66  
    67    if(OSX AND CMAKE_VERSION VERSION_LESS 3.7)
    68      # Bug in macOS CMake < 3.7 is unable to download catch
    69      message(WARNING "CMAKE 3.7+ needed on macOS to download catch, and newer HIGHLY recommended")
    70    elseif(WINDOWS AND CMAKE_VERSION VERSION_LESS 3.8)
    71      # Only tested with 3.8+ in CI.
    72      message(WARNING "CMAKE 3.8+ tested on Windows, previous versions untested")
    73    endif()
    74  
    75    message(STATUS "CMake ${CMAKE_VERSION}")
    76  
    77    if(CMAKE_CXX_STANDARD)
    78      set(CMAKE_CXX_EXTENSIONS OFF)
    79      set(CMAKE_CXX_STANDARD_REQUIRED ON)
    80    endif()
    81  
    82    set(pybind11_system "")
    83  
    84    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
    85  else()
    86    set(PYBIND11_MASTER_PROJECT OFF)
    87    set(pybind11_system SYSTEM)
    88  endif()
    89  
    90  # Options
    91  option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
    92  option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
    93  option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
    94  option(PYBIND11_SIMPLE_GIL_MANAGEMENT
    95         "Use simpler GIL management logic that does not support disassociation" OFF)
    96  set(PYBIND11_INTERNALS_VERSION
    97      ""
    98      CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
    99  
   100  if(PYBIND11_SIMPLE_GIL_MANAGEMENT)
   101    add_compile_definitions(PYBIND11_SIMPLE_GIL_MANAGEMENT)
   102  endif()
   103  
   104  cmake_dependent_option(
   105    USE_PYTHON_INCLUDE_DIR
   106    "Install pybind11 headers in Python include directory instead of default installation prefix"
   107    OFF "PYBIND11_INSTALL" OFF)
   108  
   109  cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF
   110                         "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF)
   111  
   112  # NB: when adding a header don't forget to also add it to setup.py
   113  set(PYBIND11_HEADERS
   114      include/pybind11/detail/class.h
   115      include/pybind11/detail/common.h
   116      include/pybind11/detail/descr.h
   117      include/pybind11/detail/init.h
   118      include/pybind11/detail/internals.h
   119      include/pybind11/detail/type_caster_base.h
   120      include/pybind11/detail/typeid.h
   121      include/pybind11/attr.h
   122      include/pybind11/buffer_info.h
   123      include/pybind11/cast.h
   124      include/pybind11/chrono.h
   125      include/pybind11/common.h
   126      include/pybind11/complex.h
   127      include/pybind11/options.h
   128      include/pybind11/eigen.h
   129      include/pybind11/eigen/matrix.h
   130      include/pybind11/eigen/tensor.h
   131      include/pybind11/embed.h
   132      include/pybind11/eval.h
   133      include/pybind11/gil.h
   134      include/pybind11/iostream.h
   135      include/pybind11/functional.h
   136      include/pybind11/numpy.h
   137      include/pybind11/operators.h
   138      include/pybind11/pybind11.h
   139      include/pybind11/pytypes.h
   140      include/pybind11/stl.h
   141      include/pybind11/stl_bind.h
   142      include/pybind11/stl/filesystem.h)
   143  
   144  # Compare with grep and warn if mismatched
   145  if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
   146    file(
   147      GLOB_RECURSE _pybind11_header_check
   148      LIST_DIRECTORIES false
   149      RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
   150      CONFIGURE_DEPENDS "include/pybind11/*.h")
   151    set(_pybind11_here_only ${PYBIND11_HEADERS})
   152    set(_pybind11_disk_only ${_pybind11_header_check})
   153    list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check})
   154    list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS})
   155    if(_pybind11_here_only)
   156      message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only})
   157    endif()
   158    if(_pybind11_disk_only)
   159      message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only})
   160    endif()
   161  endif()
   162  
   163  # CMake 3.12 added list(TRANSFORM <list> PREPEND
   164  # But we can't use it yet
   165  string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS
   166                 "${PYBIND11_HEADERS}")
   167  
   168  # Cache variable so this can be used in parent projects
   169  set(pybind11_INCLUDE_DIR
   170      "${CMAKE_CURRENT_LIST_DIR}/include"
   171      CACHE INTERNAL "Directory where pybind11 headers are located")
   172  
   173  # Backward compatible variable for add_subdirectory mode
   174  if(NOT PYBIND11_MASTER_PROJECT)
   175    set(PYBIND11_INCLUDE_DIR
   176        "${pybind11_INCLUDE_DIR}"
   177        CACHE INTERNAL "")
   178  endif()
   179  
   180  # Note: when creating targets, you cannot use if statements at configure time -
   181  # you need generator expressions, because those will be placed in the target file.
   182  # You can also place ifs *in* the Config.in, but not here.
   183  
   184  # This section builds targets, but does *not* touch Python
   185  # Non-IMPORT targets cannot be defined twice
   186  if(NOT TARGET pybind11_headers)
   187    # Build the headers-only target (no Python included):
   188    # (long name used here to keep this from clashing in subdirectory mode)
   189    add_library(pybind11_headers INTERFACE)
   190    add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target
   191    add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember
   192  
   193    target_include_directories(
   194      pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}>
   195                                                    $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
   196  
   197    target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals
   198                                                       cxx_right_angle_brackets)
   199    if(NOT "${PYBIND11_INTERNALS_VERSION}" STREQUAL "")
   200      target_compile_definitions(
   201        pybind11_headers INTERFACE "PYBIND11_INTERNALS_VERSION=${PYBIND11_INTERNALS_VERSION}")
   202    endif()
   203  else()
   204    # It is invalid to install a target twice, too.
   205    set(PYBIND11_INSTALL OFF)
   206  endif()
   207  
   208  include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake")
   209  # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
   210  # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
   211  include("${CMAKE_CURRENT_SOURCE_DIR}/tools/JoinPaths.cmake")
   212  
   213  # Relative directory setting
   214  if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
   215    file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS})
   216  elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR)
   217    file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
   218  endif()
   219  
   220  if(PYBIND11_INSTALL)
   221    install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
   222    set(PYBIND11_CMAKECONFIG_INSTALL_DIR
   223        "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
   224        CACHE STRING "install path for pybind11Config.cmake")
   225  
   226    if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
   227      set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
   228    else()
   229      set(pybind11_INCLUDEDIR "\$\{PACKAGE_PREFIX_DIR\}/${CMAKE_INSTALL_INCLUDEDIR}")
   230    endif()
   231  
   232    configure_package_config_file(
   233      tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
   234      INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
   235  
   236    if(CMAKE_VERSION VERSION_LESS 3.14)
   237      # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
   238      # not depend on architecture specific settings or libraries.
   239      set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
   240      unset(CMAKE_SIZEOF_VOID_P)
   241  
   242      write_basic_package_version_file(
   243        ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
   244        VERSION ${PROJECT_VERSION}
   245        COMPATIBILITY AnyNewerVersion)
   246  
   247      set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
   248    else()
   249      # CMake 3.14+ natively supports header-only libraries
   250      write_basic_package_version_file(
   251        ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
   252        VERSION ${PROJECT_VERSION}
   253        COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT)
   254    endif()
   255  
   256    install(
   257      FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
   258            ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
   259            tools/FindPythonLibsNew.cmake
   260            tools/pybind11Common.cmake
   261            tools/pybind11Tools.cmake
   262            tools/pybind11NewTools.cmake
   263      DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
   264  
   265    if(NOT PYBIND11_EXPORT_NAME)
   266      set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets")
   267    endif()
   268  
   269    install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}")
   270  
   271    install(
   272      EXPORT "${PYBIND11_EXPORT_NAME}"
   273      NAMESPACE "pybind11::"
   274      DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
   275  
   276    # pkg-config support
   277    if(NOT prefix_for_pc_file)
   278      set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
   279    endif()
   280    join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
   281    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
   282                   "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY)
   283    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
   284            DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
   285  
   286    # Uninstall target
   287    if(PYBIND11_MASTER_PROJECT)
   288      configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"
   289                     "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
   290  
   291      add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
   292                                          ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
   293    endif()
   294  endif()
   295  
   296  # BUILD_TESTING takes priority, but only if this is the master project
   297  if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING)
   298    if(BUILD_TESTING)
   299      if(_pybind11_nopython)
   300        message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
   301      else()
   302        add_subdirectory(tests)
   303      endif()
   304    endif()
   305  else()
   306    if(PYBIND11_TEST)
   307      if(_pybind11_nopython)
   308        message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode")
   309      else()
   310        add_subdirectory(tests)
   311      endif()
   312    endif()
   313  endif()
   314  
   315  # Better symmetry with find_package(pybind11 CONFIG) mode.
   316  if(NOT PYBIND11_MASTER_PROJECT)
   317    set(pybind11_FOUND
   318        TRUE
   319        CACHE INTERNAL "True if pybind11 and all required components found on the system")
   320  endif()