Skip to content

Commit 209179f

Browse files
committed
Add CMakeLists.txt
1 parent 5e77eab commit 209179f

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

CMakeLists.txt

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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
4+
5+
cmake_minimum_required(VERSION 3.14...3.20)
6+
7+
project(boost_python VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
8+
9+
find_package(Python REQUIRED COMPONENTS Development OPTIONAL_COMPONENTS NumPy)
10+
11+
if(Python_NumPy_FOUND)
12+
message(STATUS "Boost.Python: using Python ${Python_VERSION} with NumPy at ${Python_NumPy_INCLUDE_DIRS}")
13+
else()
14+
message(STATUS "Boost.Python: using Python ${Python_VERSION} without NumPy")
15+
endif()
16+
17+
# boost_pythonXY
18+
19+
set(_pyver ${Python_VERSION_MAJOR}${Python_VERSION_MINOR})
20+
set(_boost_python boost_python${_pyver})
21+
22+
add_library(${_boost_python}
23+
src/dict.cpp
24+
src/errors.cpp
25+
src/exec.cpp
26+
src/import.cpp
27+
src/list.cpp
28+
src/long.cpp
29+
src/module.cpp
30+
src/object_operators.cpp
31+
src/object_protocol.cpp
32+
src/slice.cpp
33+
src/str.cpp
34+
src/tuple.cpp
35+
src/wrapper.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
41+
src/object/enum.cpp
42+
src/object/class.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
52+
)
53+
54+
add_library(Boost::python${_pyver} ALIAS ${_boost_python})
55+
56+
target_include_directories(${_boost_python} PUBLIC include)
57+
58+
target_link_libraries(${_boost_python}
59+
PUBLIC
60+
Boost::align
61+
Boost::bind
62+
Boost::config
63+
Boost::conversion
64+
Boost::core
65+
Boost::detail
66+
Boost::foreach
67+
Boost::function
68+
Boost::iterator
69+
Boost::lexical_cast
70+
Boost::mpl
71+
Boost::numeric_conversion
72+
Boost::preprocessor
73+
Boost::smart_ptr
74+
Boost::static_assert
75+
Boost::tuple
76+
Boost::type_traits
77+
Boost::utility
78+
79+
Python::Module
80+
81+
PRIVATE
82+
Boost::graph
83+
Boost::integer
84+
Boost::property_map
85+
)
86+
87+
target_compile_definitions(${_boost_python}
88+
PUBLIC BOOST_PYTHON_NO_LIB
89+
PRIVATE BOOST_PYTHON_SOURCE
90+
)
91+
92+
if(BUILD_SHARED_LIBS)
93+
target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_DYN_LINK)
94+
else()
95+
target_compile_definitions(${_boost_python} PUBLIC BOOST_PYTHON_STATIC_LINK BOOST_PYTHON_STATIC_LIB)
96+
endif()
97+
98+
# Boost::python alias
99+
100+
add_library(boost_python INTERFACE)
101+
add_library(Boost::python ALIAS boost_python)
102+
target_link_libraries(boost_python INTERFACE Boost::python${_pyver})
103+
104+
# Installation
105+
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)
108+
endif()
109+
110+
if(Python_NumPy_FOUND)
111+
112+
# boost_numpyXY
113+
114+
set(_boost_numpy boost_numpy${_pyver})
115+
116+
add_library(${_boost_numpy}
117+
src/numpy/dtype.cpp
118+
src/numpy/matrix.cpp
119+
src/numpy/ndarray.cpp
120+
src/numpy/numpy.cpp
121+
src/numpy/scalars.cpp
122+
src/numpy/ufunc.cpp
123+
)
124+
125+
add_library(Boost::numpy${_pyver} ALIAS ${_boost_numpy})
126+
127+
target_include_directories(${_boost_numpy} PUBLIC include)
128+
129+
target_link_libraries(${_boost_numpy}
130+
PUBLIC
131+
Boost::config
132+
Boost::core
133+
Boost::detail
134+
Boost::mpl
135+
Boost::python
136+
Boost::smart_ptr
137+
138+
Python::NumPy
139+
)
140+
141+
target_compile_definitions(${_boost_numpy}
142+
PUBLIC BOOST_NUMPY_NO_LIB
143+
PRIVATE BOOST_NUMPY_SOURCE
144+
)
145+
146+
if(BUILD_SHARED_LIBS)
147+
target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_DYN_LINK)
148+
else()
149+
target_compile_definitions(${_boost_numpy} PUBLIC BOOST_NUMPY_STATIC_LINK BOOST_NUMPY_STATIC_LIB)
150+
endif()
151+
152+
# Boost::numpy alias
153+
154+
add_library(boost_numpy INTERFACE)
155+
add_library(Boost::numpy ALIAS boost_numpy)
156+
target_link_libraries(boost_numpy INTERFACE Boost::numpy${_pyver})
157+
158+
# Installation
159+
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})
162+
endif()
163+
164+
endif()
165+
166+
unset(_pyver)
167+
unset(_boost_python)
168+
unset(_boost_numpy)
169+
170+
# Testing
171+
172+
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
173+
174+
add_subdirectory(test)
175+
176+
endif()

0 commit comments

Comments
 (0)