1
+ #######################################################
2
+ ### Matplot++ ###
3
+ #######################################################
1
4
cmake_minimum_required (VERSION 3.14 )
2
- project (matplotplusplus )
5
+ project (matplotplusplus VERSION 1.0.0 )
3
6
4
- # https://cliutils.gitlab.io/modern-cmake/chapters/basics/variables.html
5
7
set (CMAKE_CXX_STANDARD 17 )
6
-
7
8
include (CMakePackageConfigHelpers )
8
9
include (GNUInstallDirs )
9
-
10
10
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake )
11
11
include (cmake/CPM.cmake )
12
12
message ("CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} " )
13
13
14
+ # Is this a master project or a subdirectory of another project
14
15
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR} )
15
16
set (MASTER_PROJECT ON )
16
17
else ()
17
18
set (MASTER_PROJECT OFF )
18
19
endif ()
19
20
set (MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
20
21
22
+ #######################################################
23
+ ### Options ###
24
+ #######################################################
25
+ # What to build
21
26
option (BUILD_EXAMPLES "Build examples" ${MASTER_PROJECT} )
22
27
option (BUILD_TESTS "Build tests" ${MASTER_PROJECT} )
28
+ option (BUILD_INSTALLER "Build installer target" ${MASTER_PROJECT} )
29
+ option (BUILD_PACKAGE "Build package" ${MASTER_PROJECT} )
23
30
31
+ # How to build
24
32
option (BUILD_SHARED_LIBS "Build shared libraries" OFF )
25
-
26
33
option (BUILD_HIGH_RESOLUTION_WORLD_MAP "Compile the high resolution maps for geoplots" ON )
27
34
option (BUILD_FOR_DOCUMENTATION_IMAGES "Bypass wait() commands and save figures as .svg at destruction" OFF )
28
35
option (BUILD_EXPERIMENTAL_OPENGL_BACKEND "Compile target with the experimental OpenGL backend" OFF )
36
+ option (OPTIMIZE_RELEASE_CODE_BY_DEFAULT "Turn on optimization flags by default in Release" OFF )
37
+ if (OPTIMIZE_RELEASE_CODE_BY_DEFAULT )
38
+ if (MSVC )
39
+ set (CMAKE_CXX_FLAGS_RELEASE "/O2" )
40
+ else ()
41
+ set (CMAKE_CXX_FLAGS_RELEASE "-O2" )
42
+ endif ()
43
+ endif ()
44
+ option (BUILD_WITH_PEDANTIC_WARNINGS "Use pedantic warnings. This is useful for developers because many of these warnings will be in continuous integration anyway." OFF )
45
+ option (BUILD_WITH_UTF8 "Accept utf-8 in MSVC by default." ON )
29
46
47
+ # Where to find dependencies
30
48
option (WITH_SYSTEM_CIMG "Use system-provided CImg.h instead of bundled" OFF )
31
49
option (WITH_SYSTEM_NODESOUP "Use system-provided nodesoup instead of bundled" OFF )
32
50
33
-
51
+ #######################################################
52
+ ### Libraries ###
53
+ #######################################################
34
54
add_subdirectory (source )
35
55
36
- if (MASTER_PROJECT )
37
- if (BUILD_EXAMPLES )
38
- add_subdirectory (examples )
39
- endif ()
40
- if (BUILD_TESTS )
41
- add_subdirectory (test )
42
- endif ()
56
+ #######################################################
57
+ ### Examples and tests ###
58
+ #######################################################
59
+ if (BUILD_EXAMPLES )
60
+ add_subdirectory (examples )
61
+ endif ()
43
62
63
+ if (BUILD_TESTS )
64
+ add_subdirectory (test )
65
+ endif ()
66
+
67
+ #######################################################
68
+ ### Installer ###
69
+ #######################################################
70
+ if (BUILD_INSTALLER )
71
+ # https://cliutils.gitlab.io/modern-cmake/chapters/install/installing.html
72
+ # Set variable where the cmake config is
44
73
set (CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
74
+
75
+ # Create Matplot++ConfigVersion.cmake and install it
76
+ write_basic_package_version_file (
77
+ Matplot++ConfigVersion.cmake
78
+ VERSION ${PACKAGE_VERSION}
79
+ COMPATIBILITY AnyNewerVersion
80
+ )
81
+
82
+ # Create matplot++-config.cmake from matplot++-config.cmake.in
45
83
configure_package_config_file (${CMAKE_CURRENT_SOURCE_DIR} /matplot++-config.cmake.in
46
- ${CMAKE_CURRENT_BINARY_DIR} /matplot++-config.cmake
47
- INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
84
+ ${CMAKE_CURRENT_BINARY_DIR} /matplot++-config.cmake
85
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
86
+
87
+ # Install the file matplot++-config.cmake
48
88
install (FILES ${CMAKE_CURRENT_BINARY_DIR} /matplot++-config.cmake
49
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
89
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
50
90
51
- if (NOT BUILD_SHARED_LIBS )
91
+ # Install cmake to find filesystem as a dependency
92
+ if (NOT BUILD_SHARED_LIBS )
52
93
install (FILES ${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindFilesystem.cmake
53
- DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
54
- endif ()
55
- endif ()
94
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/Matplot++ )
95
+ endif ()
96
+ endif ()
97
+
98
+ #######################################################
99
+ ### Packages ###
100
+ #######################################################
101
+ if (BUILD_INSTALLER AND BUILD_PACKAGE )
102
+ # Set the cpack variables
103
+ # https://cliutils.gitlab.io/modern-cmake/chapters/install/packaging.html
104
+
105
+ # The most common cpack variables
106
+ set (CPACK_PACKAGE_VENDOR "Matplot++" )
107
+ set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Matplot++: A C++ Graphics Library for Data Visualization" )
108
+ set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} )
109
+ set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR} )
110
+ set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH} )
111
+ set (CPACK_RESOURCE_FILE_LICENSE "${MATPLOT_ROOT_DIR} /LICENSE" )
112
+ set (CPACK_RESOURCE_FILE_README "${MATPLOT_ROOT_DIR} /README.md" )
113
+
114
+ # Set CPACK_SOURCE_IGNORE_FILES with files source packages shouldn't install
115
+ # We get these from .gitignore to avoid redundancy
116
+ FILE (READ .gitignore GITIGNORE_CONTENTS )
117
+ STRING (REGEX REPLACE ";" "\\\\ ;" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS} " )
118
+ STRING (REGEX REPLACE "\n " ";" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS} " )
119
+ set (CPACK_SOURCE_IGNORE_FILES ${GITIGNORE_CONTENTS} )
120
+
121
+ # Always include CPack at last
122
+ include (CPack )
123
+ endif ()
0 commit comments