1# #################################################################################################
2# ALib.cmake - CMake file for projects using ALib
4# Copyright 2015-2024 A-Worx GmbH, Germany
5# Published under 'Boost Software License' (a free software license, see LICENSE.txt)
8# CMake file for projects using ALib
9# #################################################################################################
11# --------------------------------------------------------------------------------------------------
13# --------------------------------------------------------------------------------------------------
14 cmake_minimum_required( VERSION 3.20.0 )
17 if (tmp_alib_included_marker)
18 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
21 set(tmp_alib_included_marker "1")
24 # Infer base directory from this script's location
25 if( NOT DEFINED ALIB_BASE_DIR )
26 set( temp "${CMAKE_CURRENT_LIST_DIR}/../.." )
27 get_filename_component(temp ${temp} ABSOLUTE)
28 set( ALIB_BASE_DIR ${temp} CACHE PATH
29 "The base path to ALib containing source code, project files, tools, docs, etc.")
34 if (NOT EXISTS "${ALIB_BASE_DIR}/src/alib" )
35 message( FATAL_ERROR "ALib.cmake: Can't read sources in ALIB_BASE_DIR= ${ALIB_BASE_DIR}" )
40 # build type defaults to "Debug"
41 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
42 set( CMAKE_BUILD_TYPE "Debug" )
45 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
48 # include tool functions
49 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
51# --------------------------------------------------------------------------------------------------
52# ALib Module Dependency Resolution
53# --------------------------------------------------------------------------------------------------
55 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
57# --------------------------------------------------------------------------------------------------
59# The variables are only set, if not already predefined prior to invoking this script.
60# --------------------------------------------------------------------------------------------------
62set( ALIB_VERSION "2412R0" CACHE STRING
63 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
65set( ALIB_VERSION_NO "2412" )
66set( ALIB_VERSION_REV "0" )
68if( NOT DEFINED ALIB_DEBUG )
69 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
70 set( defaultALIB_DEBUG "On" )
72 set( defaultALIB_DEBUG "Off" )
75 set( defaultALIB_DEBUG ALIB_DEBUG )
78set( ALIB_DEBUG ${defaultALIB_DEBUG} CACHE BOOL
79 "Enable/disable ALib debug code. Defaults to true with debug builds, otherwise to false." )
82if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
83 if( NOT DEFINED ALIB_DEBUG_GLIB )
84 set( ALIB_DEBUG_GLIB "Off" CACHE BOOL
85 "Defaults to false. If true, compiler symbols '_GLIBCXX_DEBUG', '_GLIBCXX_DEBUG_PEDANTIC' and '_GLIBCPP_CONCEPT_CHECKS' are set." )
89 if( NOT DEFINED ALIB_COVERAGE_COMPILE )
90 set( ALIB_COVERAGE_COMPILE "Off" CACHE BOOL
91 "Defaults to false. If true, option --coverage is added to GNU compiler command line.")
94 if ( $ENV{CLION_IDE} )
95 set( tmpDefault "On" )
97 set( tmpDefault "Off" )
100 set( ALIB_GDB_PP_SUPPRESS_CHILDREN ${tmpDefault} CACHE BOOL
101 "Defaults to false except if CMake is run from within JetBrains CLion. If true, a corresponding symbol gets set with debug builds which is detected by GDB pretty printer scripts provided with ALib.")
103 set( ALIB_GDB_PP_FIND_POINTER_TYPES ${tmpDefault} CACHE BOOL
104 "Defaults to false. If true, a corresponding symbol gets set with debug builds which is detected by GDB pretty printer scripts provided with ALib.")
107if( NOT DEFINED ALIB_PRECOMPILED_HEADER )
108 set( ALIB_PRECOMPILED_HEADER "Off" CACHE BOOL
109 "If on, header file ’alib/alib_precompile.hpp' will included some default headers, depending on the selected modules. Defaults to off." )
113if( NOT DEFINED ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH )
114 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH "Off" CACHE BOOL
115 "If true, no thread library is searched and bound to the target. If false, a thread library is searched and bound even if module Threads is not included. This is to allow debug assertions with multi-threaded use of a single-threaded ALib distribution." )
119if( NOT DEFINED ALIB_CMAKE_VERBOSE )
120 set( ALIB_CMAKE_VERBOSE "Off" CACHE BOOL
121 "If true, CMake generation runs will provide a detailed report." )
125if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
126 if( NOT DEFINED ALIB_DEBUG_ALLOCATIONS )
127 set( ALIB_DEBUG_ALLOCATIONS "Off" CACHE BOOL
128 "Adds allocation debug mechanics with lang::HeapAllocator and ALib Monomem allocators. Defaults to false." )
133if( "SINGLETONS" IN_LIST ALIB_DISTRIBUTION )
135 set( platformDefaultFor_SINGLETON_MAPPED "On" )
137 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
139 if( NOT DEFINED ALIB_FEAT_SINGLETON_MAPPED )
140 set( ALIB_FEAT_SINGLETON_MAPPED ${platformDefaultFor_SINGLETON_MAPPED} CACHE BOOL
141 "Defaults to true on Windows OS, which then selects code to implement class Singleton to work with multiple data segments, as imposed by the use of Windows DLLs.")
145if( "BITBUFFER" IN_LIST ALIB_DISTRIBUTION )
146 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
147 if( NOT DEFINED ALIB_DEBUG_ARRAY_COMPRESSION )
148 set( ALIB_DEBUG_ARRAY_COMPRESSION "On" CACHE BOOL
149 "If true, in debug compilations, compressed arrays are read back to check if result is same. Defaults to true." )
154if( "CONTAINERS" IN_LIST ALIB_DISTRIBUTION )
155 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
156 if( NOT DEFINED ALIB_DEBUG_CONTAINERS )
157 set( ALIB_DEBUG_CONTAINERS "Off" CACHE BOOL
158 "Adds debug features to module ALib Containers. Defaults to false." )
163if( "MONOMEM" IN_LIST ALIB_DISTRIBUTION )
164 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
165 if( NOT DEFINED ALIB_DEBUG_MONOMEM )
166 set( ALIB_DEBUG_MONOMEM "Off" CACHE BOOL
167 "Adds consistency checks and collection of statistics with module ALib Monomem. Defaults to false." )
173if( "BOXING" IN_LIST ALIB_DISTRIBUTION )
174 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
175 set( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS "Off" CACHE BOOL
176 "If true, any C++ integral type will be boxed to its original type. If false (the default) all types are boxed to type 'integer', respectively / 'uinteger' and only this can be unboxed.")
179 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
180 set( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS "Off" CACHE BOOL
181 "If true, any C++ character type will be boxed to its original type. If false (the default) all types are boxed to type 'character' and only this can be unboxed.")
184 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
185 set( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS "Off" CACHE BOOL
186 "If true, type float will be boxed as float. If false (the default) float will be boxed as double and cannot be unboxed.")
189 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
190 if( NOT DEFINED ALIB_DEBUG_BOXING )
191 set( ALIB_DEBUG_BOXING "Off" CACHE BOOL
192 "Adds collection of statistics and debug methods to module ALib Boxing. Defaults to false." )
197if( "CHARACTERS" IN_LIST ALIB_DISTRIBUTION )
199 set( defaultALIB_CHARACTERS_WIDE "On" )
200 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
202 set( defaultALIB_CHARACTERS_WIDE "Off" )
203 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
206 if( NOT DEFINED ALIB_CHARACTERS_WIDE )
207 set( ALIB_CHARACTERS_WIDE ${defaultALIB_CHARACTERS_WIDE} CACHE BOOL
208 "If false, the type 'alib::character' is 1-byte wide, otherwise it has the width given with ALIB_CHARACTERS_SIZEOF_WCHAR. Default value depends on platform preference.")
211 if( NOT DEFINED ALIB_CHARACTERS_SIZEOF_WCHAR )
212 set( ALIB_CHARACTERS_SIZEOF_WCHAR ${defaultALIB_CHARACTERS_SIZEOF_WCHAR} CACHE STRING
213 "The width of wide characters, maybe 2 or 4. Default value depends on platform/compiler preference.")
217if( "STRINGS" IN_LIST ALIB_DISTRIBUTION )
218 if( NOT DEFINED ALIB_FEAT_BOOST_REGEX )
219 set( ALIB_FEAT_BOOST_REGEX "Off" CACHE BOOL
220 "Defaults to false. If true, activates ALib classes that use boost regular expressions, for example strings::util::RegexMatcher. The corresponding boost library is searched and added to CMake variable ALIB_EXTERNAL_LIBS.")
223 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
224 if( NOT DEFINED ALIB_DEBUG_STRINGS )
225 set( ALIB_DEBUG_STRINGS "Off" CACHE BOOL
226 "Defaults to false. Adds consistency checks to ALib string classes. Useful when developing code to manipulate strings externally, i.e T_Append to specializations.")
231if( "THREADS" IN_LIST ALIB_DISTRIBUTION )
232 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
233 if( NOT DEFINED ALIB_DEBUG_CRITICAL_SECTIONS )
234 set( ALIB_DEBUG_CRITICAL_SECTIONS "Off" CACHE BOOL
235 "Defaults to true. Activates lang::DbgCriticalSections with debug compilations.")
241if( "CAMP" IN_LIST ALIB_DISTRIBUTION )
242 if( NOT DEFINED ALIB_RESOURCES_OMIT_DEFAULTS )
243 set( ALIB_RESOURCES_OMIT_DEFAULTS "Off" CACHE BOOL
244 "If true, ALib modules do not add default versions of resource strings. See section 'Bootstrapping' of ALib Programmer's Manual for more information. Defaults to false.")
247 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
248 if( NOT DEFINED ALIB_DEBUG_RESOURCES )
249 set( ALIB_DEBUG_RESOURCES "Off" CACHE BOOL
250 "Adds collection of statistics and resource export with module ALib Resources. Defaults to false." )
256if( "FILES" IN_LIST ALIB_DISTRIBUTION )
257 if( NOT DEFINED ALIB_FILES_FORCE_STD_SCANNER )
258 set( ALIB_FILES_FORCE_STD_SCANNER "Off" CACHE BOOL
259 "If true, file scanning of ALib camp 'Files' falls back to a basic implementation using C++ library std::filesystem.")
263if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
265 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
266 set( defaultALOX_DBG_LOG "On" )
268 set( defaultALOX_DBG_LOG "Off" )
270 if( NOT DEFINED ALOX_DBG_LOG )
271 set( ALOX_DBG_LOG ${defaultALOX_DBG_LOG} CACHE BOOL
272 "Enable/disable debug log statements. Defaults to true with debug builds, otherwise to false." )
275 if( NOT DEFINED ALOX_DBG_LOG_CI )
276 set( ALOX_DBG_LOG_CI "On" CACHE BOOL
277 "Defaults to true. If set, caller information is used with debug log statements." )
280 if( NOT DEFINED ALOX_REL_LOG )
281 set( ALOX_REL_LOG "On" CACHE BOOL
282 "Enable/disable release log statements. Defaults to true." )
285 if( NOT DEFINED ALOX_REL_LOG_CI )
286 set( ALOX_REL_LOG_CI "Off" CACHE BOOL
287 "Defaults to false. If set, caller information is used even with release log statements (and even in release builds!)" )
291# --------------------------------------------------------------------------------------------------
293# --------------------------------------------------------------------------------------------------
298 LIST( APPEND moduleList "EXPRESSIONS;CLI;ALOX" )
299 LIST( APPEND moduleList "CONFIGURATION;CAMP;CONTAINERS" )
300 LIST( APPEND moduleList "THREADS;THREADMODEL;FILES" )
301 LIST( APPEND moduleList "ENUMS;BOXING;STRINGS" )
302 LIST( APPEND moduleList "SINGLETONS;MONOMEM;BITBUFFER;CHARACTERS;TIME" )
303 FOREACH( module IN LISTS moduleList )
304 IF( module IN_LIST ALIB_DISTRIBUTION )
305 list( APPEND ALIB_SYMBOLS "ALIB_${module}" )
312 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
314 if ( ${ALIB_DEBUG_GLIB} )
315 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
316 "_GLIBCXX_DEBUG_PEDANTIC"
317 "_GLIBCPP_CONCEPT_CHECKS" )
319 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
320 "_GLIBCXX_DEBUG_PEDANTIC"
321 "_GLIBCPP_CONCEPT_CHECKS" )
324 if ( ${ALIB_GDB_PP_SUPPRESS_CHILDREN} )
325 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
327 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
329 if ( ${ALIB_GDB_PP_FIND_POINTER_TYPES} )
330 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_FIND_POINTER_TYPES" )
332 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_FIND_POINTER_TYPES" )
338if ( ${ALIB_PRECOMPILED_HEADER} )
339 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
341 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
345if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
346 if ( ALIB_DEBUG_ALLOCATIONS )
347 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ALLOCATIONS" )
349 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ALLOCATIONS" )
354if( "SINGLETONS" IN_LIST ALIB_DISTRIBUTION )
355 if (NOT platformDefaultFor_SINGLETON_MAPPED STREQUAL ALIB_FEAT_SINGLETON_MAPPED)
356 if ( ALIB_FEAT_SINGLETON_MAPPED )
357 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED" )
359 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
362 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
366if( "BITBUFFER" IN_LIST ALIB_DISTRIBUTION )
367 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
368 if ( ALIB_DEBUG_ARRAY_COMPRESSION )
369 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=1" )
371 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=0" )
376if( "BOXING" IN_LIST ALIB_DISTRIBUTION )
377 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
378 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
380 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
382 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
383 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
385 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
387 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
388 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
390 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
392 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
393 if( ALIB_DEBUG_BOXING )
394 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
396 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
401if( "CHARACTERS" IN_LIST ALIB_DISTRIBUTION )
402 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
403 if ( ALIB_CHARACTERS_WIDE )
404 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
406 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
409 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
412 if (NOT defaultALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL ALIB_CHARACTERS_SIZEOF_WCHAR)
413 if ( NOT (ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" OR ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "4") )
414 message( FATAL_ERROR "Value of ALIB_CHARACTERS_SIZEOF_WCHAR must be 2 or 4" )
417 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
419 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
424if( "CONTAINERS" IN_LIST ALIB_DISTRIBUTION )
425 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
426 if ( ALIB_DEBUG_CONTAINERS )
427 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CONTAINERS" )
429 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CONTAINERS" )
434if( "THREADS" IN_LIST ALIB_DISTRIBUTION )
435 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
436 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
437 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
439 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
444if( "MONOMEM" IN_LIST ALIB_DISTRIBUTION )
445 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
446 if ( ALIB_DEBUG_MONOMEM )
447 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MONOMEM" )
449 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MONOMEM" )
454if( "STRINGS" IN_LIST ALIB_DISTRIBUTION )
455 if ( ALIB_FEAT_BOOST_REGEX )
456 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
458 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
461 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
462 if ( ALIB_DEBUG_STRINGS )
463 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
465 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
470if( "CAMP" IN_LIST ALIB_DISTRIBUTION )
472 if( ALIB_RESOURCES_OMIT_DEFAULTS )
473 list( APPEND ALIB_SYMBOLS "ALIB_RESOURCES_OMIT_DEFAULTS" )
475 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_RESOURCES_OMIT_DEFAULTS" )
478 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
479 if( ALIB_DEBUG_RESOURCES )
480 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
482 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
487if( "FILES" IN_LIST ALIB_DISTRIBUTION )
488 if ( ALIB_FILES_FORCE_STD_SCANNER )
489 list( APPEND ALIB_SYMBOLS "ALIB_FILES_FORCE_STD_SCANNER" )
491 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FILES_FORCE_STD_SCANNER" )
495if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
497 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
498 if( NOT ALOX_DBG_LOG )
499 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
501 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
504 if ( NOT ${ALOX_DBG_LOG_CI} )
505 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
507 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
510 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
511 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
514 if ( NOT ALOX_REL_LOG )
515 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
517 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
519 if ( ALOX_REL_LOG_CI )
520 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
522 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
528# --------------------------------------------------------------------------------------------------
529# ALib Source File Definition
530# --------------------------------------------------------------------------------------------------
531include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
534# --------------------------------------------------------------------------------------------------
536# --------------------------------------------------------------------------------------------------
537if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
538 find_package(Threads)
540 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
541 if(CMAKE_USE_PTHREADS_INIT)
542 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
546 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
549if ( ${ALIB_FEAT_BOOST_REGEX} )
550 set(Boost_USE_STATIC_LIBS "On" CACHE BOOL "Link boost statically" )
551 if( "THREADS" IN_LIST ALIB_DISTRIBUTION )
552 set(Boost_USE_MULTITHREADED "On" CACHE BOOL "Use multi-threaded version of boost")
554 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
557 find_package( Boost CONFIG REQUIRED COMPONENTS regex )
560 list( APPEND ALIB_EXTERNAL_LIBS Boost::regex )
561 if(${Boost_USE_STATIC_LIBS})
562 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost static libraries")
564 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
567 MESSAGE("Attention: Boost::regex requested, but library not found!")
572 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
575# lib math, needed with GCC (suddenly, we don't really know why, added 221205)
578 list( APPEND ALIB_EXTERNAL_LIBS "m")
582# --------------------------------------------------------------------------------------------------
583# A-Worx compiler features and flags
584# --------------------------------------------------------------------------------------------------
586# Set minimum required standard C++ 17
587list( APPEND ALIB_COMPILER_FEATURES "cxx_std_17" )
590# if "ALIB_SUPPRESS_COMPILER_WARNINGS" is set prior to invoking this script, this entry is removed
591# and nothing is added.
592if ("ALIB_SUPPRESS_COMPILER_WARNINGS" IN_LIST ALIB_COMPILER_WARNINGS)
593 LIST( REMOVE_ITEM ALIB_COMPILER_WARNINGS "ALIB_SUPPRESS_COMPILER_WARNINGS" )
595 if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
596 # add -H to generate output "!/x" for use of precompiled header
597 list( APPEND ALIB_COMPILER_WARNINGS "-Wall" )
598 list( APPEND ALIB_COMPILER_WARNINGS "-Wextra" )
599 list( APPEND ALIB_COMPILER_WARNINGS "-Werror" )
600 #list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
601 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-psabi" )
602 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
604 # this was "suddenly" needed with GCC 13.2.1 with release compilation
605 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
607 # add coverage flags to GCC
608 if( ${ALIB_COVERAGE_COMPILE} )
609 list( APPEND ALIB_COMPILER_OPTIONS "--coverage" )
610 list( APPEND ALIB_LINKER_OPTIONS "--coverage" )
613 # force unicode (needed for mingw)
615 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
616 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
617 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
621 # Clang: We are using -Weverything, although this is not recommended. We think it should be
622 # recommended. ALib for example does not use old-style casts and explicitly cast each
623 # and every type change! The benefit for ALib users is that ALib code can be used in very
624 # strict build environments without using special warning flags.
625 # Of course, some very obvious things like C++98 compatibility warnings have to be
626 # removed explicitly:
627 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
628 list( APPEND ALIB_COMPILER_WARNINGS "-pedantic" )
629 list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
630 list( APPEND ALIB_COMPILER_WARNINGS "-Weverything" )
631 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat" )
632 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat-pedantic" )
633 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-global-constructors" )
634 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-exit-time-destructors" )
635 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-padded" )
636 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-weak-vtables" )
637 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-documentation-unknown-command" )
638 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
639 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-covered-switch-default" )
641 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
642 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
646 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" )
647 list( APPEND ALIB_COMPILER_WARNINGS "/W4" )
648 list( APPEND ALIB_COMPILER_WARNINGS "/WX" )
649 list( APPEND ALIB_COMPILER_WARNINGS "/EHsc" )
651 #! NEVER TESTED YET !
652 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
653 list( APPEND ALIB_COMPILER_WARNINGS "" )
658# --------------------------------------------------------------------------------------------------
659# A-Worx linker features and flags
660# --------------------------------------------------------------------------------------------------
662 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
664 list( APPEND ALIB_LINKER_OPTIONS "" )
668# -------------------------------------------------------------------------------------------------
669# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
670# -------------------------------------------------------------------------------------------------
671if ( NOT ALIB_LIBRARY_FILENAME )
673 set( ALIB_LIBRARY_FILENAME "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
676 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
677 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBG )
679 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}RELDBG )
681 if ( NOT ${ALIB_DEBUG_CRITICAL_SECTIONS} )
682 list( FIND ALIB_DISTRIBUTION "THREADS" idx )
684 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_NOCSDBG )
687 if ( ${ALIB_DEBUG_ALLOCATIONS} )
688 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DALLOC )
691 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
692 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBGREL )
697 if ( ${ALIB_FEAT_SINGLETON_MAPPED} )
698 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MS )
700 if ( ${ALIB_CHARACTERS_WIDE} )
701 if ( ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" )
702 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC2 )
704 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC4 )
707 if ( ${ALIB_FEAT_BOOST_REGEX} )
708 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BREGEX )
710 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS} )
711 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJCHARS )
713 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_FLOATS} )
714 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJFLOATS )
716 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS} )
717 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJINTS )
722 # Add all module's names, prefixed by "DBG" if special debug flag is set
724 FOREACH(modName IN LISTS ALIB_DISTRIBUTION)
726 # MONOMEM debug mode?
727 IF( modName STREQUAL "MONOMEM" )
728 if ( ALIB_DEBUG_MONOMEM AND ${ALIB_DEBUG} )
729 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGMONOMEM )
731 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MONOMEM )
734 # CONTAINERS debug mode?
735 ELSEIF( modName STREQUAL "CONTAINERS" )
736 if ( ALIB_DEBUG_CONTAINERS AND ${ALIB_DEBUG} )
737 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGCONTAINERS )
739 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CONTAINERS )
742 # STRINGS debug mode?
743 ELSEIF( modName STREQUAL "STRINGS" )
744 if ( ALIB_DEBUG_STRINGS AND ${ALIB_DEBUG} )
745 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
747 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
750 # RESOURCES debug mode?
751 ELSEIF( modName STREQUAL "CAMP" )
752 if ( ALIB_DEBUG_RESOURCES AND ${ALIB_DEBUG} )
753 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGCAMP )
755 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CAMP )
758 # ALOX: add non-default feature s
759 ELSEIF( modName STREQUAL "ALOX" )
760 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ALOX )
761 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT ALOX_DBG_LOG) )
762 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NDL )
765 if ( NOT ALOX_REL_LOG )
766 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
769 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
774 # Remove all dependent modules from the name, which are not added in a dbg version:
775 list( FIND ALIB_DISTRIBUTION "BOXING" idx )
777 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
778 STRING(REPLACE "_CHARACTERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
781 list( FIND ALIB_DISTRIBUTION "STRINGS" idx )
783 STRING(REPLACE "_CHARACTERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
786 list( FIND ALIB_DISTRIBUTION "THREADS" idx )
788 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
789 STRING(REPLACE "_TIME" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
792 list( FIND ALIB_DISTRIBUTION "ENUMS" idx )
794 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
795 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
798 list( FIND ALIB_DISTRIBUTION "BITBUFFER" idx )
800 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
801 STRING(REPLACE "_ENUMS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
804 list( FIND ALIB_DISTRIBUTION "THREADMODEL" idx )
806 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
807 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
808 STRING(REPLACE "_ENUMS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
809 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
810 STRING(REPLACE "_THREADS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
813 list( FIND ALIB_DISTRIBUTION "CAMP" idx )
815 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
816 STRING(REPLACE "_ENUMS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
817 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
818 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
819 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
820 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
821 STRING(REPLACE "_TIME" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
824 list( FIND ALIB_DISTRIBUTION "CONFIGURATION" idx )
826 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
829 list( FIND ALIB_DISTRIBUTION "ALOX" idx )
831 STRING(REPLACE "_CONFIGURATION" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
834 list( FIND ALIB_DISTRIBUTION "EXPRESSIONS" idx )
836 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
839 list( FIND ALIB_DISTRIBUTION "FILES" idx )
841 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
844 list( FIND ALIB_DISTRIBUTION "CLI" idx )
846 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
849 endif() # not all modules
853# -------------------------------------------------------------------------------------------------
854# Display result summary
855# -------------------------------------------------------------------------------------------------
856message( "ALib CMake Configuration:" )
858 message( " Module Selection : ${ALIB_DISTRIBUTION}" )
860 message( " Module Selection : All (${ALIB_DISTRIBUTION})" )
863 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
864 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
866IF( NOT ALIB_CMAKE_VERBOSE )
867 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
870 message( " Source folder: ${ALIB_SOURCE_DIR}" )
872 LIST( APPEND result ${ALIB_INCLUDE_FILES} )
873 LIST( APPEND result ${ALIB_SOURCE_FILES} )
875 LIST( LENGTH result length)
876 message( "\n List of header and source files (${length} items):" )
877 FOREACH( entry IN LISTS result )
878 STRING(REPLACE "${ALIB_SOURCE_DIR}/" "" entry ${entry} )
879 message( " ${entry}" )
883 LIST( APPEND result ${ALIB_SYMBOLS} )
885 LIST( LENGTH result length)
886 message( "\n Compiler definitions (${length} items):" )
887 FOREACH( entry IN LISTS result )
888 message( " ${entry}" )
893 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
895 LIST( LENGTH result length)
896 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
897 FOREACH( entry IN LISTS result )
898 message( " ${entry}" )
902 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
904 LIST( LENGTH result length)
905 message( "\n Compiler warnings (${length} items):" )
906 FOREACH( entry IN LISTS result )
907 message( " ${entry}" )
911 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
913 LIST( LENGTH result length)
914 message( "\n Compiler flags (${length} items):" )
915 FOREACH( entry IN LISTS result )
916 message( " ${entry}" )
920 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
922 LIST( LENGTH result length)
923 message( "\n Compiler features (${length} items):" )
924 FOREACH( entry IN LISTS result )
925 message( " ${entry}" )
929 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
931 LIST( LENGTH result length)
932 message( "\n External libraries (${length} items):" )
933 FOREACH( entry IN LISTS result )
934 message( " ${entry}" )
938 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
940 LIST( LENGTH result length)
941 message( "\n Linker flags (${length} items):" )
942 FOREACH( entry IN LISTS result )
943 message( " ${entry}" )
950# -------------------------------------------------------------------------------------------------
951# ALibSetCompilerAndLinker(target)
953# Simple CMake function that sets
955# - ALIB_COMPILER_FEATURES
956# - ALIB_COMPILER_OPTIONS
957# - ALIB_COMPILER_WARNINGS
958# - ALIB_LINKER_OPTIONS
960# In addition, postion independent compile (-fPic) is enabled (for static libraries its default
962# -------------------------------------------------------------------------------------------------
963function( ALibSetCompilerAndLinker target )
966 target_compile_features ( ${target} PRIVATE ${ALIB_COMPILER_FEATURES} )
967 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_OPTIONS} )
968 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_WARNINGS} )
969 set_property ( TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON )
970 target_include_directories( ${target} PUBLIC ${ALIB_SOURCE_DIR} )
973 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
976 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
977 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
979 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
980 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
985# -------------------------------------------------------------------------------------------------
987# -------------------------------------------------------------------------------------------------
988function( ALibAddStaticLibrary )
990 add_library ( ALib_StaticLib STATIC ${ALIB_INCLUDE_FILES} ${ALIB_SOURCE_FILES} )
991 ALibSetCompilerAndLinker ( ALib_StaticLib )
992 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
995function( ALibAddSharedLibrary )
996 add_library ( ALib_SharedLib SHARED ${ALIB_INCLUDE_FILES} ${ALIB_SOURCE_FILES} )
997 ALibSetCompilerAndLinker ( ALib_SharedLib )
998 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1001 target_compile_definitions ( ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
1005# --------------------------------------------------------------------------------------------------
1006# CMake debugging Uncomment a line to have CMake summarize information
1007# --------------------------------------------------------------------------------------------------
1008#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} INCLUDE_DIRECTORIES )
1009#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} SOURCES )
1010#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_DEFINITIONS )
1011#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_OPTIONS )
1012#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_FEATURES )
1013#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} AUTOUIC_OPTIONS )
1014#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} POSITION_INDEPENDENT_CODE )
1015#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} CONTAINER_SIZE_REQUIRED )
1016#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} LIB_VERSION )
1018#set(CMAKE_VERBOSE_MAKEFILE ON)