2023-07-23 20:57:35 +02:00
|
|
|
cmake_minimum_required(VERSION 3.17.0 FATAL_ERROR)
|
2015-12-05 22:47:49 +01:00
|
|
|
|
2019-07-20 16:06:37 +02:00
|
|
|
project(c++utilities)
|
|
|
|
|
2015-12-08 08:32:57 +01:00
|
|
|
# add project files
|
|
|
|
set(HEADER_FILES
|
|
|
|
application/argumentparser.h
|
|
|
|
application/commandlineutils.h
|
|
|
|
application/fakeqtconfigarguments.h
|
|
|
|
application/global.h
|
|
|
|
chrono/datetime.h
|
|
|
|
chrono/period.h
|
|
|
|
chrono/timespan.h
|
2016-08-30 19:59:04 +02:00
|
|
|
chrono/format.h
|
2015-12-08 08:32:57 +01:00
|
|
|
conversion/binaryconversion.h
|
|
|
|
conversion/binaryconversionprivate.h
|
|
|
|
conversion/conversionexception.h
|
|
|
|
conversion/stringconversion.h
|
2017-01-26 22:15:27 +01:00
|
|
|
conversion/stringbuilder.h
|
2015-12-08 08:32:57 +01:00
|
|
|
io/ansiescapecodes.h
|
|
|
|
io/binaryreader.h
|
|
|
|
io/binarywriter.h
|
|
|
|
io/bitreader.h
|
2021-07-15 02:24:28 +02:00
|
|
|
io/buffersearch.h
|
2015-12-08 08:32:57 +01:00
|
|
|
io/copy.h
|
|
|
|
io/inifile.h
|
|
|
|
io/path.h
|
2016-12-19 23:29:54 +01:00
|
|
|
io/nativefilestream.h
|
2017-02-03 00:55:15 +01:00
|
|
|
io/misc.h
|
2019-08-12 20:20:55 +02:00
|
|
|
misc/flagenumclass.h
|
2019-05-13 22:42:17 +02:00
|
|
|
misc/math.h
|
2018-05-03 00:45:50 +02:00
|
|
|
misc/multiarray.h
|
2019-06-10 16:03:27 +02:00
|
|
|
misc/parseerror.h
|
2016-11-13 22:51:09 +01:00
|
|
|
misc/traits.h
|
2018-05-05 23:26:53 +02:00
|
|
|
misc/levenshtein.h
|
2016-02-06 02:52:06 +01:00
|
|
|
tests/testutils.h
|
|
|
|
tests/cppunit.h
|
2019-02-06 17:30:52 +01:00
|
|
|
tests/outputcheck.h)
|
2015-12-08 08:32:57 +01:00
|
|
|
set(SRC_FILES
|
2018-04-28 12:15:34 +02:00
|
|
|
application/argumentparserprivate.h
|
2015-12-08 08:32:57 +01:00
|
|
|
application/argumentparser.cpp
|
|
|
|
application/commandlineutils.cpp
|
|
|
|
application/fakeqtconfigarguments.cpp
|
|
|
|
chrono/datetime.cpp
|
|
|
|
chrono/period.cpp
|
|
|
|
chrono/timespan.cpp
|
|
|
|
conversion/conversionexception.cpp
|
|
|
|
conversion/stringconversion.cpp
|
|
|
|
io/ansiescapecodes.cpp
|
|
|
|
io/binaryreader.cpp
|
|
|
|
io/binarywriter.cpp
|
|
|
|
io/bitreader.cpp
|
2021-07-15 02:24:28 +02:00
|
|
|
io/buffersearch.cpp
|
2015-12-08 08:32:57 +01:00
|
|
|
io/inifile.cpp
|
|
|
|
io/path.cpp
|
2016-12-19 23:29:54 +01:00
|
|
|
io/nativefilestream.cpp
|
2017-02-03 00:55:15 +01:00
|
|
|
io/misc.cpp
|
2019-05-13 22:42:17 +02:00
|
|
|
misc/math.cpp
|
2019-06-10 16:03:27 +02:00
|
|
|
misc/parseerror.cpp
|
2018-05-05 23:26:53 +02:00
|
|
|
misc/levenshtein.cpp
|
2019-02-06 17:30:52 +01:00
|
|
|
tests/testutils.cpp)
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
set(TEST_HEADER_FILES)
|
2016-01-25 23:59:52 +01:00
|
|
|
set(TEST_SRC_FILES
|
|
|
|
tests/cppunit.cpp
|
|
|
|
tests/conversiontests.cpp
|
|
|
|
tests/iotests.cpp
|
2016-01-27 01:01:43 +01:00
|
|
|
tests/chronotests.cpp
|
2016-06-12 01:56:57 +02:00
|
|
|
tests/argumentparsertests.cpp
|
2017-05-08 19:59:29 +02:00
|
|
|
tests/traitstests.cpp
|
2017-08-02 13:29:22 +02:00
|
|
|
tests/mathtests.cpp
|
2019-02-06 17:30:52 +01:00
|
|
|
tests/misctests.cpp)
|
2015-12-08 08:32:57 +01:00
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
set(CMAKE_MODULE_FILES
|
|
|
|
cmake/modules/BasicConfig.cmake
|
2016-08-03 17:33:26 +02:00
|
|
|
cmake/modules/ConfigHeader.cmake
|
2016-04-16 00:50:16 +02:00
|
|
|
cmake/modules/LibraryTarget.cmake
|
2020-06-15 22:28:19 +02:00
|
|
|
cmake/modules/TestUtilities.cmake
|
2016-04-16 00:50:16 +02:00
|
|
|
cmake/modules/TestTarget.cmake
|
2022-10-08 21:55:24 +02:00
|
|
|
cmake/modules/AppUtilities.cmake
|
2016-04-16 00:50:16 +02:00
|
|
|
cmake/modules/AppTarget.cmake
|
|
|
|
cmake/modules/WindowsResources.cmake
|
2016-06-09 22:57:51 +02:00
|
|
|
cmake/modules/TemplateFinder.cmake
|
|
|
|
cmake/modules/Doxygen.cmake
|
|
|
|
cmake/modules/ListToString.cmake
|
2016-07-03 22:36:48 +02:00
|
|
|
cmake/modules/ShellCompletion.cmake
|
2022-12-24 23:15:24 +01:00
|
|
|
cmake/modules/DevelUtilities.cmake
|
2019-02-06 17:30:52 +01:00
|
|
|
cmake/modules/3rdParty.cmake)
|
2016-04-16 00:50:16 +02:00
|
|
|
set(CMAKE_TEMPLATE_FILES
|
2016-09-11 21:02:20 +02:00
|
|
|
cmake/templates/bash-completion.sh.in
|
2016-04-16 00:50:16 +02:00
|
|
|
cmake/templates/Config.cmake.in
|
|
|
|
cmake/templates/config.h.in
|
|
|
|
cmake/templates/desktop.in
|
2018-02-19 19:50:07 +01:00
|
|
|
cmake/templates/appdata.xml.in
|
2016-06-09 22:57:51 +02:00
|
|
|
cmake/templates/doxygen.in
|
2016-09-11 21:02:20 +02:00
|
|
|
cmake/templates/global.h.in
|
2019-06-16 18:23:42 +02:00
|
|
|
cmake/templates/version.h.in
|
2019-02-06 17:30:52 +01:00
|
|
|
cmake/templates/template.pc.in)
|
2023-05-07 21:34:46 +02:00
|
|
|
if (WIN32)
|
2023-05-16 21:39:10 +02:00
|
|
|
list(APPEND CMAKE_TEMPLATE_FILES cmake/templates/windows.rc.in cmake/templates/windows-cli-wrapper.rc.in
|
|
|
|
cmake/templates/cli-wrapper.cpp)
|
2023-05-06 22:48:27 +02:00
|
|
|
endif ()
|
|
|
|
set(EXCLUDED_FILES cmake/templates/cli-wrapper.cpp)
|
2016-04-16 00:50:16 +02:00
|
|
|
|
2019-02-06 17:30:52 +01:00
|
|
|
set(DOC_FILES README.md doc/buildvariables.md doc/testapplication.md)
|
|
|
|
set(EXTRA_FILES tests/calculateoverallcoverage.awk coding-style.clang-format)
|
2016-06-10 22:59:22 +02:00
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
# required to include CMake modules from own project directory
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" "${CMAKE_MODULE_PATH}")
|
|
|
|
|
2015-12-05 22:47:49 +01:00
|
|
|
# meta data
|
|
|
|
set(META_PROJECT_NAME c++utilities)
|
2016-04-16 00:50:16 +02:00
|
|
|
set(META_PROJECT_VARNAME CPP_UTILITIES)
|
2015-12-05 22:47:49 +01:00
|
|
|
set(META_APP_NAME "C++ Utilities")
|
|
|
|
set(META_APP_AUTHOR "Martchus")
|
|
|
|
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
2017-11-04 15:48:47 +01:00
|
|
|
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
|
2017-07-28 19:31:06 +02:00
|
|
|
set(META_VERSION_MAJOR 5)
|
2023-06-17 22:46:55 +02:00
|
|
|
set(META_VERSION_MINOR 24)
|
2024-06-10 00:11:55 +02:00
|
|
|
set(META_VERSION_PATCH 10)
|
2015-12-05 22:47:49 +01:00
|
|
|
|
2016-07-27 18:16:51 +02:00
|
|
|
# find required 3rd party libraries
|
|
|
|
include(3rdParty)
|
2016-08-19 16:13:41 +02:00
|
|
|
use_iconv(AUTO_LINKAGE REQUIRED)
|
2016-07-27 18:16:51 +02:00
|
|
|
|
2018-09-29 18:05:02 +02:00
|
|
|
# configure use of native file buffer and its backend implementation if enabled
|
2023-08-18 22:57:54 +02:00
|
|
|
set(REQUIRED_BOOST_COMPONENTS "")
|
2019-06-16 18:11:30 +02:00
|
|
|
set(USE_NATIVE_FILE_BUFFER_BY_DEFAULT OFF)
|
2019-11-30 17:58:01 +01:00
|
|
|
if (WIN32
|
|
|
|
OR ANDROID
|
|
|
|
OR (UNIX AND NOT APPLE))
|
2019-06-16 18:11:30 +02:00
|
|
|
set(USE_NATIVE_FILE_BUFFER_BY_DEFAULT ON)
|
|
|
|
endif ()
|
|
|
|
option(USE_NATIVE_FILE_BUFFER "enables use of native file buffer, affects ABI" ${USE_NATIVE_FILE_BUFFER_BY_DEFAULT})
|
2018-09-29 18:05:02 +02:00
|
|
|
option(FORCE_BOOST_IOSTREAMS_FOR_NATIVE_FILE_BUFFER "forces use of Boost.Iostreams for native file buffer" OFF)
|
2019-02-06 17:30:52 +01:00
|
|
|
if (USE_NATIVE_FILE_BUFFER)
|
2016-12-19 23:29:54 +01:00
|
|
|
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_NATIVE_FILE_BUFFER)
|
2019-05-04 15:49:41 +02:00
|
|
|
set(NATIVE_FILE_STREAM_IMPL_FILES io/nativefilestream.cpp tests/iotests.cpp)
|
2018-09-29 18:05:02 +02:00
|
|
|
|
|
|
|
# check whether __gnu_cxx::stdio_filebuf is available
|
2019-11-30 17:58:01 +01:00
|
|
|
try_compile(
|
2020-08-11 23:13:09 +02:00
|
|
|
GNU_CXX_STDIO_FILEBUF_AVAILABLE ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/feature_detection/stdio_filebuf.cpp
|
|
|
|
OUTPUT_VARIABLE GNU_CXX_STDIO_FILEBUF_CHECK_LOG)
|
2018-09-29 18:05:02 +02:00
|
|
|
|
|
|
|
# use __gnu_cxx::stdio_filebuf if available or fallback to boost::iostreams::stream_buffer
|
2019-02-06 17:30:52 +01:00
|
|
|
if (GNU_CXX_STDIO_FILEBUF_AVAILABLE AND NOT FORCE_BOOST_IOSTREAMS_FOR_NATIVE_FILE_BUFFER)
|
2018-09-29 18:05:02 +02:00
|
|
|
message(STATUS "Using __gnu_cxx::stdio_filebuf for NativeFileStream")
|
2019-05-04 15:49:41 +02:00
|
|
|
foreach (NATIVE_FILE_STREAM_IMPL_FILE ${NATIVE_FILE_STREAM_IMPL_FILES})
|
2019-11-30 17:58:01 +01:00
|
|
|
set_property(
|
|
|
|
SOURCE ${NATIVE_FILE_STREAM_IMPL_FILE}
|
|
|
|
APPEND
|
|
|
|
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_GNU_CXX_STDIO_FILEBUF)
|
2019-05-04 15:49:41 +02:00
|
|
|
endforeach ()
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2018-09-29 18:05:02 +02:00
|
|
|
message(STATUS "Using boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> for NativeFileStream")
|
2023-08-18 22:57:54 +02:00
|
|
|
list(APPEND REQUIRED_BOOST_COMPONENTS iostreams)
|
2019-05-04 15:49:41 +02:00
|
|
|
foreach (NATIVE_FILE_STREAM_IMPL_FILE ${NATIVE_FILE_STREAM_IMPL_FILES})
|
2020-08-11 23:13:09 +02:00
|
|
|
set_property(
|
|
|
|
SOURCE ${NATIVE_FILE_STREAM_IMPL_FILE}
|
|
|
|
APPEND
|
|
|
|
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_BOOST_IOSTREAMS)
|
2019-05-04 15:49:41 +02:00
|
|
|
endforeach ()
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
|
|
|
else ()
|
2018-09-29 18:05:02 +02:00
|
|
|
message(STATUS "Using std::fstream for NativeFileStream")
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2016-12-19 23:29:54 +01:00
|
|
|
|
2023-08-18 22:57:54 +02:00
|
|
|
# configure use of Boost.Process for launching test applications on Windows
|
|
|
|
if (WIN32)
|
|
|
|
option(USE_BOOST_PROCESS "enables use of Boost.Process to launch test applications" ON)
|
|
|
|
if (USE_BOOST_PROCESS)
|
|
|
|
list(APPEND REQUIRED_BOOST_COMPONENTS filesystem)
|
|
|
|
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_BOOST_PROCESS)
|
|
|
|
list(APPEND PRIVATE_LIBRARIES ws2_32) # needed by Boost.Asio
|
|
|
|
use_package(TARGET_NAME Threads::Threads PACKAGE_NAME Threads PACKAGE_ARGS REQUIRED)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
# configure usage of Boost
|
|
|
|
if (REQUIRED_BOOST_COMPONENTS)
|
|
|
|
set(BOOST_ARGS REQUIRED COMPONENTS ${REQUIRED_BOOST_COMPONENTS})
|
|
|
|
use_package(TARGET_NAME Boost::boost PACKAGE_NAME Boost PACKAGE_ARGS "${BOOST_ARGS}")
|
|
|
|
foreach (COMPONENT ${REQUIRED_BOOST_COMPONENTS})
|
|
|
|
use_package(TARGET_NAME Boost::${COMPONENT} PACKAGE_NAME Boost PACKAGE_ARGS "${BOOST_ARGS}")
|
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
2019-07-02 18:40:25 +02:00
|
|
|
# configure required libraries for std::filesystem
|
2019-08-06 00:02:38 +02:00
|
|
|
option(USE_STANDARD_FILESYSTEM "uses std::filesystem; if disabled Bash completion for files and directories is not working"
|
|
|
|
ON)
|
2019-07-02 18:40:25 +02:00
|
|
|
if (USE_STANDARD_FILESYSTEM)
|
|
|
|
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_STANDARD_FILESYSTEM)
|
|
|
|
use_standard_filesystem()
|
|
|
|
else ()
|
|
|
|
message(WARNING "The use of std::filesystem has been disabled. Bash completion for files and directories will not work.")
|
|
|
|
endif ()
|
2019-06-05 23:49:35 +02:00
|
|
|
|
2017-10-17 00:00:46 +02:00
|
|
|
# configure whether escape codes should be enabled by default
|
|
|
|
option(ENABLE_ESCAPE_CODES_BY_DEAULT "enables usage of escape codes by default" ON)
|
2019-02-06 17:30:52 +01:00
|
|
|
if (ENABLE_ESCAPE_CODES_BY_DEAULT)
|
2020-08-11 23:13:09 +02:00
|
|
|
set_property(
|
|
|
|
SOURCE application/argumentparser.cpp io/ansiescapecodes.cpp tests/argumentparsertests.cpp
|
|
|
|
APPEND
|
|
|
|
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_ESCAPE_CODES_ENABLED_BY_DEFAULT)
|
2019-02-06 17:30:52 +01:00
|
|
|
else ()
|
2017-10-17 00:00:46 +02:00
|
|
|
message(STATUS "Disabling use of escape codes by default.")
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2017-10-17 00:00:46 +02:00
|
|
|
|
2018-06-03 22:14:22 +02:00
|
|
|
# configure use of thread_local
|
|
|
|
option(ENABLE_THREAD_LOCAL "enables use of Thread-Local Storage" ON)
|
2019-02-06 17:30:52 +01:00
|
|
|
if (NOT ENABLE_THREAD_LOCAL)
|
2020-08-11 23:13:09 +02:00
|
|
|
set_property(
|
|
|
|
SOURCE conversion/stringconversion.cpp
|
|
|
|
APPEND
|
|
|
|
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_NO_THREAD_LOCAL)
|
2019-02-06 17:30:52 +01:00
|
|
|
endif ()
|
2018-06-03 22:14:22 +02:00
|
|
|
|
2023-04-23 19:23:47 +02:00
|
|
|
# configure use of platform-specific APIs for optimizing CopyHelper
|
2023-04-29 12:53:46 +02:00
|
|
|
option(USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER
|
|
|
|
"enables use of platform-specific APIs for optimizing CopyHelper" OFF)
|
2023-04-23 19:23:47 +02:00
|
|
|
if (USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER)
|
|
|
|
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER)
|
|
|
|
endif ()
|
|
|
|
|
2016-04-16 00:50:16 +02:00
|
|
|
# include modules to apply configuration
|
|
|
|
include(BasicConfig)
|
|
|
|
include(WindowsResources)
|
|
|
|
include(LibraryTarget)
|
|
|
|
include(TestTarget)
|
2016-06-09 22:57:51 +02:00
|
|
|
include(Doxygen)
|
2016-07-27 21:38:40 +02:00
|
|
|
include(ConfigHeader)
|