1# #################################################################################################
2# ALib.cmake - CMake file for projects using ALib
4# Copyright 2013-2025 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) # For C++ 20 module compilation, V. 3.28 is needed
16 if( NOT DEFINED ALIB_C20_MODULES )
17 set( ALIB_C20_MODULES "Off" CACHE PATH
18 "If on, this script will compile ALib using C++20 Modules. Also, in this case, a symbol of the same name is passed to the compiler.")
21 if( ALIB_C20_MODULES )
22 if ( NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
23 message( FATAL_ERROR "ALib.cmake: ALIB configured to use C++20 modules. As of today, this only works with Clang compiler! (Compiler is ${CMAKE_CXX_COMPILER_ID})" )
25 set(CMAKE_CXX_SCAN_FOR_MODULES ON)
29 if (tmp_alib_included_marker)
30 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
33 set(tmp_alib_included_marker "1")
36 # Infer base directory from this script's location
37 if( NOT DEFINED ALIB_BASE_DIR )
38 set( temp "${CMAKE_CURRENT_LIST_DIR}/../.." )
39 get_filename_component(temp ${temp} ABSOLUTE)
40 set( ALIB_BASE_DIR ${temp} CACHE PATH
41 "The base path to ALib containing source code, project files, tools, docs, etc.")
46 if ( NOT EXISTS "${ALIB_BASE_DIR}/src/ALib.Lang.H"
47 OR NOT EXISTS "${ALIB_BASE_DIR}/src/alib" )
48 message( FATAL_ERROR "ALib.cmake: Can't read sources in ALIB_BASE_DIR \"${ALIB_BASE_DIR}\"" )
52 # Check if CMAKE_CXX_STANDARD is defined
53 if(DEFINED CMAKE_CXX_STANDARD)
54 # Verify if it's at least 20
55 if(CMAKE_CXX_STANDARD LESS 20)
56 message(FATAL_ERROR "ALib compilation needs C++20 standard. Given is: ${CMAKE_CXX_STANDARD}")
59 # Set the C++ standard to 20 if not defined
60 set(CMAKE_CXX_STANDARD 20)
61 set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions
63 set(CMAKE_CXX_STANDARD_REQUIRED ON)
65 # build type defaults to "Debug"
66 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
67 set( CMAKE_BUILD_TYPE "Debug" )
70 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
72 # include tool functions
73 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
76 if( NOT DEFINED ALIB_CLANG_USE_LIBCPP )
77 set( ALIB_CLANG_USE_LIBCPP "Off" )
79 CacheAsBool( ALIB_CLANG_USE_LIBCPP
80 "Defaults to false. If set and Clang is used, function ALibSetCompilerAndLinker sets compiler and linker flags to use LLVM libc++ instead of GNU libstdc++." )
81 if( ALIB_CLANG_USE_LIBCPP )
82 message( "Using LLVM libc++ (instead of GNU libstdc++)" )
85 # Single-threaded compilation?
86 if( NOT DEFINED ALIB_SINGLE_THREADED )
87 set( ALIB_SINGLE_THREADED "Off" )
89 CacheAsBool( ALIB_SINGLE_THREADED
90 "Defaults to false. Disables multi-threading functionality in ALib." )
91 if( ALIB_SINGLE_THREADED )
92 message( "Single-threaded library compilation" )
95# --------------------------------------------------------------------------------------------------
96# ALib Module Dependency Resolution
97# --------------------------------------------------------------------------------------------------
99 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
101# --------------------------------------------------------------------------------------------------
102# ALib Cache Variables
103# The variables are only set, if not already predefined prior to invoking this script.
104# --------------------------------------------------------------------------------------------------
106# --------- ALib Version ---------
108set( ALIB_VERSION "2510R0" CACHE STRING
109 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
111set( ALIB_VERSION_NO "2510" )
112set( ALIB_VERSION_REV "0" )
114# --------- ALIB_DEBUG, ALIB_DEBUG_GLIB, ALIB_COVERAGE_COMPILE ---------
115if( NOT DEFINED ALIB_DEBUG )
116 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
117 set( ALIB_DEBUG "On" )
119 set( ALIB_DEBUG "Off" )
122CacheAsBool( ALIB_DEBUG
123 "Enable/disable ALib debug code. Defaults to true with debug builds, otherwise to false. Can be set with release builds to identify errors in those." )
125if( NOT DEFINED ALIB_DEBUG_GLIB )
126 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
127 set( ALIB_DEBUG_GLIB "Off" )
129 set( ALIB_DEBUG_GLIB "Off" )
132CacheAsBool( ALIB_DEBUG_GLIB
133 "Defaults to false. If true, the compiler-symbols '_GLIBCXX_DEBUG', '_GLIBCXX_DEBUG_PEDANTIC' and '_GLIBCPP_CONCEPT_CHECKS' are set." )
136if( NOT DEFINED ALIB_COVERAGE_COMPILE )
137 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
138 set( ALIB_COVERAGE_COMPILE "Off" )
140 set( ALIB_COVERAGE_COMPILE "Off" )
143CacheAsBool( ALIB_COVERAGE_COMPILE
144 "Defaults to false. If true, option --coverage is added to GNU compiler command line.")
145# --------- ALIB_DEBUG_CRITICAL_SECTIONS, ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH ---------
146if (NOT DEFINED ALIB_DEBUG_CRITICAL_SECTIONS)
147 SetToNot(ALIB_DEBUG_CRITICAL_SECTIONS ALIB_SINGLE_THREADED)
149 AND ALIB_SINGLE_THREADED
150 AND ALIB_DEBUG_CRITICAL_SECTIONS )
151 message( "ALIB_DEBUG_CRITICAL_SECTIONS=On given while ALIB_SINGLE_THREADED=On. Disabling ALIB_DEBUG_CRITICAL_SECTIONS " )
152 Set(ALIB_DEBUG_CRITICAL_SECTIONS "Off")
156 if( ${ALIB_DEBUG_CRITICAL_SECTIONS} )
157 message( "ALIB_DEBUG_CRITICAL_SECTIONS=On given while ALIB_DEBUG=off. Disabling ALIB_DEBUG_CRITICAL_SECTIONS " )
158 Set(ALIB_DEBUG_CRITICAL_SECTIONS "Off")
162CacheAsBool( ALIB_DEBUG_CRITICAL_SECTIONS
163 "Defaults to true unless ALIB_SINGLE_THREADED is set.")
165if ( ${ALIB_DEBUG_CRITICAL_SECTIONS} )
166 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
168 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
172if( NOT DEFINED ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH )
174 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH "On" )
176 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH ALIB_SINGLE_THREADED )
180CacheAsBool( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH
181 "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 Build. Defaults to false." )
184# --------- Others ---------
185if( NOT DEFINED ALIB_PRECOMPILED_HEADER )
186 set( ALIB_PRECOMPILED_HEADER "Off" CACHE BOOL
187 "If on, header file ’alib_precompile.hpp' will included some default headers, depending on the selected modules. Defaults to off." )
189if ( ${ALIB_PRECOMPILED_HEADER} )
190 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
192 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
195if( NOT DEFINED ALIB_CMAKE_VERBOSE )
196 set( ALIB_CMAKE_VERBOSE "Off" CACHE BOOL
197 "If true, CMake generation runs will provide a detailed report." )
201# --------- ALIB_DEBUG_ALLOCATIONS ---------
202if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
203 CacheAsBool( ALIB_DEBUG_ALLOCATIONS
204 "Adds allocation debug mechanics with lang::HeapAllocator and ALib Monomem allocators. Defaults to false." )
208# --------- Per module values ---------
209if( "SINGLETONS" IN_LIST ALibBuild )
211 set( platformDefaultFor_SINGLETON_MAPPED "On" )
213 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
215 if( NOT DEFINED ALIB_FEAT_SINGLETON_MAPPED )
216 set( ALIB_FEAT_SINGLETON_MAPPED ${platformDefaultFor_SINGLETON_MAPPED} CACHE BOOL
217 "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.")
221if( "BITBUFFER" IN_LIST ALibBuild )
222 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
223 if( NOT DEFINED ALIB_DEBUG_ARRAY_COMPRESSION )
224 set( ALIB_DEBUG_ARRAY_COMPRESSION "On" CACHE BOOL
225 "If true, in debug compilations, compressed arrays are read back to check if result is same. Defaults to true." )
230if( "CONTAINERS" IN_LIST ALibBuild )
231 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
232 if( NOT DEFINED ALIB_DEBUG_CONTAINERS )
233 set( ALIB_DEBUG_CONTAINERS "Off" CACHE BOOL
234 "Adds debug features to module ALib Containers. Defaults to false." )
239if( "MONOMEM" IN_LIST ALibBuild )
240 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
241 if( NOT DEFINED ALIB_DEBUG_MEMORY )
242 set( ALIB_DEBUG_MEMORY "Off" CACHE BOOL
243 "Adds consistency checks and collection of statistics with module ALib Monomem. Defaults to false." )
249if( "BOXING" IN_LIST ALibBuild )
250 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
251 set( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS "Off" CACHE BOOL
252 "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.")
255 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
256 set( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS "Off" CACHE BOOL
257 "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.")
260 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
261 set( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS "Off" CACHE BOOL
262 "If true, type float will be boxed as float. If false (the default) float will be boxed as double and cannot be unboxed.")
265 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
266 if( NOT DEFINED ALIB_DEBUG_BOXING )
267 set( ALIB_DEBUG_BOXING "Off" CACHE BOOL
268 "Adds collection of statistics and debug methods to module ALib Boxing. Defaults to false." )
275 set( defaultALIB_CHARACTERS_WIDE "On" )
276 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
278 set( defaultALIB_CHARACTERS_WIDE "Off" )
279 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
282 if( NOT DEFINED ALIB_CHARACTERS_WIDE )
283 set( ALIB_CHARACTERS_WIDE ${defaultALIB_CHARACTERS_WIDE} CACHE BOOL
284 "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.")
287 if( NOT DEFINED ALIB_CHARACTERS_SIZEOF_WCHAR )
288 set( ALIB_CHARACTERS_SIZEOF_WCHAR ${defaultALIB_CHARACTERS_SIZEOF_WCHAR} CACHE STRING
289 "The width of wide characters, maybe 2 or 4. Default value depends on platform/compiler preference.")
293if( "STRINGS" IN_LIST ALibBuild )
294 if( NOT DEFINED ALIB_FEAT_BOOST_REGEX )
295 set( ALIB_FEAT_BOOST_REGEX "Off" CACHE BOOL
296 "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.")
299 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
300 if( NOT DEFINED ALIB_DEBUG_STRINGS )
301 set( ALIB_DEBUG_STRINGS "Off" CACHE BOOL
302 "Defaults to false. Adds consistency checks to ALib string classes. Useful when developing code to manipulate strings externally, i.e AppendableTraits to specializations.")
307if( "CAMP" IN_LIST ALibBuild )
308 if( NOT DEFINED ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
309 set( ALIB_CAMP_OMIT_DEFAULT_RESOURCES "Off" CACHE BOOL
310 "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.")
313 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
314 CacheAsBool( ALIB_DEBUG_RESOURCES
315 "Adds collection of statistics and resource export with module ALib Resources. Defaults to false." )
320if( "FILES" IN_LIST ALibBuild )
321 if( NOT DEFINED ALIB_FILES_FORCE_STD_SCANNER )
322 set( ALIB_FILES_FORCE_STD_SCANNER "Off" CACHE BOOL
323 "If true, file scanning of ALib camp 'Files' falls back to a basic implementation using C++ library std::filesystem.")
327if( "ALOX" IN_LIST ALibBuild )
329 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
330 set( defaultALOX_DBG_LOG "On" )
332 set( defaultALOX_DBG_LOG "Off" )
334 if( NOT DEFINED ALOX_DBG_LOG )
335 set( ALOX_DBG_LOG ${defaultALOX_DBG_LOG} CACHE BOOL
336 "Enable/disable debug log statements. Defaults to true with debug builds, otherwise to false." )
339 if( NOT DEFINED ALOX_DBG_LOG_CI )
340 set( ALOX_DBG_LOG_CI "On" CACHE BOOL
341 "Defaults to true. If set, caller information is used with debug log statements." )
344 if( NOT DEFINED ALOX_REL_LOG )
345 set( ALOX_REL_LOG "On" CACHE BOOL
346 "Enable/disable release log statements. Defaults to true." )
349 if( NOT DEFINED ALOX_REL_LOG_CI )
350 set( ALOX_REL_LOG_CI "Off" CACHE BOOL
351 "Defaults to false. If set, caller information is used even with release log statements (and even in release builds!)" )
355# --------------------------------------------------------------------------------------------------
357# --------------------------------------------------------------------------------------------------
360if( NOT ALibAllModules )
362 LIST( APPEND moduleList "EXPRESSIONS;CLI;ALOX;FILES" )
363 LIST( APPEND moduleList "VARIABLES;CAMP;FORMAT;EXCEPTIONS;RESOURCES;SYSTEM" )
364 LIST( APPEND moduleList "THREADMODEL;BITBUFFER" )
365 LIST( APPEND moduleList "ENUMRECORDS;BOXING;STRINGS;CONTAINERS" )
366 LIST( APPEND moduleList "SINGLETONS;MONOMEM;" )
367 FOREACH( module IN LISTS moduleList )
368 IF( module IN_LIST ALibBuild )
369 list( APPEND ALIB_SYMBOLS "ALIB_${module}" )
374# symbol ALIB_C20_MODULES (mandatory to be given from outside for technical reasons!)
375if ( ALIB_C20_MODULES )
376 list( APPEND ALIB_SYMBOLS "ALIB_C20_MODULES=1")
378 list( APPEND ALIB_SYMBOLS "ALIB_C20_MODULES=0")
383 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
385 if ( ${ALIB_DEBUG_GLIB} )
386 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
387 "_GLIBCXX_DEBUG_PEDANTIC"
388 "_GLIBCPP_CONCEPT_CHECKS" )
390 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
391 "_GLIBCXX_DEBUG_PEDANTIC"
392 "_GLIBCPP_CONCEPT_CHECKS" )
397if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
398 if ( ALIB_DEBUG_ALLOCATIONS )
399 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ALLOCATIONS" )
401 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ALLOCATIONS" )
406if( "SINGLETONS" IN_LIST ALibBuild )
407 if (NOT platformDefaultFor_SINGLETON_MAPPED STREQUAL ALIB_FEAT_SINGLETON_MAPPED)
408 if ( ALIB_FEAT_SINGLETON_MAPPED )
409 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED" )
411 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
414 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
418if( "BITBUFFER" IN_LIST ALibBuild )
419 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
420 if ( ALIB_DEBUG_ARRAY_COMPRESSION )
421 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=1" )
423 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=0" )
428if( "BOXING" IN_LIST ALibBuild )
429 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
430 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
432 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
434 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
435 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
437 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
439 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
440 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
442 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
444 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
445 if( ALIB_DEBUG_BOXING )
446 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
448 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
454 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
455 if ( ALIB_CHARACTERS_WIDE )
456 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
458 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
461 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
464 if (NOT defaultALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL ALIB_CHARACTERS_SIZEOF_WCHAR)
465 if ( NOT (ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" OR ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "4") )
466 message( FATAL_ERROR "Value of ALIB_CHARACTERS_SIZEOF_WCHAR must be 2 or 4" )
469 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
471 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
475if( "CONTAINERS" IN_LIST ALibBuild
476 AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
477 if ( ALIB_DEBUG_CONTAINERS )
478 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CONTAINERS" )
480 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CONTAINERS" )
484if( ALIB_SINGLE_THREADED )
485 list( APPEND ALIB_SYMBOLS "ALIB_SINGLE_THREADED" )
487 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_SINGLE_THREADED" )
489 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
490 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
491 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
493 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
499if( "MONOMEM" IN_LIST ALibBuild )
501 if ( ALIB_DEBUG_MEMORY )
502 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MEMORY" )
504 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MEMORY" )
509if( "STRINGS" IN_LIST ALibBuild )
510 if ( ALIB_FEAT_BOOST_REGEX )
511 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
513 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
517 if ( ALIB_DEBUG_STRINGS )
518 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
520 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
525if( "CAMP" IN_LIST ALibBuild )
527 if( ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
528 list( APPEND ALIB_SYMBOLS "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
530 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
534 if( ALIB_DEBUG_RESOURCES )
535 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
537 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
542if( "FILES" IN_LIST ALibBuild )
543 if ( ALIB_FILES_FORCE_STD_SCANNER )
544 list( APPEND ALIB_SYMBOLS "ALIB_FILES_FORCE_STD_SCANNER" )
546 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FILES_FORCE_STD_SCANNER" )
550if( "ALOX" IN_LIST ALibBuild )
552 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
553 if( NOT ALOX_DBG_LOG )
554 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
556 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
559 if ( NOT ${ALOX_DBG_LOG_CI} )
560 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
562 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
565 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
566 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
569 if ( NOT ALOX_REL_LOG )
570 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
572 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
574 if ( ALOX_REL_LOG_CI )
575 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
577 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
583# --------------------------------------------------------------------------------------------------
584# ALib Source File Definition
585# --------------------------------------------------------------------------------------------------
586include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
589# --------------------------------------------------------------------------------------------------
591# --------------------------------------------------------------------------------------------------
592if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
593 find_package(Threads)
595 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
596 if(CMAKE_USE_PTHREADS_INIT)
597 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
601 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
604if ( ${ALIB_FEAT_BOOST_REGEX} )
605 set(Boost_USE_STATIC_LIBS "On" CACHE BOOL "Link boost statically" )
606 if( NOT DEFINED ALIB_SINGLE_THREADED )
607 set(Boost_USE_MULTITHREADED "On" CACHE BOOL "Use multi-threaded version of boost")
609 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
612 find_package( Boost CONFIG REQUIRED COMPONENTS regex )
615 list( APPEND ALIB_EXTERNAL_LIBS Boost::regex )
616 if(${Boost_USE_STATIC_LIBS})
617 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost static libraries")
619 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
622 MESSAGE("Attention: Boost::regex requested, but library not found!")
627 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
632 list( APPEND ALIB_EXTERNAL_LIBS "m")
639# --------------------------------------------------------------------------------------------------
640# A-Worx compiler features and flags
641# --------------------------------------------------------------------------------------------------
643# Set minimum required standard C++20
644list( APPEND ALIB_COMPILER_FEATURES "cxx_std_20" )
646# if "ALIB_SUPPRESS_COMPILER_WARNINGS" is set prior to invoking this script, this entry is removed
647# and nothing is added.
648if ("ALIB_SUPPRESS_COMPILER_WARNINGS" IN_LIST ALIB_COMPILER_WARNINGS)
649 LIST( REMOVE_ITEM ALIB_COMPILER_WARNINGS "ALIB_SUPPRESS_COMPILER_WARNINGS" )
651 if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
652 # add -H to generate output "!/x" for use of precompiled header
653 list( APPEND ALIB_COMPILER_WARNINGS "-Wall" )
654 list( APPEND ALIB_COMPILER_WARNINGS "-Wextra" )
655 list( APPEND ALIB_COMPILER_WARNINGS "-Werror" )
656 #list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
657 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-psabi" )
658 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
660 # this was "suddenly" needed with GCC 13.2.1 with release compilation
661 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
663 # add coverage flags to GCC
664 if( ${ALIB_COVERAGE_COMPILE} )
665 list( APPEND ALIB_COMPILER_OPTIONS "--coverage" )
666 list( APPEND ALIB_LINKER_OPTIONS "--coverage" )
669 # force unicode (needed for mingw)
671 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
672 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
673 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
677 # Clang: We are using -Weverything, although this is not recommended. We think it should be
678 # recommended. ALib for example does not use old-style casts and explicitly cast each
679 # and every type change! The benefit for ALib users is that ALib code can be used in very
680 # strict build environments without using special warning flags.
681 # Of course, some very obvious warnings then have to be removed explicitly:
682 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
683 list( APPEND ALIB_COMPILER_WARNINGS "-pedantic" )
684 list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
685 list( APPEND ALIB_COMPILER_WARNINGS "-Weverything" )
686 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat" )
687 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat-pedantic" )
688 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-deprecated-declarations" )
689 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-global-constructors" )
690 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-exit-time-destructors" )
691 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-padded" )
692 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-weak-vtables" )
693 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-documentation-unknown-command" )
694 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
695 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-covered-switch-default" )
696 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-decls-in-multiple-modules" )
697 list( APPEND ALIB_COMPILER_WARNINGS "-Werror" )
699 # Note: After fighting with this for a while and locally removing the warning in many
700 # places, we gave up with Clang 19 and C++20 module compilation. Strangely, with the
701 # latter activated, Clang became even more suspicious and we decided to switch it off.
702 # It seems that also a bigger part of the community sees it that way. Where is the
703 # point to using a std::array instead of a C-array when std::array does no bounds
705 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unsafe-buffer-usage" )
707 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
708 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
712 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" )
713 list( APPEND ALIB_COMPILER_WARNINGS "/W4" )
714 list( APPEND ALIB_COMPILER_WARNINGS "/WX" )
715 list( APPEND ALIB_COMPILER_WARNINGS "/EHsc" )
719# --------------------------------------------------------------------------------------------------
720# A-Worx linker features and flags
721# --------------------------------------------------------------------------------------------------
723 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
725 list( APPEND ALIB_LINKER_OPTIONS "" )
729# -------------------------------------------------------------------------------------------------
730# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
731# -------------------------------------------------------------------------------------------------
732if ( NOT ALIB_LIBRARY_FILENAME )
733 set( ALIB_LIBRARY_FILENAME "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
736 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
737 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBG )
739 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}RELDBG )
741 if( DEFINED ALIB_SINGLE_THREADED )
742 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ST )
744 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
745 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DCS )
747 if ( ALIB_DEBUG_ALLOCATIONS )
748 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DALC )
751 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
752 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBGREL )
757 if ( ${ALIB_FEAT_SINGLETON_MAPPED} )
758 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MS )
760 if ( ${ALIB_CHARACTERS_WIDE} )
761 if ( ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" )
762 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC2 )
764 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC4 )
767 if ( ${ALIB_FEAT_BOOST_REGEX} )
768 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BREGEX )
770 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS} )
771 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJCHARS )
773 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_FLOATS} )
774 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJFLOATS )
776 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS} )
777 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJINTS )
780 # Add all module's names, prefixed by "DBG" if special debug flag is set
781 if( NOT ALibAllModules )
782 FOREACH(modName IN LISTS ALibBuild)
785 IF( modName STREQUAL "BOXING" )
786 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
787 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGBOXING )
789 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BOXING )
792 # CONTAINERS debug mode?
793 ELSEIF( modName STREQUAL "CONTAINERS" )
794 if ( ALIB_DEBUG_CONTAINERS AND ALIB_DEBUG )
795 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGCONTAINERS )
797 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CONTAINERS )
800 # MONOMEM debug mode?
801 ELSEIF( modName STREQUAL "MONOMEM" )
802 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
803 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGMONOMEM )
805 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MONOMEM )
808 # STRINGS debug mode?
809 ELSEIF( modName STREQUAL "STRINGS" )
810 if ( ALIB_DEBUG_STRINGS AND ALIB_DEBUG )
811 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
813 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
816 # RESOURCES debug mode?
817 ELSEIF( modName STREQUAL "RESOURCES" )
818 if ( ALIB_DEBUG_RESOURCES AND ALIB_DEBUG )
819 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGRESOURCES )
821 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_RESOURCES )
824 # ALOX: add non-default feature s
825 ELSEIF( modName STREQUAL "ALOX" )
826 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ALOX )
827 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT ${ALOX_DBG_LOG}) )
828 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NDL )
831 if ( NOT ALOX_REL_LOG )
832 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
835 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
841 # Remove all dependent modules from the name, which are not added in a debug version:
842 list( FIND ALibBuild "BOXING" idx )
844 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
847 list( FIND ALibBuild "ENUMRECORDS" idx )
849 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
850 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
853 list( FIND ALibBuild "BITBUFFER" idx )
855 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
856 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
859 list( FIND ALibBuild "THREADMODEL" idx )
861 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
862 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
863 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
866 list( FIND ALibBuild "SYSTEM" idx )
868 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
869 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
872 list( FIND ALibBuild "RESOURCES" idx )
874 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
875 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
876 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
879 list( FIND ALibBuild "EXCEPTIONS" idx )
881 STRING(REPLACE "_RESOURCES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
882 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
883 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
886 list( FIND ALibBuild "VARIABLES" idx )
888 STRING(REPLACE "_SYSTEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
889 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
890 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
893 list( FIND ALibBuild "FORMAT" idx )
895 STRING(REPLACE "_EXCEPTIONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
899 list( FIND ALibBuild "CAMP" idx )
901 STRING(REPLACE "_FORMAT" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
902 STRING(REPLACE "_VARIABLES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
905 list( FIND ALibBuild "ALOX" idx )
907 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
910 list( FIND ALibBuild "CLI" idx )
912 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
915 list( FIND ALibBuild "EXPRESSIONS" idx )
917 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
920 list( FIND ALibBuild "FILES" idx )
922 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
925 endif() # not all modules
929# -------------------------------------------------------------------------------------------------
930# Display result summary
931# -------------------------------------------------------------------------------------------------
932message( "ALib CMake Configuration:" )
933 message( " Modules requested : ${ALIB_BUILD}" )
934IF( NOT ALibAllModules )
935 message( " Resulting Selection: ${ALibBuild}" )
936 message( " Omitted Modules : ${ALibOmittedModules}" )
938 message( " Resulting Selection: All (${ALibBuild})" )
941 message( " C++20-Modules : ${ALIB_C20_MODULES}" )
942 message( " Single-Threaded : ${ALIB_SINGLE_THREADED}" )
944 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
945 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}" )
947IF( NOT ALIB_CMAKE_VERBOSE )
948 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
951 message( " Source folder : ${ALIB_SOURCE_DIR}" )
952 LIST( LENGTH ALIB_H length)
953 message( " File types : *.H: ${length} files" )
954 LIST( LENGTH ALIB_MPP length)
955 message( " *.mpp: ${length} files" )
956 LIST( LENGTH ALIB_INL length)
957 message( " *.inl: ${length} files" )
958 LIST( LENGTH ALIB_CPP length)
959 message( " *.cpp: ${length} files" )
960 LIST( LENGTH ALIB_HPP length)
961 message( " *.hpp: ${length} files" )
963 LIST( APPEND result ${ALIB_H} )
964 LIST( APPEND result ${ALIB_MPP} )
965 LIST( APPEND result ${ALIB_INL} )
966 LIST( APPEND result ${ALIB_CPP} )
967 LIST( APPEND result ${ALIB_HPP} )
969 LIST( LENGTH result length)
970 message( " Total: ${length} source files." )
971 message( "\n List of files:" )
972 FOREACH( entry IN LISTS result )
973 STRING(REPLACE "${ALIB_SOURCE_DIR}/" "" entry ${entry} )
974 message( " ${entry}" )
978 LIST( APPEND result ${ALIB_SYMBOLS} )
980 LIST( LENGTH result length)
981 message( "\n Compiler definitions (${length} items):" )
982 FOREACH( entry IN LISTS result )
983 message( " ${entry}" )
988 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
990 LIST( LENGTH result length)
991 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
992 FOREACH( entry IN LISTS result )
993 message( " ${entry}" )
997 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
999 LIST( LENGTH result length)
1000 message( "\n Compiler warnings (${length} items):" )
1001 FOREACH( entry IN LISTS result )
1002 message( " ${entry}" )
1006 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
1008 LIST( LENGTH result length)
1009 message( "\n Compiler flags (${length} items):" )
1010 FOREACH( entry IN LISTS result )
1011 message( " ${entry}" )
1015 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
1017 LIST( LENGTH result length)
1018 message( "\n Compiler features (${length} items):" )
1019 FOREACH( entry IN LISTS result )
1020 message( " ${entry}" )
1024 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
1026 LIST( LENGTH result length)
1027 message( "\n External libraries (${length} items):" )
1028 FOREACH( entry IN LISTS result )
1029 message( " ${entry}" )
1033 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
1035 LIST( LENGTH result length)
1036 message( "\n Linker flags (${length} items):" )
1037 FOREACH( entry IN LISTS result )
1038 message( " ${entry}" )
1045# -------------------------------------------------------------------------------------------------
1046# ALibFilterSupportedCompilerFlags()
1047# Checks the flags in the given list for compatibility with current C/C++ compiler.
1048# -------------------------------------------------------------------------------------------------
1049include(CheckCCompilerFlag)
1050include(CheckCXXCompilerFlag)
1052# filter_supported_flags(<C|CXX> <out-var> <flags...>)
1053macro(ALibFilterSupportedCompilerFlags LANG VAR)
1054 # Short-circuit only in actual try_compile sub-configures
1055 if(DEFINED CMAKE_TRY_COMPILE OR PROJECT_NAME MATCHES "^cmTC_")
1056 set(${VAR} "${ARGN}")
1061 #message(STATUS "filter_supported_flags: LANG=${LANG} input=[${ARGN}]")
1063 set(_saved ${CMAKE_REQUIRED_QUIET})
1064 set(CMAKE_REQUIRED_QUIET ON)
1067 foreach(FLAG ${ARGN}) # classic form—works on all CMake versions
1069 "${CMAKE_${LANG}_COMPILER_ID};${CMAKE_${LANG}_COMPILER_VERSION};${LANG};${FLAG}")
1071 if(${LANG} STREQUAL "C")
1072 check_c_compiler_flag("${FLAG}" _has_${_key})
1074 list(APPEND _supported "${FLAG}")
1076 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1078 elseif(${LANG} STREQUAL "CXX")
1079 check_cxx_compiler_flag("${FLAG}" _has_${_key})
1081 list(APPEND _supported "${FLAG}")
1083 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1086 message(FATAL_ERROR "filter_supported_flags: LANG must be C or CXX. Given ${LANG}")
1090 set(CMAKE_REQUIRED_QUIET ${_saved})
1091 set(${VAR} "${_supported}") # macro: mutates caller scope
1092 #message(STATUS "filter_supported_flags: output=[${${VAR}}]")
1096# -------------------------------------------------------------------------------------------------
1097# ALibSetCompilerAndLinker(target)
1099# Simple CMake function that sets
1101# - ALIB_COMPILER_FEATURES
1102# - ALIB_COMPILER_OPTIONS
1103# - ALIB_COMPILER_WARNINGS
1104# - ALIB_LINKER_OPTIONS
1106# In addition, position independent compile (-fPic) is enabled (for static libraries its default
1107# is off with CMake).
1108# -------------------------------------------------------------------------------------------------
1109function( ALibSetCompilerAndLinker target )
1110 message("${target}: Applying ALib compiler and linker settings")
1113 ALibFilterSupportedCompilerFlags(CXX ALIB_COMPILER_WARNINGS ${ALIB_COMPILER_WARNINGS})
1114 target_compile_features ( ${target} PRIVATE ${ALIB_COMPILER_FEATURES} )
1115 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_OPTIONS} )
1116 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_WARNINGS} )
1117 set_property ( TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON )
1118 target_include_directories( ${target} PUBLIC ${ALIB_SOURCE_DIR} )
1120 IF(DEFINED ALIB_PRECOMPILED_HEADER)
1121 IF(ALIB_PRECOMPILED_HEADER)
1122 IF( NOT ALIB_C20_MODULES )
1123 target_precompile_headers( ${target} PRIVATE "${ALIB_SOURCE_DIR}/alib_precompile.hpp" )
1129 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
1132 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
1133 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
1135 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
1136 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
1139 # Use clang's own stdc++ library if requested
1140 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ALIB_CLANG_USE_LIBCPP )
1141 target_compile_options(${target} PRIVATE -stdlib=libc++)
1142 target_link_libraries( ${target} PRIVATE c++)
1145 # With MSVC force UTF8 encoding of string literals
1147 target_compile_options(${target} PRIVATE /utf-8)
1152# -------------------------------------------------------------------------------------------------
1154# -------------------------------------------------------------------------------------------------
1155function( ALibAddStaticLibrary )
1157 add_library ( ALib_StaticLib STATIC )
1159 target_sources ( ALib_StaticLib PRIVATE ${ALIB_CPP} )
1160 if( ALIB_C20_MODULES )
1161 target_sources ( ALib_StaticLib PUBLIC FILE_SET alib_modules TYPE CXX_MODULES
1162 BASE_DIRS ${ALIB_BASE_DIR}
1164 target_sources ( ALib_StaticLib PUBLIC ${ALIB_HPP} )
1165 endif() # ALIB_C20_MODULES
1166 message("ALib_SharedLib target added")
1168 ALibSetCompilerAndLinker ( ALib_StaticLib )
1169 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1172function( ALibAddSharedLibrary )
1173 add_library ( ALib_SharedLib SHARED )
1174 target_sources ( ALib_SharedLib PRIVATE ${ALIB_CPP} )
1175 if( ALIB_C20_MODULES )
1176 target_sources ( ALib_SharedLib PUBLIC FILE_SET alib_modules TYPE CXX_MODULES
1177 BASE_DIRS ${ALIB_BASE_DIR}
1179 target_sources ( ALib_SharedLib PUBLIC ${ALIB_HPP} )
1180 endif() # ALIB_C20_MODULES
1181 message("ALib_SharedLib target added")
1183 ALibSetCompilerAndLinker ( ALib_SharedLib )
1184 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1187 target_compile_definitions(ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
1191# --------------------------------------------------------------------------------------------------
1192# CMake debugging Uncomment a line to have CMake summarize information
1193# --------------------------------------------------------------------------------------------------
1194#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} INCLUDE_DIRECTORIES )
1195#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} SOURCES )
1196#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_DEFINITIONS )
1197#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_OPTIONS )
1198#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_FEATURES )
1199#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} AUTOUIC_OPTIONS )
1200#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} POSITION_INDEPENDENT_CODE )
1201#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} CONTAINER_SIZE_REQUIRED )
1202#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} LIB_VERSION )
1204set(CMAKE_VERBOSE_MAKEFILE ON)
1205set(CMAKE_RULE_MESSAGES ON )