-
Notifications
You must be signed in to change notification settings - Fork 343
/
Copy pathCMakeLists.txt
179 lines (155 loc) · 7.47 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#######################################################
### Matplot++ ###
#######################################################
# Project information
cmake_minimum_required(VERSION 3.15)
include(cmake/functions/ensure_build_type.cmake)
project(Matplot++ VERSION 1.2.0)
set(MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MATPLOT_VERSION ${CMAKE_PROJECT_VERSION})
#######################################################
### CMake Functions ###
#######################################################
# CMake dependencies for installer
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# Append ./cmake directory to our include paths for the find_package scripts
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Functions to find or download packages if we can't find_package
include(FetchContent)
# Our custom cmake functions
include(cmake/functions.cmake)
#######################################################
### Declare options ###
#######################################################
# Set variables with project properties
set_master_project_booleans() # detect if master project / dev mode
set_debug_booleans() # detect if debug
set_compiler_booleans() # detect compiler
# What to build
option(MATPLOTPP_BUILD_EXAMPLES "Build examples" ${MASTER_PROJECT})
if (${MASTER_PROJECT} AND BUILD_TESTING)
option(MATPLOTPP_BUILD_TESTS "Build tests" ON)
else()
option(MATPLOTPP_BUILD_TESTS "Build tests" OFF)
endif()
option(MATPLOTPP_BUILD_INSTALLER "Build installer target" ${MASTER_PROJECT})
option(MATPLOTPP_BUILD_PACKAGE "Build package" ${MASTER_PROJECT})
# How to build
option(MATPLOTPP_BUILD_WITH_PEDANTIC_WARNINGS "Use pedantic warnings. This is useful for developers because many of these warnings will be in continuous integration anyway." ${DEBUG_MODE})
option(MATPLOTPP_BUILD_SHARED_LIBS "Build shared libraries" ${BUILD_SHARED_LIBS})
option(MATPLOTPP_BUILD_WITH_SANITIZERS "Use pedantic warnings." ${DEBUG_MODE})
# MSVC hacks
option(MATPLOTPP_BUILD_WITH_MSVC_HACKS "Accept utf-8 in MSVC by default." ON)
option(MATPLOTPP_BUILD_WITH_UTF8 "Accept utf-8 in MSVC by default." ON)
option(MATPLOTPP_BUILD_WITH_EXCEPTIONS "Add compiler flags to use exceptions." ON)
# Features
option(MATPLOTPP_BUILD_HIGH_RESOLUTION_WORLD_MAP "Compile the high resolution maps for geoplots" ON)
option(MATPLOTPP_BUILD_FOR_DOCUMENTATION_IMAGES "Bypass show() commands and save figures as .svg at destruction" OFF)
option(MATPLOTPP_BUILD_EXPERIMENTAL_OPENGL_BACKEND "Compile target with the experimental OpenGL backend" OFF)
option(MATPLOTPP_WITH_OPENCV "Use OpenCV in CImg" ON)
# Where to find dependencies
option(MATPLOTPP_WITH_SYSTEM_CIMG "Use system-provided CImg.h instead of bundled" OFF)
option(MATPLOTPP_WITH_SYSTEM_NODESOUP "Use system-provided nodesoup instead of bundled" OFF)
#######################################################
### Apply global options ###
#######################################################
# In development, we can set some options for all targets
if (MASTER_PROJECT)
message("Setting global options")
# Maybe add sanitizers to all targets
if (MATPLOTPP_BUILD_WITH_SANITIZERS AND NOT EMSCRIPTEN)
add_sanitizers()
endif ()
# Allow exceptions in MSVC
if (MSVC AND MATPLOTPP_BUILD_WITH_EXCEPTIONS)
add_compile_options(/EHsc)
endif ()
# Allow utf-8 in MSVC
if (MATPLOTPP_BUILD_WITH_UTF8 AND MSVC)
set(CMAKE_CXX_FLAGS "/utf-8")
endif ()
# MSVC hack to disable windows min/max
# http://www.suodenjoki.dk/us/archive/2010/min-max.htm
if (MSVC AND MATPLOTPP_BUILD_WITH_MSVC_HACKS)
# Check for min in Windows.h
# include(CheckSymbolExists)
# check_symbol_exists(min "WinDef.h" HAVE_WINDOWS_MINMAX)
# if (NOT HAVE_WINDOWS_MINMAX)
# check_symbol_exists(min "Windows.h" HAVE_WINDOWS_MINMAX)
# endif ()
# if (HAVE_WINDOWS_MINMAX)
add_compile_definitions(NOMINMAX)
# endif ()
endif ()
endif()
#######################################################
### Libraries ###
#######################################################
add_subdirectory(source)
#######################################################
### Tests ###
#######################################################
if (MATPLOTPP_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif ()
#######################################################
### Examples ###
#######################################################
if (MATPLOTPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
#######################################################
### Installer ###
#######################################################
if (MATPLOTPP_BUILD_INSTALLER)
# https://cliutils.gitlab.io/modern-cmake/chapters/install/installing.html
# Set variable where the cmake config is
set(CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++)
message("CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
message("CMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}")
# Create Matplot++ConfigVersion.cmake and install it
write_basic_package_version_file(
Matplot++ConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Matplot++ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++)
# Create Matplot++Config.cmake from Matplot++Config.cmake.in
set(INCLUDE_INSTALL_DIR include/)
set(LIB_INSTALL_DIR lib/)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Matplot++Config.cmake.in # input file
${CMAKE_CURRENT_BINARY_DIR}/Matplot++Config.cmake # output file
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++
PATH_VARS CMAKE_INSTALL_LIBDIR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Matplot++Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++)
endif ()
#######################################################
### Packages ###
#######################################################
if (MATPLOTPP_BUILD_INSTALLER AND MATPLOTPP_BUILD_PACKAGE)
# Set the cpack variables
# https://cliutils.gitlab.io/modern-cmake/chapters/install/packaging.html
# The most common cpack variables
set(CPACK_PACKAGE_VENDOR "Matplot++")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Matplot++: A C++ Graphics Library for Data Visualization")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_RESOURCE_FILE_LICENSE "${MATPLOT_ROOT_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${MATPLOT_ROOT_DIR}/README.md")
# Set CPACK_SOURCE_IGNORE_FILES with files source packages shouldn't install
# We get these from .gitignore to avoid redundancy
FILE(READ .gitignore GITIGNORE_CONTENTS)
STRING(REGEX REPLACE ";" "\\\\;" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS}")
STRING(REGEX REPLACE "\n" ";" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS}")
set(CPACK_SOURCE_IGNORE_FILES ${GITIGNORE_CONTENTS})
# Always include CPack at last
include(CPack)
endif ()