| 1 |
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR) |
| 2 |
|
| 3 |
project(c++utilities) |
| 4 |
|
| 5 |
# add project files |
| 6 |
set(HEADER_FILES |
| 7 |
application/argumentparser.h |
| 8 |
application/commandlineutils.h |
| 9 |
application/fakeqtconfigarguments.h |
| 10 |
application/global.h |
| 11 |
chrono/datetime.h |
| 12 |
chrono/period.h |
| 13 |
chrono/timespan.h |
| 14 |
chrono/format.h |
| 15 |
conversion/binaryconversion.h |
| 16 |
conversion/binaryconversionprivate.h |
| 17 |
conversion/conversionexception.h |
| 18 |
conversion/stringconversion.h |
| 19 |
conversion/stringbuilder.h |
| 20 |
io/ansiescapecodes.h |
| 21 |
io/binaryreader.h |
| 22 |
io/binarywriter.h |
| 23 |
io/bitreader.h |
| 24 |
io/buffersearch.h |
| 25 |
io/copy.h |
| 26 |
io/inifile.h |
| 27 |
io/path.h |
| 28 |
io/nativefilestream.h |
| 29 |
io/misc.h |
| 30 |
misc/flagenumclass.h |
| 31 |
misc/math.h |
| 32 |
misc/multiarray.h |
| 33 |
misc/parseerror.h |
| 34 |
misc/signingkeys.h |
| 35 |
misc/traits.h |
| 36 |
misc/levenshtein.h |
| 37 |
misc/verification.h |
| 38 |
tests/testutils.h |
| 39 |
tests/cppunit.h |
| 40 |
tests/outputcheck.h) |
| 41 |
set(SRC_FILES |
| 42 |
application/argumentparserprivate.h |
| 43 |
application/argumentparser.cpp |
| 44 |
application/commandlineutils.cpp |
| 45 |
application/fakeqtconfigarguments.cpp |
| 46 |
chrono/datetime.cpp |
| 47 |
chrono/period.cpp |
| 48 |
chrono/timespan.cpp |
| 49 |
conversion/conversionexception.cpp |
| 50 |
conversion/stringconversion.cpp |
| 51 |
io/ansiescapecodes.cpp |
| 52 |
io/binaryreader.cpp |
| 53 |
io/binarywriter.cpp |
| 54 |
io/bitreader.cpp |
| 55 |
io/buffersearch.cpp |
| 56 |
io/inifile.cpp |
| 57 |
io/path.cpp |
| 58 |
io/nativefilestream.cpp |
| 59 |
io/misc.cpp |
| 60 |
misc/math.cpp |
| 61 |
misc/parseerror.cpp |
| 62 |
misc/levenshtein.cpp |
| 63 |
tests/testutils.cpp) |
| 64 |
|
| 65 |
set(TEST_HEADER_FILES) |
| 66 |
set(TEST_SRC_FILES |
| 67 |
tests/cppunit.cpp |
| 68 |
tests/conversiontests.cpp |
| 69 |
tests/iotests.cpp |
| 70 |
tests/chronotests.cpp |
| 71 |
tests/argumentparsertests.cpp |
| 72 |
tests/traitstests.cpp |
| 73 |
tests/mathtests.cpp |
| 74 |
tests/misctests.cpp) |
| 75 |
|
| 76 |
set(CMAKE_MODULE_FILES |
| 77 |
cmake/modules/BasicConfig.cmake |
| 78 |
cmake/modules/ConfigHeader.cmake |
| 79 |
cmake/modules/LibraryTarget.cmake |
| 80 |
cmake/modules/TestUtilities.cmake |
| 81 |
cmake/modules/TestTarget.cmake |
| 82 |
cmake/modules/AppUtilities.cmake |
| 83 |
cmake/modules/AppTarget.cmake |
| 84 |
cmake/modules/WindowsResources.cmake |
| 85 |
cmake/modules/TemplateFinder.cmake |
| 86 |
cmake/modules/Doxygen.cmake |
| 87 |
cmake/modules/Sphinx.cmake |
| 88 |
cmake/modules/ListToString.cmake |
| 89 |
cmake/modules/ShellCompletion.cmake |
| 90 |
cmake/modules/DevelUtilities.cmake |
| 91 |
cmake/modules/3rdParty.cmake |
| 92 |
cmake/modules/3rdPartyFunctions.cmake) |
| 93 |
set(CMAKE_TEMPLATE_FILES |
| 94 |
cmake/templates/bash-completion.sh.in |
| 95 |
cmake/templates/Config.cmake.in |
| 96 |
cmake/templates/config.h.in |
| 97 |
cmake/templates/desktop.in |
| 98 |
cmake/templates/appdata.xml.in |
| 99 |
cmake/templates/doxygen.in |
| 100 |
cmake/templates/sphinx-conf.py.in |
| 101 |
cmake/templates/global.h.in |
| 102 |
cmake/templates/version.h.in |
| 103 |
cmake/templates/template.pc.in) |
| 104 |
if (WIN32) |
| 105 |
list(APPEND CMAKE_TEMPLATE_FILES cmake/templates/windows.rc.in cmake/templates/windows-cli-wrapper.rc.in |
| 106 |
cmake/templates/cli-wrapper.cpp) |
| 107 |
endif () |
| 108 |
set(EXCLUDED_FILES cmake/templates/cli-wrapper.cpp) |
| 109 |
|
| 110 |
set(DOC_FILES README.md doc/buildvariables.md doc/testapplication.md) |
| 111 |
set(EXTRA_FILES tests/calculateoverallcoverage.awk coding-style.clang-format) |
| 112 |
|
| 113 |
# required to include CMake modules from own project directory |
| 114 |
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}") |
| 115 |
|
| 116 |
# meta data |
| 117 |
set(META_PROJECT_NAME c++utilities) |
| 118 |
set(META_PROJECT_VARNAME CPP_UTILITIES) |
| 119 |
set(META_APP_NAME "C++ Utilities") |
| 120 |
set(META_APP_AUTHOR "Martchus") |
| 121 |
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") |
| 122 |
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities") |
| 123 |
set(META_VERSION_MAJOR 5) |
| 124 |
set(META_VERSION_MINOR 34) |
| 125 |
set(META_VERSION_PATCH 0) |
| 126 |
|
| 127 |
# find required 3rd party libraries |
| 128 |
include(3rdParty) |
| 129 |
option(USE_ICONV "uses iconv/libiconv; if disabled character set conversions and features depending on it are not available" |
| 130 |
ON) |
| 131 |
if (USE_ICONV) |
| 132 |
use_iconv(AUTO_LINKAGE REQUIRED) |
| 133 |
else () |
| 134 |
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_NO_ICONV) |
| 135 |
endif () |
| 136 |
|
| 137 |
# do not rely on legacy behavior of FlagEnumClass (TODO v6: remove macro, make new behavior the default) |
| 138 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_FLAG_ENUM_CLASS_NO_LEGACY_AND) |
| 139 |
|
| 140 |
# configure use of native file buffer and its backend implementation if enabled |
| 141 |
set(REQUIRED_BOOST_COMPONENTS "") |
| 142 |
set(USE_NATIVE_FILE_BUFFER_BY_DEFAULT OFF) |
| 143 |
if (WIN32 |
| 144 |
OR ANDROID |
| 145 |
OR (UNIX AND NOT APPLE)) |
| 146 |
set(USE_NATIVE_FILE_BUFFER_BY_DEFAULT ON) |
| 147 |
endif () |
| 148 |
option(USE_NATIVE_FILE_BUFFER "enables use of native file buffer, affects ABI" ${USE_NATIVE_FILE_BUFFER_BY_DEFAULT}) |
| 149 |
option(FORCE_BOOST_IOSTREAMS_FOR_NATIVE_FILE_BUFFER "forces use of Boost.Iostreams for native file buffer" OFF) |
| 150 |
if (USE_NATIVE_FILE_BUFFER) |
| 151 |
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_NATIVE_FILE_BUFFER) |
| 152 |
set(NATIVE_FILE_STREAM_IMPL_FILES io/nativefilestream.cpp tests/iotests.cpp) |
| 153 |
|
| 154 |
# check whether __gnu_cxx::stdio_filebuf is available |
| 155 |
try_compile( |
| 156 |
GNU_CXX_STDIO_FILEBUF_AVAILABLE ${CMAKE_CURRENT_BINARY_DIR} |
| 157 |
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/feature_detection/stdio_filebuf.cpp |
| 158 |
OUTPUT_VARIABLE GNU_CXX_STDIO_FILEBUF_CHECK_LOG) |
| 159 |
|
| 160 |
# use __gnu_cxx::stdio_filebuf if available or fallback to boost::iostreams::stream_buffer |
| 161 |
if (GNU_CXX_STDIO_FILEBUF_AVAILABLE AND NOT FORCE_BOOST_IOSTREAMS_FOR_NATIVE_FILE_BUFFER) |
| 162 |
message(STATUS "Using __gnu_cxx::stdio_filebuf for NativeFileStream") |
| 163 |
foreach (NATIVE_FILE_STREAM_IMPL_FILE ${NATIVE_FILE_STREAM_IMPL_FILES}) |
| 164 |
set_property( |
| 165 |
SOURCE ${NATIVE_FILE_STREAM_IMPL_FILE} |
| 166 |
APPEND |
| 167 |
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_GNU_CXX_STDIO_FILEBUF) |
| 168 |
endforeach () |
| 169 |
else () |
| 170 |
message(STATUS "Using boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> for NativeFileStream") |
| 171 |
list(APPEND REQUIRED_BOOST_COMPONENTS iostreams) |
| 172 |
foreach (NATIVE_FILE_STREAM_IMPL_FILE ${NATIVE_FILE_STREAM_IMPL_FILES}) |
| 173 |
set_property( |
| 174 |
SOURCE ${NATIVE_FILE_STREAM_IMPL_FILE} |
| 175 |
APPEND |
| 176 |
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_BOOST_IOSTREAMS) |
| 177 |
endforeach () |
| 178 |
endif () |
| 179 |
else () |
| 180 |
message(STATUS "Using std::fstream for NativeFileStream") |
| 181 |
endif () |
| 182 |
|
| 183 |
# configure use of Boost.Process for launching test applications on Windows |
| 184 |
if (WIN32) |
| 185 |
option(USE_BOOST_PROCESS "enables use of Boost.Process to launch test applications" ON) |
| 186 |
if (USE_BOOST_PROCESS) |
| 187 |
list(APPEND REQUIRED_BOOST_COMPONENTS filesystem) |
| 188 |
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_BOOST_PROCESS) |
| 189 |
list(APPEND PRIVATE_LIBRARIES ws2_32) # needed by Boost.Asio |
| 190 |
use_package(TARGET_NAME Threads::Threads PACKAGE_NAME Threads PACKAGE_ARGS REQUIRED) |
| 191 |
endif () |
| 192 |
endif () |
| 193 |
|
| 194 |
# configure usage of Boost |
| 195 |
if (REQUIRED_BOOST_COMPONENTS) |
| 196 |
set(BOOST_ARGS REQUIRED COMPONENTS ${REQUIRED_BOOST_COMPONENTS}) |
| 197 |
use_package(TARGET_NAME Boost::boost PACKAGE_NAME Boost PACKAGE_ARGS "${BOOST_ARGS}") |
| 198 |
foreach (COMPONENT ${REQUIRED_BOOST_COMPONENTS}) |
| 199 |
use_package(TARGET_NAME Boost::${COMPONENT} PACKAGE_NAME Boost PACKAGE_ARGS "${BOOST_ARGS}") |
| 200 |
endforeach () |
| 201 |
endif () |
| 202 |
|
| 203 |
# configure required libraries for std::filesystem |
| 204 |
option(USE_STANDARD_FILESYSTEM |
| 205 |
"uses std::filesystem; if disabled Bash completion for files and directories and archiving utilities are disabled" ON) |
| 206 |
if (USE_STANDARD_FILESYSTEM) |
| 207 |
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_STANDARD_FILESYSTEM) |
| 208 |
use_standard_filesystem() |
| 209 |
else () |
| 210 |
message( |
| 211 |
WARNING |
| 212 |
"The use of std::filesystem has been disabled. Bash completion for files and directories will not work and archiving utilities are disabled." |
| 213 |
) |
| 214 |
endif () |
| 215 |
|
| 216 |
# configure usage of libarchive |
| 217 |
option(USE_LIBARCHIVE "uses libarchive; if disabled archiving utilities will not be available" OFF) |
| 218 |
if (USE_LIBARCHIVE) |
| 219 |
if (NOT USE_STANDARD_FILESYSTEM) |
| 220 |
message(FATAL_ERROR "Unable to use USE_LIBARCHIVE without USE_STANDARD_FILESYSTEM.") |
| 221 |
endif () |
| 222 |
# use either the CMake find module or the pkg-config file to find libarchive; the latter is preferred as the CMake find |
| 223 |
# module does not take transitive dependencies into account and thus breaks static linking |
| 224 |
option(USE_LIBARCHIVE_VIA_FIND_MODULE "uses the CMake find module to find libarchive" OFF) |
| 225 |
if (USE_LIBARCHIVE_VIA_FIND_MODULE) |
| 226 |
use_package(TARGET_NAME LibArchive::LibArchive PACKAGE_NAME LibArchive) |
| 227 |
else () |
| 228 |
use_pkg_config_module(PKG_CONFIG_MODULES "libarchive" TARGET_NAME LibArchive::LibArchive VISIBILITY PRIVATE) |
| 229 |
endif () |
| 230 |
list(APPEND HEADER_FILES io/archive.h) |
| 231 |
list(APPEND SRC_FILES io/archive.cpp) |
| 232 |
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_LIBARCHIVE) |
| 233 |
else () |
| 234 |
set(EXCLUDED_FILES io/archive.h io/archive.cpp) |
| 235 |
endif () |
| 236 |
|
| 237 |
# configure whether escape codes should be enabled by default |
| 238 |
option(ENABLE_ESCAPE_CODES_BY_DEAULT "enables usage of escape codes by default" ON) |
| 239 |
if (ENABLE_ESCAPE_CODES_BY_DEAULT) |
| 240 |
set_property( |
| 241 |
SOURCE application/argumentparser.cpp io/ansiescapecodes.cpp tests/argumentparsertests.cpp |
| 242 |
APPEND |
| 243 |
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_ESCAPE_CODES_ENABLED_BY_DEFAULT) |
| 244 |
else () |
| 245 |
message(STATUS "Disabling use of escape codes by default.") |
| 246 |
endif () |
| 247 |
|
| 248 |
# configure use of thread_local |
| 249 |
option(ENABLE_THREAD_LOCAL "enables use of Thread-Local Storage" ON) |
| 250 |
if (NOT ENABLE_THREAD_LOCAL) |
| 251 |
set_property( |
| 252 |
SOURCE conversion/stringconversion.cpp |
| 253 |
APPEND |
| 254 |
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_NO_THREAD_LOCAL) |
| 255 |
endif () |
| 256 |
|
| 257 |
# configure use of platform-specific APIs for optimizing CopyHelper |
| 258 |
option(USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER |
| 259 |
"enables use of platform-specific APIs for optimizing CopyHelper" OFF) |
| 260 |
if (USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER) |
| 261 |
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER) |
| 262 |
endif () |
| 263 |
|
| 264 |
# configure tests for verification helpers which require OpenSSL |
| 265 |
use_crypto( |
| 266 |
LIBRARIES_VARIABLE |
| 267 |
"TEST_LIBRARIES" |
| 268 |
PACKAGES_VARIABLE |
| 269 |
"TEST_PACKAGES" |
| 270 |
PACKAGE_ARGS |
| 271 |
1.1.0 |
| 272 |
OPTIONAL) |
| 273 |
if ("OpenSSL::Crypto" IN_LIST "TEST_LIBRARIES") |
| 274 |
message(STATUS "Testing verification using OpenSSL crypto library") |
| 275 |
set_property( |
| 276 |
SOURCE tests/misctests.cpp |
| 277 |
APPEND |
| 278 |
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_HAS_OPENSSL_CRYPTO) |
| 279 |
else () |
| 280 |
message(WARNING "Unable to test verification helper of setup tools because OpenSSL crypto library is not available.") |
| 281 |
endif () |
| 282 |
|
| 283 |
# apply basic configuration |
| 284 |
include(BasicConfig) |
| 285 |
|
| 286 |
# set the package name of c++utilities itself as it is used in the config module template |
| 287 |
set(CPP_UTILITIES_PACKAGE "${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}") |
| 288 |
|
| 289 |
# include further modules to apply configuration |
| 290 |
include(WindowsResources) |
| 291 |
include(LibraryTarget) |
| 292 |
include(TestTarget) |
| 293 |
include(Doxygen) |
| 294 |
include(ConfigHeader) |