|
5 | 5 | cmake_minimum_required(VERSION 3.14)
|
6 | 6 | project(matplotplusplus VERSION 1.0.2)
|
7 | 7 | set(CMAKE_CXX_STANDARD 17)
|
| 8 | +set(CMAKE_C_STANDARD 11) |
| 9 | +set(MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 10 | +set(MATPLOT_VERSION ${CMAKE_PROJECT_VERSION}) |
8 | 11 |
|
| 12 | +####################################################### |
| 13 | +### CMake Functions ### |
| 14 | +####################################################### |
9 | 15 | # CMake dependencies for installer
|
10 | 16 | include(CMakePackageConfigHelpers)
|
11 | 17 | include(GNUInstallDirs)
|
12 | 18 |
|
13 |
| -# To find or download packages |
| 19 | +# Append ./cmake directory to our include paths for the find_package scripts |
14 | 20 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
15 |
| -message("CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") |
16 |
| -option(CPM_USE_LOCAL_PACKAGES "Try `find_package` before downloading dependencies" ON) |
17 |
| -include(cmake/CPM.cmake) |
18 |
| - |
19 |
| -# Check if this is a master project or a subdirectory of another project |
20 |
| -if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) |
21 |
| - set(MASTER_PROJECT ON) |
22 |
| -else () |
23 |
| - set(MASTER_PROJECT OFF) |
24 |
| -endif () |
25 |
| -set(MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
26 | 21 |
|
27 |
| -# Check if we are in debug mode |
28 |
| -if(CMAKE_BUILD_TYPE MATCHES DEBUG) |
29 |
| - set(DEBUG_MODE ON) |
30 |
| - set(NOT_DEBUG_MODE OFF) |
31 |
| -else() |
32 |
| - set(DEBUG_MODE OFF) |
33 |
| - set(NOT_DEBUG_MODE ON) |
34 |
| -endif() |
| 22 | +# Functions to find or download packages if we can't find_package |
| 23 | +include(FetchContent) |
35 | 24 |
|
36 |
| -# Function to link external libraries as system libraries |
37 |
| -include (cmake/LinkExternalLibraries.cmake) |
| 25 | +# Our custom cmake functions |
| 26 | +include(cmake/functions.cmake) |
38 | 27 |
|
39 | 28 | #######################################################
|
40 |
| -### Options ### |
| 29 | +### Declare options ### |
41 | 30 | #######################################################
|
| 31 | +# Set variables with project properties |
| 32 | +set_master_project_booleans() # detect if master project / dev mode |
| 33 | +set_debug_booleans() # detect if debug |
| 34 | +set_optimization_flags() # detect and set default optimization flags |
| 35 | +set_compiler_booleans() # detect compiler |
| 36 | + |
42 | 37 | # What to build
|
43 | 38 | option(BUILD_EXAMPLES "Build examples" ${MASTER_PROJECT})
|
44 | 39 | option(BUILD_TESTS "Build tests" ${MASTER_PROJECT})
|
45 | 40 | option(BUILD_INSTALLER "Build installer target" ${MASTER_PROJECT})
|
46 | 41 | option(BUILD_PACKAGE "Build package" ${MASTER_PROJECT})
|
47 | 42 |
|
48 | 43 | # How to build
|
| 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." ${DEBUG_MODE}) |
49 | 45 | option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
| 46 | +option(BUILD_WITH_SANITIZERS "Use pedantic warnings." ${DEBUG_MODE}) |
| 47 | + |
| 48 | +# MSVC hacks |
| 49 | +option(BUILD_WITH_MSVC_HACKS "Accept utf-8 in MSVC by default." ON) |
| 50 | +option(BUILD_WITH_UTF8 "Accept utf-8 in MSVC by default." ON) |
| 51 | +option(BUILD_WITH_EXCEPTIONS "Add compiler flags to use exceptions." ON) |
| 52 | + |
| 53 | +# Features |
50 | 54 | option(BUILD_HIGH_RESOLUTION_WORLD_MAP "Compile the high resolution maps for geoplots" ON)
|
51 | 55 | option(BUILD_FOR_DOCUMENTATION_IMAGES "Bypass show() commands and save figures as .svg at destruction" OFF)
|
52 | 56 | option(BUILD_EXPERIMENTAL_OPENGL_BACKEND "Compile target with the experimental OpenGL backend" OFF)
|
53 |
| -option(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}) |
54 |
| -option(BUILD_WITH_UTF8 "Accept utf-8 in MSVC by default." ON) |
55 | 57 |
|
56 | 58 | # Where to find dependencies
|
57 | 59 | option(WITH_SYSTEM_CIMG "Use system-provided CImg.h instead of bundled" OFF)
|
58 | 60 | option(WITH_SYSTEM_NODESOUP "Use system-provided nodesoup instead of bundled" OFF)
|
59 | 61 |
|
| 62 | +####################################################### |
| 63 | +### Apply global options ### |
| 64 | +####################################################### |
| 65 | +# In development, we can set some options for all targets |
| 66 | +if (MASTER_PROJECT) |
| 67 | + # Maybe add sanitizers to all targets |
| 68 | + if (BUILD_WITH_SANITIZERS AND NOT EMSCRIPTEN) |
| 69 | + add_sanitizers() |
| 70 | + endif () |
| 71 | + |
| 72 | + # Allow exceptions in MSVC |
| 73 | + if (MSVC AND BUILD_WITH_EXCEPTIONS) |
| 74 | + add_compile_options(/EHsc) |
| 75 | + endif () |
| 76 | + |
| 77 | + # Allow utf-8 in MSVC |
| 78 | + if (BUILD_WITH_UTF8 AND MSVC) |
| 79 | + set(CMAKE_CXX_FLAGS "/utf-8") |
| 80 | + endif () |
| 81 | + |
| 82 | + # MSVC hack to disable windows min/max |
| 83 | + # http://www.suodenjoki.dk/us/archive/2010/min-max.htm |
| 84 | + if (BUILD_WITH_MSVC_HACKS) |
| 85 | + # Check for min in Windows.h |
| 86 | + include(CheckSymbolExists) |
| 87 | + check_symbol_exists(min "Windows.h" HAVE_WINDOWS_MINMAX) |
| 88 | + if (HAVE_WINDOWS_MINMAX) |
| 89 | + add_compile_definitions(NOMINMAX) |
| 90 | + endif () |
| 91 | + endif () |
| 92 | +endif() |
| 93 | + |
60 | 94 | #######################################################
|
61 | 95 | ### Libraries ###
|
62 | 96 | #######################################################
|
63 | 97 | add_subdirectory(source)
|
64 | 98 |
|
65 | 99 | #######################################################
|
66 |
| -### Examples and tests ### |
| 100 | +### Tests ### |
67 | 101 | #######################################################
|
68 |
| -if (BUILD_EXAMPLES) |
69 |
| - add_subdirectory(examples) |
70 |
| -endif () |
71 |
| - |
72 | 102 | if (BUILD_TESTS)
|
| 103 | + include(CTest) |
| 104 | + enable_testing() |
73 | 105 | add_subdirectory(test)
|
74 | 106 | endif ()
|
75 | 107 |
|
| 108 | +####################################################### |
| 109 | +### Examples ### |
| 110 | +####################################################### |
| 111 | +if (BUILD_EXAMPLES) |
| 112 | + add_subdirectory(examples) |
| 113 | +endif () |
| 114 | + |
76 | 115 | #######################################################
|
77 | 116 | ### Installer ###
|
78 | 117 | #######################################################
|
|
0 commit comments