1 # Copyright 2020, 2021 Peter Dimov
2 # Distributed under the Boost Software License, Version 1.0.
3 # https://www.boost.org/LICENSE_1_0.txt
5 cmake_minimum_required(VERSION 3.14...3.20)
7 project(boost_python VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
9 find_package(Python REQUIRED COMPONENTS Development OPTIONAL_COMPONENTS NumPy)
11 if(Python_NumPy_FOUND)
12 message(STATUS "Boost.Python: using Python ${Python_VERSION} with NumPy at ${Python_NumPy_INCLUDE_DIRS}")
14 message(STATUS "Boost.Python: using Python ${Python_VERSION} without NumPy")
19 set(_pyver ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
20 set(_boost_python boost_python${_pyver})
22 add_library(${_boost_python}
30 src/object_operators.cpp
31 src/object_protocol.cpp
36 src/converter/from_python.cpp
37 src/converter/registry.cpp
38 src/converter/type_id.cpp
39 src/converter/builtin_converters.cpp
40 src/converter/arg_to_python_base.cpp
43 src/object/function.cpp
44 src/object/inheritance.cpp
45 src/object/life_support.cpp
46 src/object/pickle_support.cpp
47 src/object/iterator.cpp
48 src/object/stl_iterator.cpp
49 src/object_protocol.cpp
50 src/object_operators.cpp
51 src/object/function_doc_signature.cpp
54 add_library(Boost::python${_pyver} ALIAS ${_boost_python})
56 target_include_directories(${_boost_python} PUBLIC include)
58 target_link_libraries(${_boost_python}
71 Boost::numeric_conversion
87 target_compile_definitions(${_boost_python}
88 PUBLIC BOOST_PYTHON_NO_LIB
89 PRIVATE BOOST_PYTHON_SOURCE
93 target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_DYN_LINK)
95 target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_STATIC_LINK BOOST_PYTHON_STATIC_LIB)
100 add_library(boost_python INTERFACE)
101 add_library(Boost::python ALIAS boost_python)
102 target_link_libraries(boost_python INTERFACE Boost::python${_pyver})
106 if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
107 boost_install(TARGETS ${_boost_python} boost_python VERSION ${BOOST_SUPERPROJECT_VERSION} HEADER_DIRECTORY include)
110 if(Python_NumPy_FOUND)
114 set(_boost_numpy boost_numpy${_pyver})
116 add_library(${_boost_numpy}
119 src/numpy/ndarray.cpp
121 src/numpy/scalars.cpp
125 add_library(Boost::numpy${_pyver} ALIAS ${_boost_numpy})
127 target_include_directories(${_boost_numpy} PUBLIC include)
129 target_link_libraries(${_boost_numpy}
141 target_compile_definitions(${_boost_numpy}
142 PUBLIC BOOST_NUMPY_NO_LIB
143 PRIVATE BOOST_NUMPY_SOURCE
146 if(BUILD_SHARED_LIBS)
147 target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_DYN_LINK)
149 target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_STATIC_LINK BOOST_NUMPY_STATIC_LIB)
154 add_library(boost_numpy INTERFACE)
155 add_library(Boost::numpy ALIAS boost_numpy)
156 target_link_libraries(boost_numpy INTERFACE Boost::numpy${_pyver})
160 if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13)
161 boost_install(TARGETS ${_boost_numpy} boost_numpy VERSION ${BOOST_SUPERPROJECT_VERSION})
172 if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
174 add_subdirectory(test)