Skip to content

Commit 1863553

Browse files
committed
Add CPack
1 parent b055a03 commit 1863553

File tree

1 file changed

+88
-20
lines changed

1 file changed

+88
-20
lines changed

CMakeLists.txt

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,123 @@
1+
#######################################################
2+
### Matplot++ ###
3+
#######################################################
14
cmake_minimum_required(VERSION 3.14)
2-
project(matplotplusplus)
5+
project(matplotplusplus VERSION 1.0.0)
36

4-
# https://cliutils.gitlab.io/modern-cmake/chapters/basics/variables.html
57
set(CMAKE_CXX_STANDARD 17)
6-
78
include(CMakePackageConfigHelpers)
89
include(GNUInstallDirs)
9-
1010
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
1111
include(cmake/CPM.cmake)
1212
message("CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
1313

14+
# Is this a master project or a subdirectory of another project
1415
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
1516
set(MASTER_PROJECT ON)
1617
else ()
1718
set(MASTER_PROJECT OFF)
1819
endif ()
1920
set(MATPLOT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2021

22+
#######################################################
23+
### Options ###
24+
#######################################################
25+
# What to build
2126
option(BUILD_EXAMPLES "Build examples" ${MASTER_PROJECT})
2227
option(BUILD_TESTS "Build tests" ${MASTER_PROJECT})
28+
option(BUILD_INSTALLER "Build installer target" ${MASTER_PROJECT})
29+
option(BUILD_PACKAGE "Build package" ${MASTER_PROJECT})
2330

31+
# How to build
2432
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
25-
2633
option(BUILD_HIGH_RESOLUTION_WORLD_MAP "Compile the high resolution maps for geoplots" ON)
2734
option(BUILD_FOR_DOCUMENTATION_IMAGES "Bypass wait() commands and save figures as .svg at destruction" OFF)
2835
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)
2946

47+
# Where to find dependencies
3048
option(WITH_SYSTEM_CIMG "Use system-provided CImg.h instead of bundled" OFF)
3149
option(WITH_SYSTEM_NODESOUP "Use system-provided nodesoup instead of bundled" OFF)
3250

33-
51+
#######################################################
52+
### Libraries ###
53+
#######################################################
3454
add_subdirectory(source)
3555

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 ()
4362

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
4473
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
4583
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
4888
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matplot++-config.cmake
49-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++)
89+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Matplot++)
5090

51-
if(NOT BUILD_SHARED_LIBS)
91+
# Install cmake to find filesystem as a dependency
92+
if (NOT BUILD_SHARED_LIBS)
5293
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

Comments
 (0)