forked from alandefreitas/small
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
167 lines (141 loc) · 5.85 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
#
# Copyright (c) 2022 alandefreitas (alandefreitas@gmail.com)
#
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
#
#######################################################
### Small ###
#######################################################
# Project information
cmake_minimum_required(VERSION 3.15)
project(
small
VERSION 0.2.1
DESCRIPTION "C++ small containers"
HOMEPAGE_URL "https://alandefreitas.github.io/small"
)
set(SMALL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SMALL_VERSION ${CMAKE_PROJECT_VERSION})
message(STATUS "${CMAKE_PROJECT_NAME} v${CMAKE_PROJECT_VERSION}: ${CMAKE_PROJECT_HOMEPAGE_URL}")
include(cmake/small/in_source_guard.cmake)
include(cmake/small/variables.cmake)
#######################################################
### Options ###
#######################################################
# What to build
option(SMALL_BUILD_INSTALLER "Build installer target" ${SMALL_MASTER_PROJECT})
option(SMALL_BUILD_PACKAGE "Build package" ${SMALL_MASTER_PROJECT})
# How to build
option(SMALL_BUILD_WITH_EXCEPTIONS "Add compiler flags to use exceptions." ON)
# Development options
include(cmake/small/dev-options.cmake)
#######################################################
### Libraries ###
#######################################################
add_subdirectory(include)
#######################################################
### Installer ###
#######################################################
if (SMALL_BUILD_INSTALLER)
# Install targets
install(TARGETS small
EXPORT small-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/small
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
# Install cmake targets script
install(EXPORT small-targets
FILE small-targets.cmake
NAMESPACE small::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/small
)
# 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/small)
message(STATUS "${CMAKE_PROJECT_NAME} install directory: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "${CMAKE_PROJECT_NAME} library install directory: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
# Create small-config-version.cmake and install it
if (CMAKE_PROJECT_VERSION VERSION_LESS 1.0.0)
set(compatibility_mode SameMajorVersion)
else ()
set(compatibility_mode SameMinorVersion)
endif ()
write_basic_package_version_file(
small-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ${compatibility_mode}
)
# Install the file small-config-version.cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/small-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/small)
# Create small-config.cmake from small-config.cmake.in
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/small-config.cmake.in # input file
${CMAKE_CURRENT_BINARY_DIR}/small-config.cmake # output file
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/small
)
# Install the file small-config.cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/small-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/small)
endif ()
#######################################################
### Packages ###
#######################################################
if (SMALL_BUILD_INSTALLER AND SMALL_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 "small")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "small: C++ small containers")
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 "${SMALL_ROOT_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${SMALL_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 ()
#######################################################
### Developer mode ###
#######################################################
if (NOT SMALL_DEVELOPER_MODE)
return()
elseif (NOT SMALL_MASTER_PROJECT)
message(
AUTHOR_WARNING
"Developer mode is intended for developers"
)
endif ()
add_subdirectory(dev-tools)
if (SMALL_BUILD_TESTS)
include(CTest)
enable_testing()
add_subdirectory(test)
endif ()
if (SMALL_BUILD_DOCS)
add_subdirectory(docs)
endif ()
if (SMALL_BUILD_COVERAGE_REPORT)
include(cmake/small/coverage-report.cmake)
endif ()
if (SMALL_BUILD_LINT)
include(cmake/small/lint-targets.cmake)
endif ()
#######################################################
### Examples ###
#######################################################
if (SMALL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()