8000 Add build via CMakeLists · Cryoris/matplotlib-cpp@b959de0 · GitHub
[go: up one dir, main page]

Skip to content

Commit b959de0

Browse files
committed
Add build via CMakeLists
1 parent 208807d commit b959de0

File tree

5 files changed

+183
-4
lines changed

5 files changed

+183
-4
lines changed

.gitignore

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

3434
# Build
3535
/examples/build/*
36+
/build/*
3637

3738
# Images
3839
*.png

CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
project(MatplotlibC++)
2+
cmake_minimum_required(VERSION 2.8)
3+
4+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
5+
6+
find_package(Eigen3)
7+
8+
if (${EIGEN3_FOUND})
9+
include_directories(${EIGEN3_INCLUDE_DIR})
10+
else()
11+
message(STATUS "Eigen3 not found")
12+
endif()
13+
14+
find_package(Python3 COMPONENTS Interpreter Development)
15+
if (${Python3_FOUND})
16+
include_directories(${Python3_INCLUDE_DIRS})
17+
else()
18+
message(FATAL_ERROR "Python3 not found, please install it.")
19+
endif()
20+
21+
find_package(NumPy)
22+
if (${PYTHON_NUMPY_FOUND})
23+
include_directories(${PYTHON_NUMPY_INCLUDE_DIR})
24+
else()
25+
message(WARNING "Python3 NumPy not found, proceeding with -DWITHOUT_NUMPY."
26+
" Some functions might not work.")
27+
add_definitions(-DWITHOUT_NUMPY)
28+
endif()
29+
30+
# add_subdirectory("examples")
31+
set(CMAKE_CXX_STANDARD 17)
32+
add_executable(basic examples/basic.cpp matplotlibcpp.h)
33+
target_link_libraries(basic ${Python3_LIBRARIES})

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Put the path to your Python.h here
1+
# Python header include: Put the path to Python.h here
22
includes = -I /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/include/python3.7m
33

4-
# Numpy include
4+
# Numpy include: Put the path to numpy/arrayobject.h
55
includes += -I /usr/local/lib/python3.7/site-packages/numpy/core/include
66

7-
# Add the path to the directory containing libpython*.a here if the linking fails
7+
# Python libraries include: Add the path to the directory containing libpython*.a here
88
includes += -L /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib
99

10-
# Link your python version
10+
# Link your Python version
1111
linkings = -lpython3.7
1212

1313
# Compiler definitions

cmake/modules/FindEigen3.cmake

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# - Try to find Eigen3 lib
2+
#
3+
# This module supports requiring a minimum version, e.g. you can do
4+
# find_package(Eigen3 3.1.2)
5+
# to require version 3.1.2 or newer of Eigen3.
6+
#
7+
# Once done this will define
8+
#
9+
# EIGEN3_FOUND - system has eigen lib with correct version
10+
# EIGEN3_INCLUDE_DIR - the eigen include directory
11+
# EIGEN3_VERSION - eigen version
12+
#
13+
# This module reads hints about search locations from
14+
# the following enviroment variables:
15+
#
16+
# EIGEN3_ROOT
17+
# EIGEN3_ROOT_DIR
18+
19+
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
20+
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
21+
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
22+
# Redistribution and use is allowed according to the terms of the 2-clause BSD license.
23+
24+
if(NOT Eigen3_FIND_VERSION)
25+
if(NOT Eigen3_FIND_VERSION_MAJOR)
26+
set(Eigen3_FIND_VERSION_MAJOR 2)
27+
endif(NOT Eigen3_FIND_VERSION_MAJOR)
28+
if(NOT Eigen3_FIND_VERSION_MINOR)
29+
set(Eigen3_FIND_VERSION_MINOR 91)
30+
endif(NOT Eigen3_FIND_VERSION_MINOR)
31+
if(NOT Eigen3_FIND_VERSION_PATCH)
32+
set(Eigen3_FIND_VERSION_PATCH 0)
33+
endif(NOT Eigen3_FIND_VERSION_PATCH)
34+
35+
set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}")
36+
endif(NOT Eigen3_FIND_VERSION)
37+
38+
macro(_eigen3_check_version)
39+
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
40+
41+
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
42+
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")
43+
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}")
44+
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}")
45+
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}")
46+
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}")
47+
48+
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION})
49+
if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
50+
set(EIGEN3_VERSION_OK FALSE)
51+
else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
52+
set(EIGEN3_VERSION_OK TRUE)
53+
endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION})
54+
55+
if(NOT EIGEN3_VERSION_OK)
56+
57+
message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, "
58+
"but at least version ${Eigen3_FIND_VERSION} is required")
59+
endif(NOT EIGEN3_VERSION_OK)
60+
endmacro(_eigen3_check_version)
61+
62+
if (EIGEN3_INCLUDE_DIR)
63+
64+
# in cache already
65+
_eigen3_check_version()
66+
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK})
67+
68+
else (EIGEN3_INCLUDE_DIR)
69+
70+
# search for signature, 1st try
71+
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
72+
HINTS
73+
ENV EIGEN3_ROOT
74+
ENV EIGEN3_ROOT_DIR
75+
PATHS
76+
${CMAKE_INSTALL_PREFIX}/include
77+
${KDE4_INCLUDE_DIR}
78+
PATH_SUFFIXES eigen3 eigen
79+
)
80+
81+
if (NOT DEFINED EIGEN3_INCLUDE_DIR)
82+
83+
# search for directory name, 2nd try
84+
find_path(EIGEN3_INCLUDE_DIR NAMES Eigen/Core
85+
HINTS
86< 10000 code class="diff-text syntax-highlighted-line addition">+
/usr/include
87+
/usr/local/include
88+
)
89+
90+
endif()
91+
92+
endif(EIGEN3_INCLUDE_DIR)
93+
94+
if(EIGEN3_INCLUDE_DIR)
95+
_eigen3_check_version()
96+
message(STATUS "Eigen3 found at ${EIGEN3_INCLUDE_DIR}")
97+
98+
include(FindPackageHandleStandardArgs)
99+
find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
100+
101+
mark_as_advanced(EIGEN3_INCLUDE_DIR)
102+
103+
endif()
104+

cmake/modules/FindNumPy.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Find the Python NumPy package
2+
# PYTHON_NUMPY_INCLUDE_DIR
3+
# PYTHON_NUMPY_FOUND
4+
# will be set by this script
5+
6+
cmake_minimum_required(VERSION 2.8)
7+
8+
if(NOT PYTHON_EXECUTABLE)
9+
if(NumPy_FIND_QUIETLY)
10+
find_package(PythonInterp QUIET)
11+
else()
12+
find_package(PythonInterp)
13+
set(__numpy_out 1)
14+
endif()
15+
endif()
16+
17+
if (PYTHON_EXECUTABLE)
18+
# Find out the include path
19+
execute_process(
20+
COMMAND "${PYTHON_EXECUTABLE}" -c
21+
"from __future__ import print_function\ntry: import numpy; print(numpy.get_include(), end='')\nexcept:pass\n"
22+
OUTPUT_VARIABLE __numpy_path)
23+
# And the version
24+
execute_process(
25+
COMMAND "${PYTHON_EXECUTABLE}" -c
26+
"from __future__ import print_function\ntry: import numpy; print(numpy.__version__, end='')\nexcept:pass\n"
27+
OUTPUT_VARIABLE __numpy_version)
28+
elseif(__numpy_out)
29+
message(STATUS "Python executable not found.")
30+
endif(PYTHON_EXECUTABLE)
31+
32+
find_path(PYTHON_NUMPY_INCLUDE_DIR numpy/arrayobject.h
33+
HINTS "${__numpy_path}" "${PYTHON_INCLUDE_PATH}" NO_DEFAULT_PATH)
34+
35+
if(PYTHON_NUMPY_INCLUDE_DIR)
36+
set(PYTHON_NUMPY_FOUND 1 CACHE INTERNAL "Python numpy found")
37+
endif(PYTHON_NUMPY_INCLUDE_DIR)
38+
39+
include(FindPackageHandleStandardArgs)
40+
find_package_handle_standard_args(NumPy REQUIRED_VARS PYTHON_NUMPY_INCLUDE_DIR
41+
VERSION_VAR __numpy_version)

0 commit comments

Comments
 (0)
0