Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 1 | # CMakeLists.txt -- Build system for the pybind11 modules |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 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 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 3.4) |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 9 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 10 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 11 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate |
| 12 | # the behavior using the following workaround: |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 13 | if(${CMAKE_VERSION} VERSION_LESS 3.18) |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 14 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) |
Florian Apolloner | 29b99a1 | 2017-08-30 14:17:54 +0200 | [diff] [blame] | 15 | else() |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 16 | cmake_policy(VERSION 3.18) |
Florian Apolloner | 29b99a1 | 2017-08-30 14:17:54 +0200 | [diff] [blame] | 17 | endif() |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 18 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 19 | # Extract project version from source |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 20 | file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/pybind11/detail/common.h" |
| 21 | pybind11_version_defines REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 22 | |
| 23 | foreach(ver ${pybind11_version_defines}) |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 24 | if(ver MATCHES [[#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$]]) |
| 25 | set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}") |
| 26 | endif() |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 27 | endforeach() |
| 28 | |
Henry Schreiner | fd61f50 | 2020-09-16 17:13:41 -0400 | [diff] [blame] | 29 | if(PYBIND11_VERSION_PATCH MATCHES [[\.([a-zA-Z0-9]+)$]]) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 30 | set(pybind11_VERSION_TYPE "${CMAKE_MATCH_1}") |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 31 | endif() |
Henry Schreiner | fd61f50 | 2020-09-16 17:13:41 -0400 | [diff] [blame] | 32 | string(REGEX MATCH "^[0-9]+" PYBIND11_VERSION_PATCH "${PYBIND11_VERSION_PATCH}") |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 33 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 34 | project( |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 35 | pybind11 |
| 36 | LANGUAGES CXX |
| 37 | VERSION "${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH}") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 38 | |
| 39 | # Standard includes |
| 40 | include(GNUInstallDirs) |
| 41 | include(CMakePackageConfigHelpers) |
| 42 | include(CMakeDependentOption) |
| 43 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 44 | if(NOT pybind11_FIND_QUIETLY) |
| 45 | message(STATUS "pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}") |
| 46 | endif() |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 47 | |
Henry Schreiner | 130c995 | 2021-01-19 18:49:03 -0500 | [diff] [blame] | 48 | # Avoid infinite recursion if tests include this as a subdirectory |
| 49 | if(DEFINED PYBIND11_MASTER_PROJECT) |
| 50 | set(PYBIND11_TEST OFF) |
| 51 | endif() |
| 52 | |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 53 | # Check if pybind11 is being used directly or via add_subdirectory |
Henry Schreiner | 130c995 | 2021-01-19 18:49:03 -0500 | [diff] [blame] | 54 | if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR AND NOT DEFINED PYBIND11_MASTER_PROJECT) |
Henry Schreiner | 04fdc44 | 2020-08-19 13:11:57 -0400 | [diff] [blame] | 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 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 65 | set(PYBIND11_MASTER_PROJECT ON) |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 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 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 75 | message(STATUS "CMake ${CMAKE_VERSION}") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 76 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 77 | if(CMAKE_CXX_STANDARD) |
| 78 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 79 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 80 | endif() |
Henry Schreiner | eb83fee | 2021-01-19 18:48:22 -0500 | [diff] [blame] | 81 | |
| 82 | set(pybind11_system "") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 83 | else() |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 84 | set(PYBIND11_MASTER_PROJECT OFF) |
| 85 | set(pybind11_system SYSTEM) |
Wenzel Jakob | 67a6392 | 2016-05-29 12:35:16 +0200 | [diff] [blame] | 86 | endif() |
Dean Moldovan | 8c6b0b8 | 2016-05-23 00:12:37 +0200 | [diff] [blame] | 87 | |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 88 | # Options |
Dean Moldovan | 49720f0 | 2016-05-26 22:53:38 +0200 | [diff] [blame] | 89 | option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT}) |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 90 | option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT}) |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 91 | option(PYBIND11_NOPYTHON "Disable search for Python" OFF) |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 92 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 93 | cmake_dependent_option( |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 94 | USE_PYTHON_INCLUDE_DIR |
| 95 | "Install pybind11 headers in Python include directory instead of default installation prefix" |
| 96 | OFF "PYBIND11_INSTALL" OFF) |
Wenzel Jakob | 3350b5e | 2015-11-24 21:33:18 +0100 | [diff] [blame] | 97 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 98 | cmake_dependent_option(PYBIND11_FINDPYTHON "Force new FindPython" OFF |
| 99 | "NOT CMAKE_VERSION VERSION_LESS 3.12" OFF) |
| 100 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 101 | # NB: when adding a header don't forget to also add it to setup.py |
| 102 | set(PYBIND11_HEADERS |
| 103 | include/pybind11/detail/class.h |
| 104 | include/pybind11/detail/common.h |
| 105 | include/pybind11/detail/descr.h |
| 106 | include/pybind11/detail/init.h |
| 107 | include/pybind11/detail/internals.h |
| 108 | include/pybind11/detail/typeid.h |
| 109 | include/pybind11/attr.h |
| 110 | include/pybind11/buffer_info.h |
| 111 | include/pybind11/cast.h |
| 112 | include/pybind11/chrono.h |
| 113 | include/pybind11/common.h |
| 114 | include/pybind11/complex.h |
| 115 | include/pybind11/options.h |
| 116 | include/pybind11/eigen.h |
| 117 | include/pybind11/embed.h |
| 118 | include/pybind11/eval.h |
Henry Schreiner | 1caf1d0 | 2020-08-01 15:24:30 -0400 | [diff] [blame] | 119 | include/pybind11/iostream.h |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 120 | include/pybind11/functional.h |
| 121 | include/pybind11/numpy.h |
| 122 | include/pybind11/operators.h |
| 123 | include/pybind11/pybind11.h |
| 124 | include/pybind11/pytypes.h |
| 125 | include/pybind11/stl.h |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 126 | include/pybind11/stl_bind.h) |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 127 | |
Henry Schreiner | 1caf1d0 | 2020-08-01 15:24:30 -0400 | [diff] [blame] | 128 | # Compare with grep and warn if mismatched |
| 129 | if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12) |
| 130 | file( |
| 131 | GLOB_RECURSE _pybind11_header_check |
| 132 | LIST_DIRECTORIES false |
| 133 | RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" |
| 134 | CONFIGURE_DEPENDS "include/pybind11/*.h") |
| 135 | set(_pybind11_here_only ${PYBIND11_HEADERS}) |
| 136 | set(_pybind11_disk_only ${_pybind11_header_check}) |
| 137 | list(REMOVE_ITEM _pybind11_here_only ${_pybind11_header_check}) |
| 138 | list(REMOVE_ITEM _pybind11_disk_only ${PYBIND11_HEADERS}) |
| 139 | if(_pybind11_here_only) |
| 140 | message(AUTHOR_WARNING "PYBIND11_HEADERS has extra files:" ${_pybind11_here_only}) |
| 141 | endif() |
| 142 | if(_pybind11_disk_only) |
| 143 | message(AUTHOR_WARNING "PYBIND11_HEADERS is missing files:" ${_pybind11_disk_only}) |
| 144 | endif() |
| 145 | endif() |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 146 | |
Henry Schreiner | 1caf1d0 | 2020-08-01 15:24:30 -0400 | [diff] [blame] | 147 | # CMake 3.12 added list(TRANSFORM <list> PREPEND |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 148 | # But we can't use it yet |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 149 | string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS |
| 150 | "${PYBIND11_HEADERS}") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 151 | |
Henry Schreiner | b8dc60e | 2020-11-02 20:45:54 -0500 | [diff] [blame] | 152 | # Cache variable so this can be used in parent projects |
| 153 | set(pybind11_INCLUDE_DIR |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 154 | "${CMAKE_CURRENT_LIST_DIR}/include" |
Henry Schreiner | b8dc60e | 2020-11-02 20:45:54 -0500 | [diff] [blame] | 155 | CACHE INTERNAL "Directory where pybind11 headers are located") |
| 156 | |
| 157 | # Backward compatible variable for add_subdirectory mode |
| 158 | if(NOT PYBIND11_MASTER_PROJECT) |
| 159 | set(PYBIND11_INCLUDE_DIR |
| 160 | "${pybind11_INCLUDE_DIR}" |
| 161 | CACHE INTERNAL "") |
| 162 | endif() |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 163 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 164 | # Note: when creating targets, you cannot use if statements at configure time - |
| 165 | # you need generator expressions, because those will be placed in the target file. |
Henry Schreiner | 1651c32 | 2020-07-30 16:04:26 -0400 | [diff] [blame] | 166 | # You can also place ifs *in* the Config.in, but not here. |
Dean Moldovan | 7f5c85c | 2017-03-23 13:32:54 +0100 | [diff] [blame] | 167 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 168 | # This section builds targets, but does *not* touch Python |
Henry Schreiner | 130c995 | 2021-01-19 18:49:03 -0500 | [diff] [blame] | 169 | # Non-IMPORT targets cannot be defined twice |
| 170 | if(NOT TARGET pybind11_headers) |
| 171 | # Build the headers-only target (no Python included): |
| 172 | # (long name used here to keep this from clashing in subdirectory mode) |
| 173 | add_library(pybind11_headers INTERFACE) |
| 174 | add_library(pybind11::pybind11_headers ALIAS pybind11_headers) # to match exported target |
| 175 | add_library(pybind11::headers ALIAS pybind11_headers) # easier to use/remember |
Dean Moldovan | b0f3885 | 2016-12-14 01:43:39 +0100 | [diff] [blame] | 176 | |
Henry Schreiner | 130c995 | 2021-01-19 18:49:03 -0500 | [diff] [blame] | 177 | target_include_directories( |
| 178 | pybind11_headers ${pybind11_system} INTERFACE $<BUILD_INTERFACE:${pybind11_INCLUDE_DIR}> |
| 179 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 180 | |
| 181 | target_compile_features(pybind11_headers INTERFACE cxx_inheriting_constructors cxx_user_literals |
| 182 | cxx_right_angle_brackets) |
| 183 | else() |
| 184 | # It is invalid to install a target twice, too. |
| 185 | set(PYBIND11_INSTALL OFF) |
| 186 | endif() |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 187 | |
| 188 | include("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11Common.cmake") |
| 189 | |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 190 | # Relative directory setting |
| 191 | if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS) |
| 192 | file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS}) |
| 193 | elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR) |
| 194 | file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS}) |
| 195 | endif() |
| 196 | |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 197 | if(PYBIND11_INSTALL) |
Henry Schreiner | b8dc60e | 2020-11-02 20:45:54 -0500 | [diff] [blame] | 198 | install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 199 | set(PYBIND11_CMAKECONFIG_INSTALL_DIR |
Henry Schreiner | edda89b | 2020-10-13 13:08:54 -0400 | [diff] [blame] | 200 | "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 201 | CACHE STRING "install path for pybind11Config.cmake") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 202 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 203 | configure_package_config_file( |
| 204 | tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 205 | INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 206 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 207 | if(CMAKE_VERSION VERSION_LESS 3.14) |
| 208 | # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does |
| 209 | # not depend on architecture specific settings or libraries. |
| 210 | set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) |
| 211 | unset(CMAKE_SIZEOF_VOID_P) |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 212 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 213 | write_basic_package_version_file( |
| 214 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
| 215 | VERSION ${PROJECT_VERSION} |
| 216 | COMPATIBILITY AnyNewerVersion) |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 217 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 218 | set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P}) |
| 219 | else() |
| 220 | # CMake 3.14+ natively supports header-only libraries |
| 221 | write_basic_package_version_file( |
| 222 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
| 223 | VERSION ${PROJECT_VERSION} |
| 224 | COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT) |
| 225 | endif() |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 226 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 227 | install( |
| 228 | FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake |
| 229 | ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 230 | tools/FindPythonLibsNew.cmake |
| 231 | tools/pybind11Common.cmake |
| 232 | tools/pybind11Tools.cmake |
| 233 | tools/pybind11NewTools.cmake |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 234 | DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 235 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 236 | if(NOT PYBIND11_EXPORT_NAME) |
| 237 | set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets") |
| 238 | endif() |
Dean Moldovan | 3dde6dd | 2017-08-07 22:47:19 +0200 | [diff] [blame] | 239 | |
Henry Schreiner | c58f7b7 | 2020-08-22 09:06:01 -0400 | [diff] [blame] | 240 | install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}") |
Henry Schreiner | 6ec1775 | 2020-07-28 00:43:12 -0400 | [diff] [blame] | 241 | |
Henry Schreiner | 94db5c5 | 2020-07-30 16:20:10 -0400 | [diff] [blame] | 242 | install( |
| 243 | EXPORT "${PYBIND11_EXPORT_NAME}" |
| 244 | NAMESPACE "pybind11::" |
| 245 | DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) |
acxz | 6f6e939 | 2020-07-30 21:16:50 -0400 | [diff] [blame] | 246 | |
Henry Schreiner | b804724 | 2020-07-31 04:16:40 -0400 | [diff] [blame] | 247 | # Uninstall target |
| 248 | if(PYBIND11_MASTER_PROJECT) |
| 249 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in" |
| 250 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) |
acxz | 6f6e939 | 2020-07-30 21:16:50 -0400 | [diff] [blame] | 251 | |
Henry Schreiner | b804724 | 2020-07-31 04:16:40 -0400 | [diff] [blame] | 252 | add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P |
| 253 | ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) |
| 254 | endif() |
acxz | 6f6e939 | 2020-07-30 21:16:50 -0400 | [diff] [blame] | 255 | endif() |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 256 | |
Paul Fultz II | 69821d9 | 2020-08-18 07:34:18 -0500 | [diff] [blame] | 257 | # BUILD_TESTING takes priority, but only if this is the master project |
| 258 | if(PYBIND11_MASTER_PROJECT AND DEFINED BUILD_TESTING) |
| 259 | if(BUILD_TESTING) |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 260 | if(_pybind11_nopython) |
| 261 | message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode") |
| 262 | else() |
| 263 | add_subdirectory(tests) |
| 264 | endif() |
Paul Fultz II | 69821d9 | 2020-08-18 07:34:18 -0500 | [diff] [blame] | 265 | endif() |
| 266 | else() |
| 267 | if(PYBIND11_TEST) |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 268 | if(_pybind11_nopython) |
| 269 | message(FATAL_ERROR "Cannot activate tests in NOPYTHON mode") |
| 270 | else() |
| 271 | add_subdirectory(tests) |
| 272 | endif() |
Paul Fultz II | 69821d9 | 2020-08-18 07:34:18 -0500 | [diff] [blame] | 273 | endif() |
Henry Schreiner | df11597 | 2020-07-31 22:45:19 -0400 | [diff] [blame] | 274 | endif() |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 275 | |
| 276 | # Better symmetry with find_package(pybind11 CONFIG) mode. |
| 277 | if(NOT PYBIND11_MASTER_PROJECT) |
| 278 | set(pybind11_FOUND |
| 279 | TRUE |
Henry Schreiner | b8dc60e | 2020-11-02 20:45:54 -0500 | [diff] [blame] | 280 | CACHE INTERNAL "True if pybind11 and all required components found on the system") |
Henry Schreiner | 1729aae | 2020-08-19 12:26:26 -0400 | [diff] [blame] | 281 | endif() |