2016-08-12 11:50:00 +00:00
|
|
|
# CMakeLists.txt -- Build system for the pybind11 modules
|
2015-07-05 18:05:44 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
|
|
|
|
#
|
|
|
|
# All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2016-05-22 20:23:18 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2015-07-05 18:05:44 +00:00
|
|
|
|
2016-12-26 10:26:21 +00:00
|
|
|
if (POLICY CMP0048)
|
|
|
|
# cmake warns if loaded from a min-3.0-required parent dir, so silence the warning:
|
|
|
|
cmake_policy(SET CMP0048 NEW)
|
|
|
|
endif()
|
|
|
|
|
2015-10-15 16:13:33 +00:00
|
|
|
project(pybind11)
|
2015-07-05 18:05:44 +00:00
|
|
|
|
2016-05-22 22:12:37 +00:00
|
|
|
# Check if pybind11 is being used directly or via add_subdirectory
|
2016-05-26 20:53:38 +00:00
|
|
|
set(PYBIND11_MASTER_PROJECT OFF)
|
2016-05-22 22:12:37 +00:00
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2016-05-26 20:53:38 +00:00
|
|
|
set(PYBIND11_MASTER_PROJECT ON)
|
2016-05-29 10:35:16 +00:00
|
|
|
endif()
|
2016-05-22 22:12:37 +00:00
|
|
|
|
2016-05-26 20:53:38 +00:00
|
|
|
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
|
2016-05-29 10:35:16 +00:00
|
|
|
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
|
2015-11-24 20:33:18 +00:00
|
|
|
|
2016-05-22 17:48:47 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools")
|
2016-05-28 09:08:16 +00:00
|
|
|
|
2016-12-13 15:59:21 +00:00
|
|
|
include(pybind11Tools)
|
2016-05-28 09:08:16 +00:00
|
|
|
|
2016-05-22 20:23:18 +00:00
|
|
|
# Cache variables so pybind11_add_module can be used in parent projects
|
|
|
|
set(PYBIND11_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include" CACHE INTERNAL "")
|
|
|
|
set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
|
2016-05-25 11:39:32 +00:00
|
|
|
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE INTERNAL "")
|
2016-05-22 20:23:18 +00:00
|
|
|
set(PYTHON_MODULE_PREFIX ${PYTHON_MODULE_PREFIX} CACHE INTERNAL "")
|
|
|
|
set(PYTHON_MODULE_EXTENSION ${PYTHON_MODULE_EXTENSION} CACHE INTERNAL "")
|
2016-05-05 18:33:54 +00:00
|
|
|
|
2017-05-07 16:19:19 +00:00
|
|
|
# NB: when adding a header don't forget to also add it to setup.py
|
2016-09-29 19:30:00 +00:00
|
|
|
set(PYBIND11_HEADERS
|
|
|
|
include/pybind11/attr.h
|
2017-04-07 19:21:53 +00:00
|
|
|
include/pybind11/buffer_info.h
|
2016-09-29 19:30:00 +00:00
|
|
|
include/pybind11/cast.h
|
|
|
|
include/pybind11/chrono.h
|
2017-02-13 17:11:24 +00:00
|
|
|
include/pybind11/class_support.h
|
2016-09-29 19:30:00 +00:00
|
|
|
include/pybind11/common.h
|
|
|
|
include/pybind11/complex.h
|
|
|
|
include/pybind11/descr.h
|
2016-11-15 11:38:05 +00:00
|
|
|
include/pybind11/options.h
|
2016-09-29 19:30:00 +00:00
|
|
|
include/pybind11/eigen.h
|
2017-03-29 22:20:42 +00:00
|
|
|
include/pybind11/embed.h
|
2016-09-29 19:30:00 +00:00
|
|
|
include/pybind11/eval.h
|
|
|
|
include/pybind11/functional.h
|
|
|
|
include/pybind11/numpy.h
|
|
|
|
include/pybind11/operators.h
|
|
|
|
include/pybind11/pybind11.h
|
|
|
|
include/pybind11/pytypes.h
|
|
|
|
include/pybind11/stl.h
|
|
|
|
include/pybind11/stl_bind.h
|
|
|
|
include/pybind11/typeid.h
|
|
|
|
)
|
|
|
|
string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
|
|
|
PYBIND11_HEADERS "${PYBIND11_HEADERS}")
|
|
|
|
|
2016-05-22 22:12:37 +00:00
|
|
|
if (PYBIND11_TEST)
|
2016-08-12 11:50:00 +00:00
|
|
|
add_subdirectory(tests)
|
2016-05-22 20:23:18 +00:00
|
|
|
endif()
|
2015-10-12 21:57:20 +00:00
|
|
|
|
2016-12-13 15:46:41 +00:00
|
|
|
include(GNUInstallDirs)
|
2016-12-13 15:55:38 +00:00
|
|
|
include(CMakePackageConfigHelpers)
|
2016-12-13 15:46:41 +00:00
|
|
|
|
|
|
|
# extract project version from source
|
|
|
|
file(STRINGS "${PYBIND11_INCLUDE_DIR}/pybind11/common.h" pybind11_version_defines
|
|
|
|
REGEX "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) ")
|
|
|
|
foreach(ver ${pybind11_version_defines})
|
|
|
|
if (ver MATCHES "#define PYBIND11_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
|
|
|
|
set(PYBIND11_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${PROJECT_NAME}_VERSION ${PYBIND11_VERSION_MAJOR}.${PYBIND11_VERSION_MINOR}.${PYBIND11_VERSION_PATCH})
|
2016-12-14 00:43:39 +00:00
|
|
|
message(STATUS "pybind11 v${${PROJECT_NAME}_VERSION}")
|
2016-12-13 15:46:41 +00:00
|
|
|
|
2017-02-14 12:16:14 +00:00
|
|
|
option (USE_PYTHON_INCLUDE_DIR "Install pybind11 headers in Python include directory instead of default installation prefix" OFF)
|
|
|
|
if (USE_PYTHON_INCLUDE_DIR)
|
|
|
|
file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS})
|
|
|
|
endif()
|
|
|
|
|
2016-12-13 15:55:38 +00:00
|
|
|
if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) # CMake >= 3.0
|
|
|
|
# Build an interface library target:
|
2017-03-23 12:32:54 +00:00
|
|
|
add_library(pybind11 INTERFACE)
|
|
|
|
add_library(pybind11::pybind11 ALIAS pybind11) # to match exported target
|
|
|
|
target_include_directories(pybind11 INTERFACE $<BUILD_INTERFACE:${PYBIND11_INCLUDE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
|
|
|
target_compile_options(pybind11 INTERFACE $<BUILD_INTERFACE:${PYBIND11_CPP_STANDARD}>)
|
|
|
|
|
2016-12-17 20:38:57 +00:00
|
|
|
add_library(module INTERFACE)
|
2017-03-23 12:32:54 +00:00
|
|
|
add_library(pybind11::module ALIAS module)
|
|
|
|
target_link_libraries(module INTERFACE pybind11::pybind11)
|
2016-12-14 00:43:39 +00:00
|
|
|
if(WIN32 OR CYGWIN)
|
2016-12-17 20:38:57 +00:00
|
|
|
target_link_libraries(module INTERFACE $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
|
2016-12-14 00:43:39 +00:00
|
|
|
elseif(APPLE)
|
2016-12-17 20:38:57 +00:00
|
|
|
target_link_libraries(module INTERFACE "-undefined dynamic_lookup")
|
2016-12-13 15:55:38 +00:00
|
|
|
endif()
|
2016-12-14 00:43:39 +00:00
|
|
|
|
2017-03-23 12:32:54 +00:00
|
|
|
add_library(embed INTERFACE)
|
|
|
|
add_library(pybind11::embed ALIAS embed)
|
|
|
|
target_link_libraries(embed INTERFACE pybind11::pybind11 $<BUILD_INTERFACE:${PYTHON_LIBRARIES}>)
|
2016-12-13 15:55:38 +00:00
|
|
|
endif()
|
|
|
|
|
2015-11-24 20:33:18 +00:00
|
|
|
if (PYBIND11_INSTALL)
|
2016-12-13 15:46:41 +00:00
|
|
|
install(FILES ${PYBIND11_HEADERS}
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pybind11)
|
|
|
|
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
|
|
|
|
set(PYBIND11_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake")
|
|
|
|
|
2016-12-13 15:55:38 +00:00
|
|
|
configure_package_config_file(tools/${PROJECT_NAME}Config.cmake.in
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
|
|
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
|
2017-03-24 22:09:38 +00:00
|
|
|
# Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does
|
|
|
|
# not depend on architecture specific settings or libraries.
|
|
|
|
set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
|
|
|
unset(CMAKE_SIZEOF_VOID_P)
|
2016-12-13 15:55:38 +00:00
|
|
|
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
|
|
|
VERSION ${${PROJECT_NAME}_VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
2017-03-24 22:09:38 +00:00
|
|
|
set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P})
|
2016-12-13 15:55:38 +00:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
|
|
|
|
tools/FindPythonLibsNew.cmake
|
|
|
|
tools/pybind11Tools.cmake
|
|
|
|
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
|
|
|
|
|
|
|
|
if(NOT (CMAKE_VERSION VERSION_LESS 3.0))
|
2017-03-23 12:32:54 +00:00
|
|
|
install(TARGETS pybind11 module embed
|
2016-12-13 15:55:38 +00:00
|
|
|
EXPORT "${PROJECT_NAME}Targets")
|
|
|
|
install(EXPORT "${PROJECT_NAME}Targets"
|
|
|
|
NAMESPACE "${PROJECT_NAME}::"
|
|
|
|
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})
|
|
|
|
endif()
|
2015-11-24 20:20:56 +00:00
|
|
|
endif()
|