Skip to content

Commit 06550f8

Browse files
authored
Update CMakeLists.txt to support Python2 easily
1 parent ef0383f commit 06550f8

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

CMakeLists.txt

+28-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(matplotlib_cpp LANGUAGES CXX)
44
include(GNUInstallDirs)
55
set(PACKAGE_NAME matplotlib_cpp)
66
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake)
7-
7+
set(USING_PYTHON3 True)
88

99
# Library target
1010
add_library(matplotlib_cpp INTERFACE)
@@ -17,19 +17,37 @@ target_compile_features(matplotlib_cpp INTERFACE
1717
cxx_std_11
1818
)
1919
# TODO: Use `Development.Embed` component when requiring cmake >= 3.18
20-
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
21-
target_link_libraries(matplotlib_cpp INTERFACE
22-
Python3::Python
23-
Python3::Module
24-
)
25-
find_package(Python3 COMPONENTS NumPy)
26-
if(Python3_NumPy_FOUND)
20+
if(USING_PYTHON3)
21+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
2722
target_link_libraries(matplotlib_cpp INTERFACE
28-
Python3::NumPy
23+
Python3::Python
24+
Python3::Module
2925
)
26+
find_package(Python3 COMPONENTS NumPy)
27+
if(Python3_NumPy_FOUND)
28+
target_link_libraries(matplotlib_cpp INTERFACE
29+
Python3::NumPy
30+
)
31+
else()
32+
target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
33+
endif()
3034
else()
31-
target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
35+
find_package(Python2 COMPONENTS Interpreter Development REQUIRED)
36+
target_link_libraries(matplotlib_cpp INTERFACE
37+
Python2::Python
38+
Python2::Module
39+
)
40+
find_package(Python2 COMPONENTS NumPy)
41+
if(Python2_NumPy_FOUND)
42+
target_link_libraries(matplotlib_cpp INTERFACE
43+
Python2::NumPy
44+
)
45+
else()
46+
target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
47+
endif()
3248
endif()
49+
50+
3351
install(
3452
TARGETS matplotlib_cpp
3553
EXPORT install_targets

0 commit comments

Comments
 (0)