forked from synesissoftware/CLASP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
233 lines (157 loc) · 6.22 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# ######################################################################## #
# File: /CMakeLists.txt
#
# Purpose: Top-level CMake lists file for CLASP
#
# Created: 8th January 2021
# Updated: 23rd October 2024
#
# ######################################################################## #
# ##########################################################
# CMake
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
# require out-of-source builds
file(TO_CMAKE_PATH "${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()
# directory for CMake specific extensions and source files.
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# ##########################################################
# project
project(CLASP
DESCRIPTION "CLASP is a small, simple C-language library for parsing command-line arguments, along with a C++ header-only API."
HOMEPAGE_URL "https://github.com/synesissoftware/CLASP"
LANGUAGES C CXX
)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
# handle version number
set(RX_PROJ_TAG "${PROJECT_NAME_UPPER}")
set(RX_WS "[ \t]")
file(READ "${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME_LOWER}/${PROJECT_NAME_LOWER}.h" _header_file)
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MAJOR${RX_WS}+([0-9]+)" MAJOR_DUMMY ${_header_file})
set(_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_MINOR${RX_WS}+([0-9]+)" MINOR_DUMMY ${_header_file})
set(_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "#${RX_WS}*define${RX_WS}+_?${RX_PROJ_TAG}_VER_REVISION${RX_WS}+([0-9]+)" PATCH_DUMMY ${_header_file})
set(_VERSION_PATCH ${CMAKE_MATCH_1})
# set project version number here
set(PROJECT_VERSION_MAJOR ${_VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${_VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${_VERSION_PATCH})
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# adhere strictly to C and C++ standards plus extensions. These are actually
# useless since we do not compile anything; they merely state our intention.
set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON) # GNU extensions and POSIX standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if(MSVC)
if(MSVC_VERSION LESS 1930)
set(CMAKE_C_STANDARD 90)
set(CMAKE_CXX_STANDARD 98)
endif()
endif(MSVC)
# ##########################################################
# dependencies, includes, options
# ################################################
# includes - 1
include(BuildType)
include(LanguageFullVersion)
include(TargetMacros)
# ################################################
# dependencies and options
option(BUILD_EXAMPLES "Build examples" ON)
# ######################################
# dependencies
#
# required:
# - STLSoft;
#
# optional:
# - xTests - required for testing;
if(DEFINED STLSOFT)
message("-- STLSOFT provided as CMake variable with value '${STLSOFT}'")
set(STLSOFT_INCLUDE_DIR ${STLSOFT}/include)
elseif(DEFINED ENV{STLSOFT})
message("-- STLSOFT provided as environment variable with value '$ENV{STLSOFT}'")
set(STLSOFT_INCLUDE_DIR $ENV{STLSOFT}/include)
else()
set(STLSoft_REQUIRED_VERSION_ 1.11)
find_package(STLSoft ${STLSoft_REQUIRED_VERSION_} REQUIRED)
message("-- CMake package STLSoft found (version ${STLSoft_VERSION}; ${STLSoft_REQUIRED_VERSION_} requested)")
endif()
if(DEFINED STLSOFT_INCLUDE_DIR)
include_directories(${STLSOFT_INCLUDE_DIR})
endif()
# ############################
# xTests
if(BUILD_TESTING)
set(xTests_REQUIRED_VERSION_ 0.25)
find_package(xTests ${xTests_REQUIRED_VERSION_} REQUIRED)
message("-- CMake package xTests found (version ${xTests_VERSION}; ${xTests_REQUIRED_VERSION_} requested)")
endif(BUILD_TESTING)
# ################################################
# includes - 2
include(CMakePackageConfigHelpers)
if(BUILD_TESTING)
include(CTest)
endif(BUILD_TESTING)
include(GNUInstallDirs)
# ##########################################################
# targets
# ################################################
# main library
add_subdirectory(src)
# ################################################
# examples
if(BUILD_EXAMPLES)
message("-- enabled building of examples ...")
add_subdirectory(examples)
else(BUILD_EXAMPLES)
message("-- disabled building of examples - define BUILD_EXAMPLES to enable")
endif(BUILD_EXAMPLES)
# ################################################
# tests
if(BUILD_TESTING)
message("-- enabled building of tests ...")
add_subdirectory(test)
else(BUILD_TESTING)
message("-- disabled building of tests - define BUILD_TESTING to enable")
endif(BUILD_TESTING)
# ##########################################################
# install
# ##########################################################
# export
set(EXPORT_NAME ${PROJECT_NAME})
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${EXPORT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/${EXPORT_NAME}/cmake
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT project-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-targets.cmake"
NAMESPACE "${PROJECT_NAME}::"
)
install(EXPORT project-targets
NAMESPACE "${PROJECT_NAME}::"
FILE "${EXPORT_NAME}-targets.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${EXPORT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
)
# ##########################################################
# completion
message(NOTICE "Generating CMake build scripts for ${PROJECT_NAME} ${PROJECT_VERSION}, for C${CMAKE_C_STANDARD} C++${CMAKE_CXX_STANDARD}")
# ############################## end of file ############################# #