-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
199 lines (170 loc) · 5.51 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
#
# Copyright (C) 2023,2024 Dan Arrhenius <dan@ultramarin.se>
#
# This file is part of ujson.
#
# ujson is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required (VERSION 3.22)
# Project name and info
#
project (libujson
VERSION 4.2.3
LANGUAGES CXX
DESCRIPTION "A JSON C++ library and utility applications for handling JSON documents."
HOMEPAGE_URL https://github.com/alfmep/libujson
)
# C++ standard
#
set (CMAKE_CXX_STANDARD 17)
# Default GNU installation directories
#
include (GNUInstallDirs)
# Common compiler flags
#
set (gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set (msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
add_compile_options (
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-pipe;-Wall>>"
"$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>"
)
if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug")
# If build type is debug, add flag -Og for GCC et al.
add_compile_options (
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Og>>"
)
endif()
# Options
#
option (BUILD_SHARED_LIBS "Build shared library." ON)
option (DISABLE_GMPXX "Don't use libgmpxx to support numbers with arbitrary precision. Default is to use libgmpxx if found." OFF)
option (BUILD_UTILS "Build utility applications." ON)
option (BUILD_EXAMPLES "Build example applications." OFF)
option (BUILD_TESTS "Build test applications." OFF)
option (BUILD_DOC "Generate documentation (if doxygen is found)." ON)
if (UNIX)
option (DISABLE_CONSOLE_COLOR "Disable support for console color." OFF)
endif()
set (PREDEFINED_IN_DOXYGEN "")
# Support for console color codes
#
if (UNIX)
if (NOT DISABLE_CONSOLE_COLOR)
set (UJSON_HAS_CONSOLE_COLOR "1")
set (PREDEFINED_IN_DOXYGEN "${PREDEFINED_IN_DOXYGEN} UJSON_HAS_CONSOLE_COLOR=1")
else()
set (UJSON_HAS_CONSOLE_COLOR "0")
endif()
else()
set (UJSON_HAS_CONSOLE_COLOR "0")
endif()
# Dependencies
#
if (DISABLE_GMPXX)
message (STATUS "Don't use libgmpxx to support numbers with arbitrary precision, instead numbers are represented by type double.")
set (GMPXX_FOUND False)
else()
include (find-gmpxx.cmake)
endif()
if (GMPXX_FOUND)
set (UJSON_HAVE_GMPXX "1")
set (PREDEFINED_IN_DOXYGEN "${PREDEFINED_IN_DOXYGEN} UJSON_HAVE_GMPXX=1")
else()
set (UJSON_HAVE_GMPXX "0")
endif()
# libujson
#
add_subdirectory (src)
# Utility applications
#
if (BUILD_UTILS)
add_subdirectory (utils)
endif()
# Example applications
#
if (BUILD_EXAMPLES)
add_subdirectory (examples)
endif()
# test applications
#
if (BUILD_TESTS)
add_subdirectory (test)
endif()
# Doxygen documentation
#
if (BUILD_DOC)
find_package (Doxygen)
if (DOXYGEN_FOUND)
add_subdirectory (doc)
endif()
endif()
# Add targets for distributable files
#
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set (CPACK_GENERATOR "TGZ" "TXZ" "ZIP")
set (CPACK_SOURCE_GENERATOR "TGZ" "TXZ" "ZIP")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${libujson_VERSION_MAJOR}.${libujson_VERSION_MINOR}.${libujson_VERSION_PATCH}")
include (CPack)
# Un-installation
#
if (NOT TARGET uninstall)
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target (uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
# Print summary
#
message (STATUS "Summary:")
if (CMAKE_BUILD_TYPE MATCHES "^$")
message (STATUS " Build type........................... [default]")
else()
message (STATUS " Build type........................... ${CMAKE_BUILD_TYPE}")
endif()
message (STATUS " Installation prefix.................. ${CMAKE_INSTALL_PREFIX}")
if (GMPXX_FOUND)
message (STATUS " Using gmpxx.......................... yes - numbers with arbitrary precision supported")
else()
message (STATUS " Using gmpxx.......................... no - numbers are represented by type double")
endif()
if (UNIX)
if (DISABLE_CONSOLE_COLOR)
message (STATUS " Enable support for console colors.... no")
else()
message (STATUS " Enable support for console colors.... yes")
endif()
endif()
if (BUILD_UTILS)
message (STATUS " Build utilities ..................... yes")
else()
message (STATUS " Build utilities ..................... no")
endif()
if (BUILD_EXAMPLES)
message (STATUS " Build example applications........... yes (example applications are not installed)")
else()
message (STATUS " Build example applications........... no")
endif()
if (BUILD_TESTS)
message (STATUS " Build test applications.............. yes (test applications are not installed)")
else()
message (STATUS " Build test applications.............. no")
endif()
if (DOXYGEN_FOUND)
message (STATUS " Generate API documentation........... yes")
else()
message (STATUS " Generate API documentation........... no")
endif()