ALib C++ Library
Library Version: 2511 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 # C++20 module support is deprecated!
17 if( NOT DEFINED ALIB_C20_MODULES )
18 set( ALIB_C20_MODULES "Off")
19 #set( ALIB_C20_MODULES "Off" CACHE PATH
20 # "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 endif()
22
23 if( ALIB_C20_MODULES )
24 message( FATAL_ERROR "ALib.cmake: ALIB configured to use C++20 modules. As of today, the effort to offer dual-compile support is dropped and not supported" )
25 endif()
26 set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
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 "2511R0" CACHE STRING
109 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
110
111set( ALIB_VERSION_NO "2511" )
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 multithreaded 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# debug
375if ( ${ALIB_DEBUG} )
376 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
377
378 if ( ${ALIB_DEBUG_GLIB} )
379 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
380 "_GLIBCXX_DEBUG_PEDANTIC"
381 "_GLIBCPP_CONCEPT_CHECKS" )
382 else()
383 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
384 "_GLIBCXX_DEBUG_PEDANTIC"
385 "_GLIBCPP_CONCEPT_CHECKS" )
386 endif()
387endif()
388
389# ALib features
390if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
391 if ( ALIB_DEBUG_ALLOCATIONS )
392 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ALLOCATIONS" )
393 else()
394 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ALLOCATIONS" )
395 endif()
396endif()
397
398
399if( "SINGLETONS" IN_LIST ALibBuild )
400 if (NOT platformDefaultFor_SINGLETON_MAPPED STREQUAL ALIB_FEAT_SINGLETON_MAPPED)
401 if ( ALIB_FEAT_SINGLETON_MAPPED )
402 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED" )
403 else()
404 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
405 endif()
406 else()
407 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
408 endif()
409endif()
410
411if( "BITBUFFER" IN_LIST ALibBuild )
412 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
413 if ( ALIB_DEBUG_ARRAY_COMPRESSION )
414 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=1" )
415 else()
416 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=0" )
417 endif()
418 endif()
419endif()
420
421if( "BOXING" IN_LIST ALibBuild )
422 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
423 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
424 else()
425 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
426 endif()
427 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
428 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
429 else()
430 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
431 endif()
432 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
433 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
434 else()
435 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
436 endif()
437 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
438 if( ALIB_DEBUG_BOXING )
439 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
440 else()
441 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
442 endif()
443 endif()
444endif()
445
446# "CHARACTERS"
447 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
448 if ( ALIB_CHARACTERS_WIDE )
449 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
450 else()
451 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
452 endif()
453 else()
454 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
455 endif()
456
457 if (NOT defaultALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL ALIB_CHARACTERS_SIZEOF_WCHAR)
458 if ( NOT (ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" OR ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "4") )
459 message( FATAL_ERROR "Value of ALIB_CHARACTERS_SIZEOF_WCHAR must be 2 or 4" )
460 return()
461 endif()
462 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
463 else()
464 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
465 endif()
466
467
468if( "CONTAINERS" IN_LIST ALibBuild
469 AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
470 if ( ALIB_DEBUG_CONTAINERS )
471 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CONTAINERS" )
472 else()
473 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CONTAINERS" )
474 endif()
475endif()
476
477if( ALIB_SINGLE_THREADED )
478 list( APPEND ALIB_SYMBOLS "ALIB_SINGLE_THREADED" )
479else()
480 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_SINGLE_THREADED" )
481
482 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
483 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
484 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
485 else()
486 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
487 endif()
488 endif()
489endif()
490
491
492if( "MONOMEM" IN_LIST ALibBuild )
493 if ( ALIB_DEBUG )
494 if ( ALIB_DEBUG_MEMORY )
495 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MEMORY" )
496 else()
497 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MEMORY" )
498 endif()
499 endif()
500endif()
501
502if( "STRINGS" IN_LIST ALibBuild )
503 if ( ALIB_FEAT_BOOST_REGEX )
504 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
505 else()
506 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
507 endif()
508
509 if ( ALIB_DEBUG )
510 if ( ALIB_DEBUG_STRINGS )
511 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
512 else()
513 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
514 endif()
515 endif()
516endif()
517
518if( "CAMP" IN_LIST ALibBuild )
519
520 if( ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
521 list( APPEND ALIB_SYMBOLS "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
522 else()
523 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
524 endif()
525
526 if ( ALIB_DEBUG )
527 if( ALIB_DEBUG_RESOURCES )
528 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
529 else()
530 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
531 endif()
532 endif()
533endif()
534
535if( "FILES" IN_LIST ALibBuild )
536 if ( ALIB_FILES_FORCE_STD_SCANNER )
537 list( APPEND ALIB_SYMBOLS "ALIB_FILES_FORCE_STD_SCANNER" )
538 else()
539 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FILES_FORCE_STD_SCANNER" )
540 endif()
541endif()
542
543if( "ALOX" IN_LIST ALibBuild )
544
545 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
546 if( NOT ALOX_DBG_LOG )
547 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
548 else()
549 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
550 endif()
551
552 if ( NOT ${ALOX_DBG_LOG_CI} )
553 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
554 else()
555 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
556 endif()
557 else()
558 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
559 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
560 endif()
561
562 if ( NOT ALOX_REL_LOG )
563 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
564 else()
565 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
566 endif()
567 if ( ALOX_REL_LOG_CI )
568 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
569 else()
570 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
571 endif()
572endif()
573
574
575
576# --------------------------------------------------------------------------------------------------
577# ALib Source File Definition
578# --------------------------------------------------------------------------------------------------
579include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
580
581
582# --------------------------------------------------------------------------------------------------
583# External libraries
584# --------------------------------------------------------------------------------------------------
585if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
586 find_package(Threads)
587 if(Threads_FOUND)
588 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
589 if(CMAKE_USE_PTHREADS_INIT)
590 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
591 endif()
592 endif()
593
594 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
595endif()
596
597if ( ${ALIB_FEAT_BOOST_REGEX} )
598 set(Boost_USE_STATIC_LIBS "On" CACHE BOOL "Link boost statically" )
599 if( NOT DEFINED ALIB_SINGLE_THREADED )
600 set(Boost_USE_MULTITHREADED "On" CACHE BOOL "Use multithreaded version of boost")
601 else()
602 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
603 endif()
604
605 find_package( Boost CONFIG REQUIRED COMPONENTS regex )
606
607 if(Boost_FOUND)
608 list( APPEND ALIB_EXTERNAL_LIBS Boost::regex )
609 if(${Boost_USE_STATIC_LIBS})
610 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost static libraries")
611 else()
612 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
613 endif()
614 else()
615 MESSAGE("Attention: Boost::regex requested, but library not found!")
616 endif()
617endif()
618
619if(APPLE)
620 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
621endif()
622
623if(NOT MSVC)
624 if(NOT APPLE)
625 list( APPEND ALIB_EXTERNAL_LIBS "m")
626 endif(NOT APPLE)
627endif(NOT MSVC)
628
629
630
631
632# --------------------------------------------------------------------------------------------------
633# A-Worx compiler features and flags
634# --------------------------------------------------------------------------------------------------
635
636# Set minimum required standard C++20
637list( APPEND ALIB_COMPILER_FEATURES "cxx_std_20" )
638
639# if "ALIB_SUPPRESS_COMPILER_WARNINGS" is set prior to invoking this script, this entry is removed
640# and nothing is added.
641if ("ALIB_SUPPRESS_COMPILER_WARNINGS" IN_LIST ALIB_COMPILER_WARNINGS)
642 LIST( REMOVE_ITEM ALIB_COMPILER_WARNINGS "ALIB_SUPPRESS_COMPILER_WARNINGS" )
643else()
644 if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
645 # add -H to generate output "!/x" for use of precompiled header
646 list( APPEND ALIB_COMPILER_WARNINGS "-Wall" )
647 list( APPEND ALIB_COMPILER_WARNINGS "-Wextra" )
648 #list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
649 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-psabi" )
650 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
651
652 # this was "suddenly" needed with GCC 13.2.1 with release compilation
653 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
654
655 # add coverage flags to GCC
656 if( ${ALIB_COVERAGE_COMPILE} )
657 list( APPEND ALIB_COMPILER_OPTIONS "--coverage" )
658 list( APPEND ALIB_LINKER_OPTIONS "--coverage" )
659 endif()
660
661 # force unicode (needed for mingw)
662 if(MINGW)
663 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
664 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
665 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
666 endif()
667
668
669 # Clang: We are using -Weverything, although this is not recommended. We think it should be
670 # recommended. ALib, for example, does not use old-style casts and explicitly cast each
671 # and every type change! The benefit for ALib users is that ALib code can be used in very
672 # strict build environments without using special warning flags.
673 # Of course, some very obvious warnings then have to be removed explicitly:
674 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
675 list( APPEND ALIB_COMPILER_WARNINGS "-pedantic" )
676 list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
677 list( APPEND ALIB_COMPILER_WARNINGS "-Weverything" )
678 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unknown-warning-option" )
679 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++20-compat" )
680 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat" )
681 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat-pedantic" )
682 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-covered-switch-default" )
683 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-decls-in-multiple-modules" )
684 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-deprecated-declarations" )
685 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-documentation-unknown-command" )
686 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-exit-time-destructors" )
687 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-global-constructors" )
688 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-ms-bitfield-padding" )
689 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
690 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-padded" )
691 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-weak-vtables" )
692 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-thread-safety-analysis" )
693
694 # Note: After fighting with this for a while and locally removing the warning in many
695 # places, we gave up with Clang 19 and C++20 module compilation. Strangely, with the
696 # latter activated, Clang became even more suspicious and we decided to switch it off.
697 # It seems that also a bigger part of the community sees it that way. Where is the
698 # point to using a std::array instead of a C-array when std::array does no bounds
699 # check?
700 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unsafe-buffer-usage" )
701
702 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
703 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
704 endif()
705
706 # MSVC
707 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" )
708 list( APPEND ALIB_COMPILER_WARNINGS "/W4" )
709 list( APPEND ALIB_COMPILER_WARNINGS "/WX" )
710 list( APPEND ALIB_COMPILER_WARNINGS "/EHsc" )
711 endif()
712endif()
713
714# --------------------------------------------------------------------------------------------------
715# A-Worx linker features and flags
716# --------------------------------------------------------------------------------------------------
717if(APPLE)
718 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
719else()
720 list( APPEND ALIB_LINKER_OPTIONS "" )
721endif()
722
723
724# -------------------------------------------------------------------------------------------------
725# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
726# -------------------------------------------------------------------------------------------------
727if ( NOT ALIB_LIBRARY_FILENAME )
728 set( ALIB_LIBRARY_FILENAME "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
729
730 if ( ${ALIB_DEBUG} )
731 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
732 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBG )
733 else()
734 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}RELDBG )
735 endif()
736 if( DEFINED ALIB_SINGLE_THREADED )
737 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ST )
738 endif()
739 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
740 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DCS )
741 endif()
742 if ( ALIB_DEBUG_ALLOCATIONS )
743 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DALC )
744 endif()
745 else()
746 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
747 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBGREL )
748 endif()
749 endif()
750
751 # Add features
752 if ( ${ALIB_FEAT_SINGLETON_MAPPED} )
753 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MS )
754 endif()
755 if ( ${ALIB_CHARACTERS_WIDE} )
756 if ( ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" )
757 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC2 )
758 else()
759 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC4 )
760 endif()
761 endif()
762 if ( ${ALIB_FEAT_BOOST_REGEX} )
763 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BREGEX )
764 endif()
765 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS} )
766 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJCHARS )
767 endif()
768 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_FLOATS} )
769 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJFLOATS )
770 endif()
771 if ( ${ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS} )
772 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJINTS )
773 endif()
774
775 # Add all module's names, prefixed by "DBG" if special debug flag is set
776 if( NOT ALibAllModules )
777 FOREACH(modName IN LISTS ALibBuild)
778
779 # BOXING debug mode?
780 IF( modName STREQUAL "BOXING" )
781 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
782 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGBOXING )
783 else()
784 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BOXING )
785 endif()
786
787 # CONTAINERS debug mode?
788 ELSEIF( modName STREQUAL "CONTAINERS" )
789 if ( ALIB_DEBUG_CONTAINERS AND ALIB_DEBUG )
790 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGCONTAINERS )
791 else()
792 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CONTAINERS )
793 endif()
794
795 # MONOMEM debug mode?
796 ELSEIF( modName STREQUAL "MONOMEM" )
797 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
798 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGMONOMEM )
799 else()
800 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MONOMEM )
801 endif()
802
803 # STRINGS debug mode?
804 ELSEIF( modName STREQUAL "STRINGS" )
805 if ( ALIB_DEBUG_STRINGS AND ALIB_DEBUG )
806 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
807 else()
808 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
809 endif()
810
811 # RESOURCES debug mode?
812 ELSEIF( modName STREQUAL "RESOURCES" )
813 if ( ALIB_DEBUG_RESOURCES AND ALIB_DEBUG )
814 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGRESOURCES )
815 else()
816 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_RESOURCES )
817 endif()
818
819 # ALOX: add non-default feature s
820 ELSEIF( modName STREQUAL "ALOX" )
821 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ALOX )
822 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT ${ALOX_DBG_LOG}) )
823 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NDL )
824 endif()
825
826 if ( NOT ALOX_REL_LOG )
827 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
828 endif()
829 ELSE()
830 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
831 ENDIF()
832
833 ENDFOREACH()
834
835
836 # Remove all dependent modules from the name, which are not added in a debug version:
837 list( FIND ALibBuild "BOXING" idx )
838 if( NOT idx LESS 0 )
839 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
840 endif()
841
842 list( FIND ALibBuild "ENUMRECORDS" idx )
843 if( NOT idx LESS 0 )
844 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
845 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
846 endif()
847
848 list( FIND ALibBuild "BITBUFFER" idx )
849 if( NOT idx LESS 0 )
850 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
851 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
852 endif()
853
854 list( FIND ALibBuild "THREADMODEL" idx )
855 if( NOT idx LESS 0 )
856 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
857 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
858 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
859 endif()
860
861 list( FIND ALibBuild "SYSTEM" idx )
862 if( NOT idx LESS 0 )
863 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
864 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
865 endif()
866
867 list( FIND ALibBuild "RESOURCES" idx )
868 if( NOT idx LESS 0 )
869 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
870 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
871 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
872 endif()
873
874 list( FIND ALibBuild "EXCEPTIONS" idx )
875 if( NOT idx LESS 0 )
876 STRING(REPLACE "_RESOURCES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
877 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
878 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
879 endif()
880
881 list( FIND ALibBuild "VARIABLES" idx )
882 if( NOT idx LESS 0 )
883 STRING(REPLACE "_SYSTEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
884 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
885 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
886 endif()
887
888 list( FIND ALibBuild "FORMAT" idx )
889 if( NOT idx LESS 0 )
890 STRING(REPLACE "_EXCEPTIONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
891 endif()
892
893
894 list( FIND ALibBuild "CAMP" idx )
895 if( NOT idx LESS 0 )
896 STRING(REPLACE "_FORMAT" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
897 STRING(REPLACE "_VARIABLES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
898 endif()
899
900 list( FIND ALibBuild "ALOX" idx )
901 if( NOT idx LESS 0 )
902 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
903 endif()
904
905 list( FIND ALibBuild "CLI" idx )
906 if( NOT idx LESS 0 )
907 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
908 endif()
909
910 list( FIND ALibBuild "EXPRESSIONS" idx )
911 if( NOT idx LESS 0 )
912 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
913 endif()
914
915 list( FIND ALibBuild "FILES" idx )
916 if( NOT idx LESS 0 )
917 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
918 endif()
919
920 endif() # not all modules
921
922endif()
923
924# -------------------------------------------------------------------------------------------------
925# Display result summary
926# -------------------------------------------------------------------------------------------------
927message( "ALib CMake Configuration:" )
928 message( " Modules requested : ${ALIB_BUILD}" )
929IF( NOT ALibAllModules )
930 message( " Resulting Selection: ${ALibBuild}" )
931 message( " Omitted Modules : ${ALibOmittedModules}" )
932ELSE()
933 message( " Resulting Selection: All (${ALibBuild})" )
934ENDIF()
935
936 message( " Single-Threaded : ${ALIB_SINGLE_THREADED}" )
937
938 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
939 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}" )
940
941IF( NOT ALIB_CMAKE_VERBOSE )
942 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
943ELSE()
944
945 message( " Source folder : ${ALIB_SOURCE_DIR}" )
946 LIST( LENGTH ALIB_H length)
947 message( " File types : *.H: ${length} files" )
948 LIST( LENGTH ALIB_MPP length)
949 message( " *.mpp: ${length} files" )
950 LIST( LENGTH ALIB_INL length)
951 message( " *.inl: ${length} files" )
952 LIST( LENGTH ALIB_CPP length)
953 message( " *.cpp: ${length} files" )
954 LIST( LENGTH ALIB_HPP length)
955 message( " *.hpp: ${length} files" )
956 SET( result "" )
957 LIST( APPEND result ${ALIB_H} )
958 LIST( APPEND result ${ALIB_MPP} )
959 LIST( APPEND result ${ALIB_INL} )
960 LIST( APPEND result ${ALIB_CPP} )
961 LIST( APPEND result ${ALIB_HPP} )
962 LIST( SORT result )
963 LIST( LENGTH result length)
964 message( " Total: ${length} source files." )
965 message( "\n List of files:" )
966 FOREACH( entry IN LISTS result )
967 STRING(REPLACE "${ALIB_SOURCE_DIR}/" "" entry ${entry} )
968 message( " ${entry}" )
969 ENDFOREACH()
970
971 SET( result "" )
972 LIST( APPEND result ${ALIB_SYMBOLS} )
973 LIST( SORT result )
974 LIST( LENGTH result length)
975 message( "\n Compiler definitions (${length} items):" )
976 FOREACH( entry IN LISTS result )
977 message( " ${entry}" )
978 ENDFOREACH()
979 SET( result "" )
980
981 SET( result "" )
982 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
983 LIST( SORT result )
984 LIST( LENGTH result length)
985 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
986 FOREACH( entry IN LISTS result )
987 message( " ${entry}" )
988 ENDFOREACH()
989 SET( result "" )
990
991 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
992 LIST( SORT result )
993 LIST( LENGTH result length)
994 message( "\n Compiler warnings (${length} items):" )
995 FOREACH( entry IN LISTS result )
996 message( " ${entry}" )
997 ENDFOREACH()
998 SET( result "" )
999
1000 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
1001 LIST( SORT result )
1002 LIST( LENGTH result length)
1003 message( "\n Compiler flags (${length} items):" )
1004 FOREACH( entry IN LISTS result )
1005 message( " ${entry}" )
1006 ENDFOREACH()
1007 SET( result "" )
1008
1009 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
1010 LIST( SORT result )
1011 LIST( LENGTH result length)
1012 message( "\n Compiler features (${length} items):" )
1013 FOREACH( entry IN LISTS result )
1014 message( " ${entry}" )
1015 ENDFOREACH()
1016 SET( result "" )
1017
1018 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
1019 LIST( SORT result )
1020 LIST( LENGTH result length)
1021 message( "\n External libraries (${length} items):" )
1022 FOREACH( entry IN LISTS result )
1023 message( " ${entry}" )
1024 ENDFOREACH()
1025 SET( result "" )
1026
1027 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
1028 LIST( SORT result )
1029 LIST( LENGTH result length)
1030 message( "\n Linker flags (${length} items):" )
1031 FOREACH( entry IN LISTS result )
1032 message( " ${entry}" )
1033 ENDFOREACH()
1034 SET( result "" )
1035
1036 message( "\n" )
1037ENDIF()
1038
1039# -------------------------------------------------------------------------------------------------
1040# ALibFilterSupportedCompilerFlags()
1041# Checks the flags in the given list for compatibility with current C/C++ compiler.
1042# -------------------------------------------------------------------------------------------------
1043include(CheckCCompilerFlag)
1044include(CheckCXXCompilerFlag)
1045
1046# filter_supported_flags(<C|CXX> <out-var> <flags...>)
1047macro(ALibFilterSupportedCompilerFlags LANG VAR)
1048 # Short-circuit only in actual try_compile sub-configures
1049 if(DEFINED CMAKE_TRY_COMPILE OR PROJECT_NAME MATCHES "^cmTC_")
1050 set(${VAR} "${ARGN}")
1051 return()
1052 endif()
1053
1054 # (Optional) debug
1055 #message(STATUS "filter_supported_flags: LANG=${LANG} input=[${ARGN}]")
1056
1057 set(_saved ${CMAKE_REQUIRED_QUIET})
1058 set(CMAKE_REQUIRED_QUIET ON)
1059
1060 set(_supported)
1061 foreach(FLAG ${ARGN}) # classic form—works on all CMake versions
1062 string(MD5 _key
1063 "${CMAKE_${LANG}_COMPILER_ID};${CMAKE_${LANG}_COMPILER_VERSION};${LANG};${FLAG}")
1064
1065 if(${LANG} STREQUAL "C")
1066 check_c_compiler_flag("${FLAG}" _has_${_key})
1067 if(_has_${_key})
1068 list(APPEND _supported "${FLAG}")
1069 else()
1070 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1071 endif()
1072 elseif(${LANG} STREQUAL "CXX")
1073 check_cxx_compiler_flag("${FLAG}" _has_${_key})
1074 if(_has_${_key})
1075 list(APPEND _supported "${FLAG}")
1076 else()
1077 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1078 endif()
1079 else()
1080 message(FATAL_ERROR "filter_supported_flags: LANG must be C or CXX. Given ${LANG}")
1081 endif()
1082 endforeach()
1083
1084 set(CMAKE_REQUIRED_QUIET ${_saved})
1085 set(${VAR} "${_supported}") # macro: mutates caller scope
1086 #message(STATUS "filter_supported_flags: output=[${${VAR}}]")
1087endmacro()
1088
1089
1090# -------------------------------------------------------------------------------------------------
1091# ALibSetCompilerAndLinker(target)
1092#
1093# Simple CMake function that sets
1094# - ALIB_SYMBOLS
1095# - ALIB_COMPILER_FEATURES
1096# - ALIB_COMPILER_OPTIONS
1097# - ALIB_COMPILER_WARNINGS
1098# - ALIB_LINKER_OPTIONS
1099#
1100# In addition, position independent compile (-fPic) is enabled (for static libraries its default
1101# is off with CMake).
1102# -------------------------------------------------------------------------------------------------
1103function( ALibSetCompilerAndLinker target )
1104 message("${target}: Applying ALib compiler and linker settings")
1105
1106 # compiler flags
1107 ALibFilterSupportedCompilerFlags(CXX ALIB_COMPILER_WARNINGS ${ALIB_COMPILER_WARNINGS})
1108 target_compile_features ( ${target} PRIVATE ${ALIB_COMPILER_FEATURES} )
1109 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_OPTIONS} )
1110 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_WARNINGS} )
1111 set_property ( TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON )
1112 target_include_directories( ${target} PUBLIC ${ALIB_SOURCE_DIR} )
1113
1114 IF(DEFINED ALIB_PRECOMPILED_HEADER)
1115 IF(ALIB_PRECOMPILED_HEADER)
1116 target_precompile_headers( ${target} PRIVATE "${ALIB_SOURCE_DIR}/alib_precompile.hpp" )
1117 ENDIF()
1118 ENDIF()
1119
1120 #definitions
1121 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
1122
1123 # linker flags
1124 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
1125 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
1126 ENDIF()
1127 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
1128 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
1129 ENDIF()
1130
1131 # Use clang's own stdc++ library if requested
1132 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ALIB_CLANG_USE_LIBCPP )
1133 target_compile_options(${target} PRIVATE -stdlib=libc++)
1134 target_link_libraries( ${target} PRIVATE c++)
1135 endif()
1136
1137 # With MSVC force UTF8 encoding of string literals
1138 if (MSVC)
1139 target_compile_options(${target} PRIVATE /utf-8)
1140 endif()
1141
1142endfunction()
1143
1144# -------------------------------------------------------------------------------------------------
1145# Targets
1146# -------------------------------------------------------------------------------------------------
1147function( ALibAddStaticLibrary )
1148 # sources
1149 add_library ( ALib_StaticLib STATIC )
1150
1151 target_sources ( ALib_StaticLib PRIVATE ${ALIB_CPP} )
1152 message("ALib_SharedLib target added")
1153
1154 ALibSetCompilerAndLinker ( ALib_StaticLib )
1155 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1156endfunction()
1157
1158function( ALibAddSharedLibrary )
1159 add_library ( ALib_SharedLib SHARED )
1160 target_sources ( ALib_SharedLib PRIVATE ${ALIB_CPP} )
1161 message("ALib_SharedLib target added")
1162
1163 ALibSetCompilerAndLinker ( ALib_SharedLib )
1164 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1165
1166 if(WIN32)
1167 target_compile_definitions(ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
1168 endif()
1169endfunction()
1170
1171# --------------------------------------------------------------------------------------------------
1172# CMake debugging Uncomment a line to have CMake summarize information
1173# --------------------------------------------------------------------------------------------------
1174#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} INCLUDE_DIRECTORIES )
1175#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} SOURCES )
1176#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_DEFINITIONS )
1177#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_OPTIONS )
1178#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_FEATURES )
1179#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} AUTOUIC_OPTIONS )
1180#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} POSITION_INDEPENDENT_CODE )
1181#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} CONTAINER_SIZE_REQUIRED )
1182#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} LIB_VERSION )
1183
1184set(CMAKE_VERBOSE_MAKEFILE ON)
1185set(CMAKE_RULE_MESSAGES ON )
1186