Skip to content

Commit 94fec2c

Browse files
committed
Update cmake configuration to use venv or conda env for build
1 parent 2530152 commit 94fec2c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# Build
3535
/examples/build/*
36-
build/*
36+
*build*
3737

3838
# vim temp files
3939
*.sw*

CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
2+
3+
# Set compiler to g++-11)
4+
message(STATUS "NOTE: ensure you're using a compiler version that matches the precompiled Python libraries! For this build g++-11 is recommended.")
5+
6+
set(CMAKE_CXX_COMPILER "g++-11")
7+
set(CMAKE_C_COMPILE "gcc-11")
8+
29
project(matplotlib_cpp LANGUAGES CXX)
310

411
include(GNUInstallDirs)
512
set(PACKAGE_NAME matplotlib_cpp)
613
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/${PACKAGE_NAME}/cmake)
714

15+
# Set C++ standard to C++11
16+
set(CMAKE_CXX_STANDARD 11)
17+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
19+
# Handle virtualenv or conda envs
20+
if(DEFINED ENV{CONDA_PREFIX})
21+
# Let CMake know to look under the conda env directory
22+
set(Python3_ROOT_DIR "$ENV{CONDA_PREFIX}")
23+
elseif(DEFINED ENV{VIRTUAL_ENV})
24+
set(Python3_ROOT_DIR "$ENV{VIRTUAL_ENV}")
25+
else()
26+
message(WARNING "Neither CONDA_PREFIX nor VIRTUAL_ENV is defined. Python3_ROOT_DIR will use system environment! Make sure this is intentional.")
27+
endif()
828

929
# Library target
1030
add_library(matplotlib_cpp INTERFACE)
@@ -18,12 +38,16 @@ target_compile_features(matplotlib_cpp INTERFACE
1838
)
1939
# TODO: Use `Development.Embed` component when requiring cmake >= 3.18
2040
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
41+
# Print location of python3
42+
message(STATUS "Python3 found at: ${Python3_EXECUTABLE}")
43+
2144
target_link_libraries(matplotlib_cpp INTERFACE
2245
Python3::Python
2346
Python3::Module
2447
)
2548
find_package(Python3 COMPONENTS NumPy)
2649
if(Python3_NumPy_FOUND)
50+
message(STATUS "Found NumPy: ${Python3_NumPy_INCLUDE_DIRS}")
2751
target_link_libraries(matplotlib_cpp INTERFACE
2852
Python3::NumPy
2953
)
@@ -35,6 +59,10 @@ install(
3559
EXPORT install_targets
3660
)
3761

62+
# Print C++ build options
63+
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER_ID}")
64+
message(STATUS "C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
65+
message(STATUS "C++ compiler flags: ${CMAKE_CXX_FLAGS}")
3866

3967
# Examples
4068
add_executable(minimal examples/minimal.cpp)

0 commit comments

Comments
 (0)