ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ALib.cmake
1# #################################################################################################
2# ALib.cmake - CMake file for projects using ALib
3#
4# Copyright 2013-2025 A-Worx GmbH, Germany
5# Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6#
7# \file
8# CMake file for projects using ALib
9# #################################################################################################
10
11# --------------------------------------------------------------------------------------------------
12# checks
13# --------------------------------------------------------------------------------------------------
14 cmake_minimum_required(VERSION 3.20) # For C++ 20 module compilation, V. 3.28 is needed
15
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.")
19 endif()
20
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})" )
24 endif()
25 set(CMAKE_CXX_SCAN_FOR_MODULES ON)
26 endif()
27
28 # check
29 if (tmp_alib_included_marker)
30 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
31 return()
32 endif()
33 set(tmp_alib_included_marker "1")
34
35
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.")
42 endif()
43
44
45 # check
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}\"" )
49 return()
50 endif()
51
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}")
57 endif()
58 else()
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
62 endif()
63 set(CMAKE_CXX_STANDARD_REQUIRED ON)
64
65 # build type defaults to "Debug"
66 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
67 set( CMAKE_BUILD_TYPE "Debug" )
68 endif()
69
70 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
71
72 # include tool functions
73 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
74
75 # Using LLVM libc++?
76 if( NOT DEFINED ALIB_CLANG_USE_LIBCPP )
77 set( ALIB_CLANG_USE_LIBCPP "Off" )
78 endif()
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++)" )
83 endif()
84
85 # Single-threaded compilation?
86 if( NOT DEFINED ALIB_SINGLE_THREADED )
87 set( ALIB_SINGLE_THREADED "Off" )
88 endif()
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" )
93 endif()
94
95# --------------------------------------------------------------------------------------------------
96# ALib Module Dependency Resolution
97# --------------------------------------------------------------------------------------------------
98
99 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
100
101# --------------------------------------------------------------------------------------------------
102# ALib Cache Variables
103# The variables are only set, if not already predefined prior to invoking this script.
104# --------------------------------------------------------------------------------------------------
105
106# --------- ALib Version ---------
107
108set( ALIB_VERSION "2510R0" CACHE STRING
109 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
110
111set( ALIB_VERSION_NO "2510" )
112set( ALIB_VERSION_REV "0" )
113
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" )
118 else()
119 set( ALIB_DEBUG "Off" )
120 endif()
121endif()
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." )
124
125if( NOT DEFINED ALIB_DEBUG_GLIB )
126 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
127 set( ALIB_DEBUG_GLIB "Off" )
128 else()
129 set( ALIB_DEBUG_GLIB "Off" )
130 endif()
131endif()
132CacheAsBool( ALIB_DEBUG_GLIB
133 "Defaults to false. If true, the compiler-symbols '_GLIBCXX_DEBUG', '_GLIBCXX_DEBUG_PEDANTIC' and '_GLIBCPP_CONCEPT_CHECKS' are set." )
134
135
136if( NOT DEFINED ALIB_COVERAGE_COMPILE )
137 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
138 set( ALIB_COVERAGE_COMPILE "Off" )
139 else()
140 set( ALIB_COVERAGE_COMPILE "Off" )
141 endif()
142endif()
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)
148elseif( ALIB_DEBUG
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")
153endif()
154
155if( NOT ALIB_DEBUG )
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")
159 endif()
160endif()
161
162CacheAsBool( ALIB_DEBUG_CRITICAL_SECTIONS
163 "Defaults to true unless ALIB_SINGLE_THREADED is set.")
164
165if ( ${ALIB_DEBUG_CRITICAL_SECTIONS} )
166 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
167else()
168 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
169endif()
170
171
172if( NOT DEFINED ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH )
173 If( ALIB_DEBUG )
174 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH "On" )
175 else()
176 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH ALIB_SINGLE_THREADED )
177 endif()
178endif()
179
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." )
182
183
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." )
188endif()
189if ( ${ALIB_PRECOMPILED_HEADER} )
190 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
191else()
192 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
193endif()
194
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." )
198endif()
199
200
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." )
205endif()
206
207
208# --------- Per module values ---------
209if( "SINGLETONS" IN_LIST ALibBuild )
210 if ( ${WIN32} )
211 set( platformDefaultFor_SINGLETON_MAPPED "On" )
212 else()
213 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
214 endif()
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.")
218 endif()
219endif()
220
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." )
226 endif()
227 endif()
228endif()
229
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." )
235 endif()
236 endif()
237endif()
238
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." )
244 endif()
245 endif()
246endif()
247
248
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.")
253 endif()
254
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.")
258 endif()
259
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.")
263 endif()
264
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." )
269 endif()
270 endif()
271endif()
272
273# "CHARACTERS"
274 if ( ${WIN32} )
275 set( defaultALIB_CHARACTERS_WIDE "On" )
276 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
277 else()
278 set( defaultALIB_CHARACTERS_WIDE "Off" )
279 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
280 endif()
281
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.")
285 endif()
286
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.")
290 endif()
291
292
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.")
297 endif()
298
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.")
303 endif()
304 endif()
305endif()
306
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.")
311 endif()
312
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." )
316 endif()
317
318endif()
319
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.")
324 endif()
325endif()
326
327if( "ALOX" IN_LIST ALibBuild )
328
329 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
330 set( defaultALOX_DBG_LOG "On" )
331 else()
332 set( defaultALOX_DBG_LOG "Off" )
333 endif()
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." )
337 endif()
338
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." )
342 endif()
343
344 if( NOT DEFINED ALOX_REL_LOG )
345 set( ALOX_REL_LOG "On" CACHE BOOL
346 "Enable/disable release log statements. Defaults to true." )
347 endif()
348
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!)" )
352 endif()
353endif()
354
355# --------------------------------------------------------------------------------------------------
356# Compiler symbols
357# --------------------------------------------------------------------------------------------------
358
359# module selection
360if( NOT ALibAllModules )
361 SET( moduleList "" )
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}" )
370 ENDIF()
371 ENDFOREACH()
372endif()
373
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")
377else()
378 list( APPEND ALIB_SYMBOLS "ALIB_C20_MODULES=0")
379endif()
380
381# debug
382if ( ${ALIB_DEBUG} )
383 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
384
385 if ( ${ALIB_DEBUG_GLIB} )
386 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
387 "_GLIBCXX_DEBUG_PEDANTIC"
388 "_GLIBCPP_CONCEPT_CHECKS" )
389 else()
390 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
391 "_GLIBCXX_DEBUG_PEDANTIC"
392 "_GLIBCPP_CONCEPT_CHECKS" )
393 endif()
394endif()
395
396# ALib features
397if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
398 if ( ALIB_DEBUG_ALLOCATIONS )
399 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ALLOCATIONS" )
400 else()
401 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ALLOCATIONS" )
402 endif()
403endif()
404
405
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" )
410 else()
411 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
412 endif()
413 else()
414 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
415 endif()
416endif()
417
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" )
422 else()
423 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=0" )
424 endif()
425 endif()
426endif()
427
428if( "BOXING" IN_LIST ALibBuild )
429 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
430 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
431 else()
432 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
433 endif()
434 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
435 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
436 else()
437 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
438 endif()
439 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
440 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
441 else()
442 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
443 endif()
444 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
445 if( ALIB_DEBUG_BOXING )
446 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
447 else()
448 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
449 endif()
450 endif()
451endif()
452
453# "CHARACTERS"
454 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
455 if ( ALIB_CHARACTERS_WIDE )
456 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
457 else()
458 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
459 endif()
460 else()
461 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
462 endif()
463
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" )
467 return()
468 endif()
469 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
470 else()
471 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
472 endif()
473
474
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" )
479 else()
480 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CONTAINERS" )
481 endif()
482endif()
483
484if( ALIB_SINGLE_THREADED )
485 list( APPEND ALIB_SYMBOLS "ALIB_SINGLE_THREADED" )
486else()
487 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_SINGLE_THREADED" )
488
489 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
490 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
491 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
492 else()
493 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
494 endif()
495 endif()
496endif()
497
498
499if( "MONOMEM" IN_LIST ALibBuild )
500 if ( ALIB_DEBUG )
501 if ( ALIB_DEBUG_MEMORY )
502 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MEMORY" )
503 else()
504 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MEMORY" )
505 endif()
506 endif()
507endif()
508
509if( "STRINGS" IN_LIST ALibBuild )
510 if ( ALIB_FEAT_BOOST_REGEX )
511 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
512 else()
513 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
514 endif()
515
516 if ( ALIB_DEBUG )
517 if ( ALIB_DEBUG_STRINGS )
518 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
519 else()
520 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
521 endif()
522 endif()
523endif()
524
525if( "CAMP" IN_LIST ALibBuild )
526
527 if( ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
528 list( APPEND ALIB_SYMBOLS "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
529 else()
530 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
531 endif()
532
533 if ( ALIB_DEBUG )
534 if( ALIB_DEBUG_RESOURCES )
535 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
536 else()
537 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
538 endif()
539 endif()
540endif()
541
542if( "FILES" IN_LIST ALibBuild )
543 if ( ALIB_FILES_FORCE_STD_SCANNER )
544 list( APPEND ALIB_SYMBOLS "ALIB_FILES_FORCE_STD_SCANNER" )
545 else()
546 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FILES_FORCE_STD_SCANNER" )
547 endif()
548endif()
549
550if( "ALOX" IN_LIST ALibBuild )
551
552 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
553 if( NOT ALOX_DBG_LOG )
554 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
555 else()
556 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
557 endif()
558
559 if ( NOT ${ALOX_DBG_LOG_CI} )
560 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
561 else()
562 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
563 endif()
564 else()
565 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
566 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
567 endif()
568
569 if ( NOT ALOX_REL_LOG )
570 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
571 else()
572 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
573 endif()
574 if ( ALOX_REL_LOG_CI )
575 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
576 else()
577 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
578 endif()
579endif()
580
581
582
583# --------------------------------------------------------------------------------------------------
584# ALib Source File Definition
585# --------------------------------------------------------------------------------------------------
586include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
587
588
589# --------------------------------------------------------------------------------------------------
590# External libraries
591# --------------------------------------------------------------------------------------------------
592if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
593 find_package(Threads)
594 if(Threads_FOUND)
595 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
596 if(CMAKE_USE_PTHREADS_INIT)
597 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
598 endif()
599 endif()
600
601 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
602endif()
603
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")
608 else()
609 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
610 endif()
611
612 find_package( Boost CONFIG REQUIRED COMPONENTS regex )
613
614 if(Boost_FOUND)
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")
618 else()
619 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
620 endif()
621 else()
622 MESSAGE("Attention: Boost::regex requested, but library not found!")
623 endif()
624endif()
625
626if(APPLE)
627 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
628endif()
629
630if(NOT MSVC)
631 if(NOT APPLE)
632 list( APPEND ALIB_EXTERNAL_LIBS "m")
633 endif(NOT APPLE)
634endif(NOT MSVC)
635
636
637
638
639# --------------------------------------------------------------------------------------------------
640# A-Worx compiler features and flags
641# --------------------------------------------------------------------------------------------------
642
643# Set minimum required standard C++20
644list( APPEND ALIB_COMPILER_FEATURES "cxx_std_20" )
645
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" )
650else()
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" )
659
660 # this was "suddenly" needed with GCC 13.2.1 with release compilation
661 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
662
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" )
667 endif()
668
669 # force unicode (needed for mingw)
670 if(MINGW)
671 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
672 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
673 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
674 endif()
675
676
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" )
698
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
704 # check?
705 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unsafe-buffer-usage" )
706
707 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
708 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
709 endif()
710
711 # MSVC
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" )
716 endif()
717endif()
718
719# --------------------------------------------------------------------------------------------------
720# A-Worx linker features and flags
721# --------------------------------------------------------------------------------------------------
722if(APPLE)
723 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
724else()
725 list( APPEND ALIB_LINKER_OPTIONS "" )
726endif()
727
728
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}" )
734
735 if ( ${ALIB_DEBUG} )
736 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
737 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBG )
738 else()
739 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}RELDBG )
740 endif()
741 if( DEFINED ALIB_SINGLE_THREADED )
742 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ST )
743 endif()
744 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
745 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DCS )
746 endif()
747 if ( ALIB_DEBUG_ALLOCATIONS )
748 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DALC )
749 endif()
750 else()
751 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
752 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBGREL )
753 endif()
754 endif()
755
756 # Add features
757 if ( ${ALIB_FEAT_SINGLETON_MAPPED} )
758 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MS )
759 endif()
760 if ( ${ALIB_CHARACTERS_WIDE} )
761 if ( ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" )
762 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC2 )
763 else()
764 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC4 )
765 endif()
766 endif()
767 if ( ${ALIB_FEAT_BOOST_REGEX} )
768 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BREGEX )
769 endif()
770 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS} )
771 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJCHARS )
772 endif()
773 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_FLOATS} )
774 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJFLOATS )
775 endif()
776 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS} )
777 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJINTS )
778 endif()
779
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)
783
784 # BOXING debug mode?
785 IF( modName STREQUAL "BOXING" )
786 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
787 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGBOXING )
788 else()
789 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BOXING )
790 endif()
791
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 )
796 else()
797 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CONTAINERS )
798 endif()
799
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 )
804 else()
805 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MONOMEM )
806 endif()
807
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 )
812 else()
813 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
814 endif()
815
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 )
820 else()
821 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_RESOURCES )
822 endif()
823
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 )
829 endif()
830
831 if ( NOT ALOX_REL_LOG )
832 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
833 endif()
834 ELSE()
835 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
836 ENDIF()
837
838 ENDFOREACH()
839
840
841 # Remove all dependent modules from the name, which are not added in a debug version:
842 list( FIND ALibBuild "BOXING" idx )
843 if( NOT idx LESS 0 )
844 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
845 endif()
846
847 list( FIND ALibBuild "ENUMRECORDS" idx )
848 if( NOT idx LESS 0 )
849 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
850 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
851 endif()
852
853 list( FIND ALibBuild "BITBUFFER" idx )
854 if( NOT idx LESS 0 )
855 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
856 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
857 endif()
858
859 list( FIND ALibBuild "THREADMODEL" idx )
860 if( NOT idx LESS 0 )
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}")
864 endif()
865
866 list( FIND ALibBuild "SYSTEM" idx )
867 if( NOT idx LESS 0 )
868 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
869 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
870 endif()
871
872 list( FIND ALibBuild "RESOURCES" idx )
873 if( NOT idx LESS 0 )
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}")
877 endif()
878
879 list( FIND ALibBuild "EXCEPTIONS" idx )
880 if( NOT idx LESS 0 )
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}")
884 endif()
885
886 list( FIND ALibBuild "VARIABLES" idx )
887 if( NOT idx LESS 0 )
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}")
891 endif()
892
893 list( FIND ALibBuild "FORMAT" idx )
894 if( NOT idx LESS 0 )
895 STRING(REPLACE "_EXCEPTIONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
896 endif()
897
898
899 list( FIND ALibBuild "CAMP" idx )
900 if( NOT idx LESS 0 )
901 STRING(REPLACE "_FORMAT" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
902 STRING(REPLACE "_VARIABLES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
903 endif()
904
905 list( FIND ALibBuild "ALOX" idx )
906 if( NOT idx LESS 0 )
907 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
908 endif()
909
910 list( FIND ALibBuild "CLI" idx )
911 if( NOT idx LESS 0 )
912 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
913 endif()
914
915 list( FIND ALibBuild "EXPRESSIONS" idx )
916 if( NOT idx LESS 0 )
917 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
918 endif()
919
920 list( FIND ALibBuild "FILES" idx )
921 if( NOT idx LESS 0 )
922 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
923 endif()
924
925 endif() # not all modules
926
927endif()
928
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}" )
937ELSE()
938 message( " Resulting Selection: All (${ALibBuild})" )
939ENDIF()
940
941 message( " C++20-Modules : ${ALIB_C20_MODULES}" )
942 message( " Single-Threaded : ${ALIB_SINGLE_THREADED}" )
943
944 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
945 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}" )
946
947IF( NOT ALIB_CMAKE_VERBOSE )
948 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
949ELSE()
950
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" )
962 SET( result "" )
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} )
968 LIST( SORT result )
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}" )
975 ENDFOREACH()
976
977 SET( result "" )
978 LIST( APPEND result ${ALIB_SYMBOLS} )
979 LIST( SORT result )
980 LIST( LENGTH result length)
981 message( "\n Compiler definitions (${length} items):" )
982 FOREACH( entry IN LISTS result )
983 message( " ${entry}" )
984 ENDFOREACH()
985 SET( result "" )
986
987 SET( result "" )
988 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
989 LIST( SORT result )
990 LIST( LENGTH result length)
991 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
992 FOREACH( entry IN LISTS result )
993 message( " ${entry}" )
994 ENDFOREACH()
995 SET( result "" )
996
997 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
998 LIST( SORT result )
999 LIST( LENGTH result length)
1000 message( "\n Compiler warnings (${length} items):" )
1001 FOREACH( entry IN LISTS result )
1002 message( " ${entry}" )
1003 ENDFOREACH()
1004 SET( result "" )
1005
1006 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
1007 LIST( SORT result )
1008 LIST( LENGTH result length)
1009 message( "\n Compiler flags (${length} items):" )
1010 FOREACH( entry IN LISTS result )
1011 message( " ${entry}" )
1012 ENDFOREACH()
1013 SET( result "" )
1014
1015 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
1016 LIST( SORT result )
1017 LIST( LENGTH result length)
1018 message( "\n Compiler features (${length} items):" )
1019 FOREACH( entry IN LISTS result )
1020 message( " ${entry}" )
1021 ENDFOREACH()
1022 SET( result "" )
1023
1024 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
1025 LIST( SORT result )
1026 LIST( LENGTH result length)
1027 message( "\n External libraries (${length} items):" )
1028 FOREACH( entry IN LISTS result )
1029 message( " ${entry}" )
1030 ENDFOREACH()
1031 SET( result "" )
1032
1033 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
1034 LIST( SORT result )
1035 LIST( LENGTH result length)
1036 message( "\n Linker flags (${length} items):" )
1037 FOREACH( entry IN LISTS result )
1038 message( " ${entry}" )
1039 ENDFOREACH()
1040 SET( result "" )
1041
1042 message( "\n" )
1043ENDIF()
1044
1045# -------------------------------------------------------------------------------------------------
1046# ALibFilterSupportedCompilerFlags()
1047# Checks the flags in the given list for compatibility with current C/C++ compiler.
1048# -------------------------------------------------------------------------------------------------
1049include(CheckCCompilerFlag)
1050include(CheckCXXCompilerFlag)
1051
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}")
1057 return()
1058 endif()
1059
1060 # (Optional) debug
1061 #message(STATUS "filter_supported_flags: LANG=${LANG} input=[${ARGN}]")
1062
1063 set(_saved ${CMAKE_REQUIRED_QUIET})
1064 set(CMAKE_REQUIRED_QUIET ON)
1065
1066 set(_supported)
1067 foreach(FLAG ${ARGN}) # classic form—works on all CMake versions
1068 string(MD5 _key
1069 "${CMAKE_${LANG}_COMPILER_ID};${CMAKE_${LANG}_COMPILER_VERSION};${LANG};${FLAG}")
1070
1071 if(${LANG} STREQUAL "C")
1072 check_c_compiler_flag("${FLAG}" _has_${_key})
1073 if(_has_${_key})
1074 list(APPEND _supported "${FLAG}")
1075 else()
1076 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1077 endif()
1078 elseif(${LANG} STREQUAL "CXX")
1079 check_cxx_compiler_flag("${FLAG}" _has_${_key})
1080 if(_has_${_key})
1081 list(APPEND _supported "${FLAG}")
1082 else()
1083 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1084 endif()
1085 else()
1086 message(FATAL_ERROR "filter_supported_flags: LANG must be C or CXX. Given ${LANG}")
1087 endif()
1088 endforeach()
1089
1090 set(CMAKE_REQUIRED_QUIET ${_saved})
1091 set(${VAR} "${_supported}") # macro: mutates caller scope
1092 #message(STATUS "filter_supported_flags: output=[${${VAR}}]")
1093endmacro()
1094
1095
1096# -------------------------------------------------------------------------------------------------
1097# ALibSetCompilerAndLinker(target)
1098#
1099# Simple CMake function that sets
1100# - ALIB_SYMBOLS
1101# - ALIB_COMPILER_FEATURES
1102# - ALIB_COMPILER_OPTIONS
1103# - ALIB_COMPILER_WARNINGS
1104# - ALIB_LINKER_OPTIONS
1105#
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")
1111
1112 # compiler flags
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} )
1119
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" )
1124 ENDIF()
1125 ENDIF()
1126 ENDIF()
1127
1128 #definitions
1129 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
1130
1131 # linker flags
1132 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
1133 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
1134 ENDIF()
1135 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
1136 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
1137 ENDIF()
1138
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++)
1143 endif()
1144
1145 # With MSVC force UTF8 encoding of string literals
1146 if (MSVC)
1147 target_compile_options(${target} PRIVATE /utf-8)
1148 endif()
1149
1150endfunction()
1151
1152# -------------------------------------------------------------------------------------------------
1153# Targets
1154# -------------------------------------------------------------------------------------------------
1155function( ALibAddStaticLibrary )
1156 # sources
1157 add_library ( ALib_StaticLib STATIC )
1158
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}
1163 FILES ${ALIB_MPP} )
1164 target_sources ( ALib_StaticLib PUBLIC ${ALIB_HPP} )
1165 endif() # ALIB_C20_MODULES
1166 message("ALib_SharedLib target added")
1167
1168 ALibSetCompilerAndLinker ( ALib_StaticLib )
1169 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1170endfunction()
1171
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}
1178 FILES ${ALIB_MPP} )
1179 target_sources ( ALib_SharedLib PUBLIC ${ALIB_HPP} )
1180 endif() # ALIB_C20_MODULES
1181 message("ALib_SharedLib target added")
1182
1183 ALibSetCompilerAndLinker ( ALib_SharedLib )
1184 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1185
1186 if(WIN32)
1187 target_compile_definitions(ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
1188 endif()
1189endfunction()
1190
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 )
1203
1204set(CMAKE_VERBOSE_MAKEFILE ON)
1205set(CMAKE_RULE_MESSAGES ON )
1206