ALib C++ Framework
by
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# CMake file for projects using ALib
8# #################################################################################################
9
10# --------------------------------------------------------------------------------------------------
11# checks
12# --------------------------------------------------------------------------------------------------
13 cmake_minimum_required(VERSION 3.20) # For C++ 20 module compilation, V. 3.28 is needed
14
15 # --------- ALib Version ---------
16
17 set( ALIB_VERSION "2511R0" CACHE STRING
18 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
19
20 set( ALIB_VERSION_NO "2511" )
21 set( ALIB_VERSION_REV "0" )
22
23
24
25 # C++20 module support is deprecated!
26 if( NOT DEFINED ALIB_C20_MODULES )
27 set( ALIB_C20_MODULES "Off")
28 #set( ALIB_C20_MODULES "Off" CACHE PATH
29 # "If on, this script will compile ALib using C++20 Modules. Also, in this case, a macro of the same name is passed to the compiler.")
30 endif()
31
32 if( ALIB_C20_MODULES )
33 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" )
34 endif()
35 set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
36
37 # check
38 if (tmp_alib_included_marker)
39 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
40 return()
41 endif()
42 set(tmp_alib_included_marker "1")
43
44
45 # Infer base directory from this script's location
46 if( NOT DEFINED ALIB_BASE_DIR )
47 set( temp "${CMAKE_CURRENT_LIST_DIR}/../.." )
48 get_filename_component(temp ${temp} ABSOLUTE)
49 set( ALIB_BASE_DIR ${temp} CACHE PATH
50 "The base path to ALib containing source code, project files, tools, docs, etc.")
51 endif()
52
53
54 # check
55 if ( NOT EXISTS "${ALIB_BASE_DIR}/src/ALib.Lang.H"
56 OR NOT EXISTS "${ALIB_BASE_DIR}/src/alib" )
57 message( FATAL_ERROR "ALib.cmake: Can't read sources in ALIB_BASE_DIR \"${ALIB_BASE_DIR}\"" )
58 return()
59 endif()
60
61 # Check if CMAKE_CXX_STANDARD is defined
62 if(DEFINED CMAKE_CXX_STANDARD)
63 # Verify if it's at least 20
64 if(CMAKE_CXX_STANDARD LESS 20)
65 message(FATAL_ERROR "ALib compilation needs C++20 standard. Given is: ${CMAKE_CXX_STANDARD}")
66 endif()
67 else()
68 # Set the C++ standard to 20 if not defined
69 set(CMAKE_CXX_STANDARD 20)
70 set(CMAKE_CXX_EXTENSIONS OFF) # Disable compiler-specific extensions
71 endif()
72 set(CMAKE_CXX_STANDARD_REQUIRED ON)
73
74 # build type defaults to "Debug"
75 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
76 set( CMAKE_BUILD_TYPE "Debug" )
77 endif()
78
79 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
80
81 # include tool functions
82 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
83
84 # Remember this cmake directory for use inside functions
85 set(ALIB_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
86
87 # --------------------------------------------------------------------------------------------------
88 # Optional install/export infrastructure (package-manager free)
89 # --------------------------------------------------------------------------------------------------
90 include(CMakePackageConfigHelpers)
91 include(GNUInstallDirs)
92
93 option(ALIB_LOCAL_INSTALL "Install ALib to a user-local cache/prefix by default" ON)
94 set(ALIB_INSTALL_PREFIX_OVERRIDE "" CACHE PATH "Override the computed install prefix (absolute path)")
95 set(ALIB_EXPORT_NAMESPACE "ALib::" CACHE STRING "CMake namespace for exported ALib targets")
96 # Prefer static for the generic alias by default (can be changed by users)
97 set(ALIB_PREFER_SHARED OFF CACHE BOOL "Prefer shared library for ALib::ALib alias (default OFF => static)")
98 # Install only headers needed for the selected modules (recommended)
99 option(ALIB_INSTALL_HEADERS_ONLY_SELECTED "Install only the headers required by the resolved ALibBuild (instead of installing the whole include tree)" ON)
100 # Keep legacy, feature-encoded output filenames or use a stable name and rely on variant directories
101 option(ALIB_STABLE_OUTPUT_NAME "Use a stable output name for binaries (variant separation by install prefix)" OFF)
102
103 # Using LLVM libc++?
104 if( NOT DEFINED ALIB_CLANG_USE_LIBCPP )
105 set( ALIB_CLANG_USE_LIBCPP "Off" )
106 endif()
107 CacheAsBool( ALIB_CLANG_USE_LIBCPP
108 "Defaults to false. If set and Clang is used, function ALibSetCompilerAndLinker sets compiler and linker flags to use LLVM libc++ instead of GNU libstdc++." )
109 if( ALIB_CLANG_USE_LIBCPP )
110 message( "Using LLVM libc++ (instead of GNU libstdc++)" )
111 endif()
112
113 # Single-threaded compilation?
114 if( NOT DEFINED ALIB_SINGLE_THREADED )
115 set( ALIB_SINGLE_THREADED "Off" )
116 endif()
117 CacheAsBool( ALIB_SINGLE_THREADED
118 "Defaults to false. Disables multi-threading functionality in ALib." )
119 if( ALIB_SINGLE_THREADED )
120 message( "Single-threaded library compilation" )
121 endif()
122
123 # --------------------------------------------------------------------------------------------------
124 # Variant key computation and default install prefix selection
125 # --------------------------------------------------------------------------------------------------
126 # OS token
127 if(UNIX)
128 set(_alib_os linux)
129 elseif(APPLE)
130 set(_alib_os mac)
131 elseif(WIN32)
132 set(_alib_os win)
133 else()
134 set(_alib_os other)
135 endif()
136
137 # Compiler id/version and short token
138 set(_alib_ccid "${CMAKE_CXX_COMPILER_ID}")
139 set(_alib_ccver "${CMAKE_CXX_COMPILER_VERSION}")
140 if(_alib_ccid STREQUAL "GNU")
141 set(shortcc gcc)
142 elseif(_alib_ccid STREQUAL "Clang")
143 set(shortcc clang)
144 elseif(_alib_ccid STREQUAL "MSVC")
145 set(shortcc msvc)
146 else()
147 string(TOLOWER "${_alib_ccid}" shortcc)
148 endif()
149
150 # stdlib (best effort)
151 set(_alib_stdlib libstdc++)
152 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
153 if(ALIB_CLANG_USE_LIBCPP)
154 set(_alib_stdlib libc++)
155 else()
156 set(_alib_stdlib libstdc++)
157 endif()
158 elseif(MSVC)
159 set(_alib_stdlib msvc)
160 endif()
161
162 # arch
163 string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _alib_arch)
164 if(_alib_arch STREQUAL "")
165 set(_alib_arch unknown)
166 endif()
167
168 # build type
169 if(CMAKE_BUILD_TYPE STREQUAL "")
170 set(CMAKE_BUILD_TYPE Debug)
171 endif()
172 string(TOLOWER "${CMAKE_BUILD_TYPE}" _alib_bt)
173
174 # C++ standard token
175 if(NOT DEFINED CMAKE_CXX_STANDARD)
176 set(CMAKE_CXX_STANDARD 20)
177 endif()
178 set(_alib_cxx cxx${CMAKE_CXX_STANDARD})
179
180 # ABI relevant flags (mirror of runtime asserted flags) todo: check for completion
181 set(ALIB_ABI_FLAGS
182 ALIB_SINGLE_THREADED
183 ALIB_THREADMODEL
184 ALIB_EXCEPTIONS
185 ALIB_MONOMEM
186 ALIB_STRINGS
187 ALIB_SINGLETONS
188 ALIB_BOXING
189 ALIB_ENUMRECORDS
190 ALIB_SYSTEM
191 ALIB_FORMAT
192 ALIB_ALOX
193 ALIB_EXPRESSIONS
194 ALIB_CLI
195 ALIB_BITBUFFER
196 ALIB_VARIABLES
197 ALIB_RESOURCES
198 ALIB_FILES
199 # Additional feature/debug flags influencing file naming and potentially ABI
200 ALIB_DEBUG
201 ALIB_DEBUG_CRITICAL_SECTIONS
202 ALIB_DEBUG_ALLOCATIONS
203 ALIB_DEBUG_MEMORY
204 ALIB_FEAT_SINGLETON_MAPPED
205 ALIB_CHARACTERS_WIDE
206 ALIB_CHARACTERS_SIZEOF_WCHAR
207 ALIB_FEAT_BOOST_REGEX
208 ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
209 ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
210 ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
211 )
212 list(REMOVE_DUPLICATES ALIB_ABI_FLAGS)
213
214 set(_alib_flags_sig "")
215 foreach(_f IN LISTS ALIB_ABI_FLAGS)
216 if(DEFINED ${_f})
217 if(${_f})
218 set(_v 1)
219 else()
220 set(_v 0)
221 endif()
222 else()
223 set(_v 0)
224 endif()
225 string(APPEND _alib_flags_sig "${_f}${_v};")
226 endforeach()
227 string(SHA1 _alib_flags_hash "${_alib_flags_sig}")
228 string(SUBSTRING "${_alib_flags_hash}" 0 8 _alib_flags_hash8)
229
230 set(ALIB_VARIANT_KEY "${_alib_os}-${shortcc}-${_alib_ccver}-${_alib_stdlib}-${_alib_cxx}-${_alib_bt}-${_alib_arch}-f${_alib_flags_hash8}")
231 set(ALIB_VARIANT_KEY_OVERRIDE "" CACHE STRING "Override the computed ALIB variant key")
232 if(ALIB_VARIANT_KEY_OVERRIDE)
233 set(ALIB_VARIANT_KEY "${ALIB_VARIANT_KEY_OVERRIDE}")
234 endif()
235 message(STATUS "ALib variant key: ${ALIB_VARIANT_KEY}")
236
237 # Compose version tag for directory layering from existing version variables
238 # Result example: V2511R0
239 set(_alib_version_tag "V${ALIB_VERSION_NO}R${ALIB_VERSION_REV}")
240
241 # Default user-local install prefix per platform
242 if(APPLE)
243 set(_alib_user_prefix "$ENV{HOME}/Library/ALib/${_alib_version_tag}/${ALIB_VARIANT_KEY}")
244 elseif(WIN32)
245 if(DEFINED ENV{LocalAppData} AND NOT "$ENV{LocalAppData}" STREQUAL "")
246 set(_alib_user_prefix "$ENV{LocalAppData}/ALib/${_alib_version_tag}/${ALIB_VARIANT_KEY}")
247 else()
248 set(_alib_user_prefix "$ENV{USERPROFILE}/.alib/${_alib_version_tag}/${ALIB_VARIANT_KEY}")
249 endif()
250 else()
251 set(_alib_user_prefix "$ENV{HOME}/.local/alib/${_alib_version_tag}/${ALIB_VARIANT_KEY}")
252 endif()
253
254 # Decide final install prefix
255 if(ALIB_INSTALL_PREFIX_OVERRIDE)
256 set(_alib_install_prefix "${ALIB_INSTALL_PREFIX_OVERRIDE}")
257 elseif(ALIB_LOCAL_INSTALL)
258 set(_alib_install_prefix "${_alib_user_prefix}")
259 elseif(DEFINED CMAKE_INSTALL_PREFIX AND NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "")
260 set(_alib_install_prefix "${CMAKE_INSTALL_PREFIX}")
261 else()
262 set(_alib_install_prefix "/usr/local")
263 endif()
264 set(CMAKE_INSTALL_PREFIX "${_alib_install_prefix}" CACHE PATH "Install prefix" FORCE)
265 message(STATUS "ALib install prefix: ${CMAKE_INSTALL_PREFIX}")
266
267 # RPATH defaults for non-Windows
268 if(NOT WIN32)
269 set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
270 set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
271 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
272 if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}")
273 if(APPLE)
274 set(CMAKE_MACOSX_RPATH ON)
275 set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR};${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
276 else()
277 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
278 endif()
279 endif()
280 endif()
281
282# --------------------------------------------------------------------------------------------------
283# ALib Module Dependency Resolution
284# --------------------------------------------------------------------------------------------------
285
286 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
287
288# --------------------------------------------------------------------------------------------------
289# ALib Cache Variables
290# The variables are only set, if not already predefined prior to invoking this script.
291# --------------------------------------------------------------------------------------------------
292
293# --------- ALIB_DEBUG, ALIB_DEBUG_GLIB, ALIB_COVERAGE_COMPILE ---------
294if( NOT DEFINED ALIB_DEBUG )
295 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
296 set( ALIB_DEBUG "On" )
297 else()
298 set( ALIB_DEBUG "Off" )
299 endif()
300endif()
301CacheAsBool( ALIB_DEBUG
302 "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." )
303
304if( NOT DEFINED ALIB_DEBUG_GLIB )
305 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
306 set( ALIB_DEBUG_GLIB "Off" )
307 else()
308 set( ALIB_DEBUG_GLIB "Off" )
309 endif()
310endif()
311CacheAsBool( ALIB_DEBUG_GLIB
312 "Defaults to false. If true, the configuration macros '_GLIBCXX_DEBUG', '_GLIBCXX_DEBUG_PEDANTIC' and '_GLIBCPP_CONCEPT_CHECKS' are set." )
313
314
315if( NOT DEFINED ALIB_COVERAGE_COMPILE )
316 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
317 set( ALIB_COVERAGE_COMPILE "Off" )
318 else()
319 set( ALIB_COVERAGE_COMPILE "Off" )
320 endif()
321endif()
322CacheAsBool( ALIB_COVERAGE_COMPILE
323 "Defaults to false. If true, option --coverage is added to GNU compiler command-line.")
324# --------- ALIB_DEBUG_CRITICAL_SECTIONS, ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH ---------
325if (NOT DEFINED ALIB_DEBUG_CRITICAL_SECTIONS)
326 SetToNot(ALIB_DEBUG_CRITICAL_SECTIONS ALIB_SINGLE_THREADED)
327elseif( ALIB_DEBUG
328 AND ALIB_SINGLE_THREADED
329 AND ALIB_DEBUG_CRITICAL_SECTIONS )
330 message( "ALIB_DEBUG_CRITICAL_SECTIONS=On given while ALIB_SINGLE_THREADED=On. Disabling ALIB_DEBUG_CRITICAL_SECTIONS " )
331 Set(ALIB_DEBUG_CRITICAL_SECTIONS "Off")
332endif()
333
334if( NOT ALIB_DEBUG )
335 if( ${ALIB_DEBUG_CRITICAL_SECTIONS} )
336 message( "ALIB_DEBUG_CRITICAL_SECTIONS=On given while ALIB_DEBUG=off. Disabling ALIB_DEBUG_CRITICAL_SECTIONS " )
337 Set(ALIB_DEBUG_CRITICAL_SECTIONS "Off")
338 endif()
339endif()
340
341CacheAsBool( ALIB_DEBUG_CRITICAL_SECTIONS
342 "Defaults to true unless ALIB_SINGLE_THREADED is set.")
343
344if ( ${ALIB_DEBUG_CRITICAL_SECTIONS} )
345 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
346else()
347 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
348endif()
349
350
351if( NOT DEFINED ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH )
352 If( ALIB_DEBUG )
353 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH "On" )
354 else()
355 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH ALIB_SINGLE_THREADED )
356 endif()
357endif()
358
359CacheAsBool( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH
360 "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." )
361
362
363# --------- Others ---------
364if( NOT DEFINED ALIB_PRECOMPILED_HEADER )
365 set( ALIB_PRECOMPILED_HEADER "Off" CACHE BOOL
366 "If on, header file ’alib_precompile.hpp' will included some default headers, depending on the selected modules. Defaults to off." )
367endif()
368if ( ${ALIB_PRECOMPILED_HEADER} )
369 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
370else()
371 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
372endif()
373
374if( NOT DEFINED ALIB_CMAKE_VERBOSE )
375 set( ALIB_CMAKE_VERBOSE "Off" CACHE BOOL
376 "If true, CMake generation runs will provide a detailed report." )
377endif()
378
379
380# --------- ALIB_DEBUG_ALLOCATIONS ---------
381if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
382 CacheAsBool( ALIB_DEBUG_ALLOCATIONS
383 "Adds allocation debug mechanics with lang::HeapAllocator and ALib Monomem allocators. Defaults to false." )
384endif()
385
386
387# --------- Per module values ---------
388if( "SINGLETONS" IN_LIST ALibBuild )
389 if ( ${WIN32} )
390 set( platformDefaultFor_SINGLETON_MAPPED "On" )
391 else()
392 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
393 endif()
394 if( NOT DEFINED ALIB_FEAT_SINGLETON_MAPPED )
395 set( ALIB_FEAT_SINGLETON_MAPPED ${platformDefaultFor_SINGLETON_MAPPED} CACHE BOOL
396 "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.")
397 endif()
398endif()
399
400if( "BITBUFFER" IN_LIST ALibBuild )
401 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
402 if( NOT DEFINED ALIB_DEBUG_ARRAY_COMPRESSION )
403 set( ALIB_DEBUG_ARRAY_COMPRESSION "On" CACHE BOOL
404 "If true, in debug compilations, compressed arrays are read back to check if result is same. Defaults to true." )
405 endif()
406 endif()
407endif()
408
409if( "CONTAINERS" IN_LIST ALibBuild )
410 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
411 if( NOT DEFINED ALIB_DEBUG_CONTAINERS )
412 set( ALIB_DEBUG_CONTAINERS "Off" CACHE BOOL
413 "Adds debug features to module ALib Containers. Defaults to false." )
414 endif()
415 endif()
416endif()
417
418if( "MONOMEM" IN_LIST ALibBuild )
419 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
420 if( NOT DEFINED ALIB_DEBUG_MEMORY )
421 set( ALIB_DEBUG_MEMORY "Off" CACHE BOOL
422 "Adds consistency checks and collection of statistics with module ALib Monomem. Defaults to false." )
423 endif()
424 endif()
425endif()
426
427
428if( "BOXING" IN_LIST ALibBuild )
429 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
430 set( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS "Off" CACHE BOOL
431 "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.")
432 endif()
433
434 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
435 set( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS "Off" CACHE BOOL
436 "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.")
437 endif()
438
439 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
440 set( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS "Off" CACHE BOOL
441 "If true, type float will be boxed as float. If false (the default) float will be boxed as double and cannot be unboxed.")
442 endif()
443
444 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
445 if( NOT DEFINED ALIB_DEBUG_BOXING )
446 set( ALIB_DEBUG_BOXING "Off" CACHE BOOL
447 "Adds collection of statistics and debug methods to module ALib Boxing. Defaults to false." )
448 endif()
449 endif()
450endif()
451
452# "CHARACTERS"
453 if ( ${WIN32} )
454 set( defaultALIB_CHARACTERS_WIDE "On" )
455 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
456 else()
457 set( defaultALIB_CHARACTERS_WIDE "Off" )
458 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
459 endif()
460
461 if( NOT DEFINED ALIB_CHARACTERS_WIDE )
462 set( ALIB_CHARACTERS_WIDE ${defaultALIB_CHARACTERS_WIDE} CACHE BOOL
463 "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.")
464 endif()
465
466 if( NOT DEFINED ALIB_CHARACTERS_SIZEOF_WCHAR )
467 set( ALIB_CHARACTERS_SIZEOF_WCHAR ${defaultALIB_CHARACTERS_SIZEOF_WCHAR} CACHE STRING
468 "The width of wide characters, maybe 2 or 4. Default value depends on platform/compiler preference.")
469 endif()
470
471
472if( "STRINGS" IN_LIST ALibBuild )
473 if( NOT DEFINED ALIB_FEAT_BOOST_REGEX )
474 set( ALIB_FEAT_BOOST_REGEX "Off" CACHE BOOL
475 "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.")
476 endif()
477
478 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
479 if( NOT DEFINED ALIB_DEBUG_STRINGS )
480 set( ALIB_DEBUG_STRINGS "Off" CACHE BOOL
481 "Defaults to false. Adds consistency checks to ALib string classes. Useful when developing code to manipulate strings externally, i.e AppendableTraits to specializations.")
482 endif()
483 endif()
484endif()
485
486if( "CAMP" IN_LIST ALibBuild )
487 if( NOT DEFINED ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
488 set( ALIB_CAMP_OMIT_DEFAULT_RESOURCES "Off" CACHE BOOL
489 "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.")
490 endif()
491
492 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
493 CacheAsBool( ALIB_DEBUG_RESOURCES
494 "Adds collection of statistics and resource export with module ALib Resources. Defaults to false." )
495 endif()
496
497endif()
498
499if( "FILES" IN_LIST ALibBuild )
500 if( NOT DEFINED ALIB_FILES_FORCE_STD_SCANNER )
501 set( ALIB_FILES_FORCE_STD_SCANNER "Off" CACHE BOOL
502 "If true, file scanning of ALib camp 'Files' falls back to a basic implementation using C++ library std::filesystem.")
503 endif()
504endif()
505
506if( "ALOX" IN_LIST ALibBuild )
507
508 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
509 set( defaultALOX_DBG_LOG "On" )
510 else()
511 set( defaultALOX_DBG_LOG "Off" )
512 endif()
513 if( NOT DEFINED ALOX_DBG_LOG )
514 set( ALOX_DBG_LOG ${defaultALOX_DBG_LOG} CACHE BOOL
515 "Enable/disable debug log statements. Defaults to true with debug builds, otherwise to false." )
516 endif()
517
518 if( NOT DEFINED ALOX_DBG_LOG_CI )
519 set( ALOX_DBG_LOG_CI "On" CACHE BOOL
520 "Defaults to true. If set, caller information is used with debug log statements." )
521 endif()
522
523 if( NOT DEFINED ALOX_REL_LOG )
524 set( ALOX_REL_LOG "On" CACHE BOOL
525 "Enable/disable release log statements. Defaults to true." )
526 endif()
527
528 if( NOT DEFINED ALOX_REL_LOG_CI )
529 set( ALOX_REL_LOG_CI "Off" CACHE BOOL
530 "Defaults to false. If set, caller information is used even with release log statements (and even in release builds!)" )
531 endif()
532endif()
533
534# --------------------------------------------------------------------------------------------------
535# Configuration macros
536# --------------------------------------------------------------------------------------------------
537
538# module selection
539if( NOT ALibAllModules )
540 SET( moduleList "" )
541 LIST( APPEND moduleList "ALOX;APP;BITBUFFER;BOXING;CAMP;CLI;CONTAINERS" )
542 LIST( APPEND moduleList "ENUMRECORDS;EXCEPTIONS;EXPRESSIONS;FILES;FORMAT" )
543 LIST( APPEND moduleList "MONOMEM;RESOURCES;SINGLETONS;STRINGS;SYSTEM" )
544 LIST( APPEND moduleList "THREADMODEL;VARIABLES" )
545 FOREACH( module IN LISTS moduleList )
546 IF( module IN_LIST ALibBuild )
547 list( APPEND ALIB_SYMBOLS "ALIB_${module}" )
548 ENDIF()
549 ENDFOREACH()
550endif()
551
552# debug
553if ( ${ALIB_DEBUG} )
554 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
555
556 if ( ${ALIB_DEBUG_GLIB} )
557 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
558 "_GLIBCXX_DEBUG_PEDANTIC"
559 "_GLIBCPP_CONCEPT_CHECKS" )
560 else()
561 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
562 "_GLIBCXX_DEBUG_PEDANTIC"
563 "_GLIBCPP_CONCEPT_CHECKS" )
564 endif()
565endif()
566
567# ALib features
568if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
569 if ( ALIB_DEBUG_ALLOCATIONS )
570 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ALLOCATIONS" )
571 else()
572 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ALLOCATIONS" )
573 endif()
574endif()
575
576
577if( "SINGLETONS" IN_LIST ALibBuild )
578 if (NOT platformDefaultFor_SINGLETON_MAPPED STREQUAL ALIB_FEAT_SINGLETON_MAPPED)
579 if ( ALIB_FEAT_SINGLETON_MAPPED )
580 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED" )
581 else()
582 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
583 endif()
584 else()
585 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
586 endif()
587endif()
588
589if( "BITBUFFER" IN_LIST ALibBuild )
590 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
591 if ( ALIB_DEBUG_ARRAY_COMPRESSION )
592 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=1" )
593 else()
594 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION=0" )
595 endif()
596 endif()
597endif()
598
599if( "BOXING" IN_LIST ALibBuild )
600 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
601 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
602 else()
603 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
604 endif()
605 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
606 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
607 else()
608 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
609 endif()
610 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
611 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
612 else()
613 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
614 endif()
615 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
616 if( ALIB_DEBUG_BOXING )
617 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
618 else()
619 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
620 endif()
621 endif()
622endif()
623
624# "CHARACTERS"
625 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
626 if ( ALIB_CHARACTERS_WIDE )
627 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
628 else()
629 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
630 endif()
631 else()
632 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
633 endif()
634
635 if (NOT defaultALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL ALIB_CHARACTERS_SIZEOF_WCHAR)
636 if ( NOT (ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" OR ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "4") )
637 message( FATAL_ERROR "Value of ALIB_CHARACTERS_SIZEOF_WCHAR must be 2 or 4" )
638 return()
639 endif()
640 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
641 else()
642 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
643 endif()
644
645
646if( "CONTAINERS" IN_LIST ALibBuild
647 AND CMAKE_BUILD_TYPE STREQUAL "Debug" )
648 if ( ALIB_DEBUG_CONTAINERS )
649 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CONTAINERS" )
650 else()
651 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CONTAINERS" )
652 endif()
653endif()
654
655if( ALIB_SINGLE_THREADED )
656 list( APPEND ALIB_SYMBOLS "ALIB_SINGLE_THREADED" )
657else()
658 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_SINGLE_THREADED" )
659
660 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
661 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
662 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_CRITICAL_SECTIONS" )
663 else()
664 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_CRITICAL_SECTIONS" )
665 endif()
666 endif()
667endif()
668
669
670if( "MONOMEM" IN_LIST ALibBuild )
671 if ( ALIB_DEBUG )
672 if ( ALIB_DEBUG_MEMORY )
673 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MEMORY" )
674 else()
675 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MEMORY" )
676 endif()
677 endif()
678endif()
679
680if( "STRINGS" IN_LIST ALibBuild )
681 if ( ALIB_FEAT_BOOST_REGEX )
682 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
683 else()
684 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
685 endif()
686
687 if ( ALIB_DEBUG )
688 if ( ALIB_DEBUG_STRINGS )
689 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
690 else()
691 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
692 endif()
693 endif()
694endif()
695
696if( "CAMP" IN_LIST ALibBuild )
697
698 if( ALIB_CAMP_OMIT_DEFAULT_RESOURCES )
699 list( APPEND ALIB_SYMBOLS "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
700 else()
701 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CAMP_OMIT_DEFAULT_RESOURCES" )
702 endif()
703
704 if ( ALIB_DEBUG )
705 if( ALIB_DEBUG_RESOURCES )
706 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
707 else()
708 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
709 endif()
710 endif()
711endif()
712
713if( "FILES" IN_LIST ALibBuild )
714 if ( ALIB_FILES_FORCE_STD_SCANNER )
715 list( APPEND ALIB_SYMBOLS "ALIB_FILES_FORCE_STD_SCANNER" )
716 else()
717 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FILES_FORCE_STD_SCANNER" )
718 endif()
719endif()
720
721if( "ALOX" IN_LIST ALibBuild )
722
723 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
724 if( NOT ALOX_DBG_LOG )
725 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
726 else()
727 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
728 endif()
729
730 if ( NOT ${ALOX_DBG_LOG_CI} )
731 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
732 else()
733 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
734 endif()
735 else()
736 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
737 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
738 endif()
739
740 if ( NOT ALOX_REL_LOG )
741 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
742 else()
743 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
744 endif()
745 if ( ALOX_REL_LOG_CI )
746 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
747 else()
748 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
749 endif()
750endif()
751
752
753
754# --------------------------------------------------------------------------------------------------
755# ALib Source File Definition
756# --------------------------------------------------------------------------------------------------
757include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
758
759
760# --------------------------------------------------------------------------------------------------
761# External libraries
762# --------------------------------------------------------------------------------------------------
763if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
764 find_package(Threads)
765 if(Threads_FOUND)
766 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
767 if(CMAKE_USE_PTHREADS_INIT)
768 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
769 endif()
770 endif()
771
772 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
773endif()
774
775if ( ${ALIB_FEAT_BOOST_REGEX} )
776 set(Boost_USE_STATIC_LIBS "On" CACHE BOOL "Link boost statically" )
777 if( NOT DEFINED ALIB_SINGLE_THREADED )
778 set(Boost_USE_MULTITHREADED "On" CACHE BOOL "Use multithreaded version of boost")
779 else()
780 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
781 endif()
782
783 find_package( Boost CONFIG REQUIRED COMPONENTS regex )
784
785 if(Boost_FOUND)
786 list( APPEND ALIB_EXTERNAL_LIBS Boost::regex )
787 if(${Boost_USE_STATIC_LIBS})
788 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost static libraries")
789 else()
790 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
791 endif()
792 else()
793 MESSAGE("Attention: Boost::regex requested, but library not found!")
794 endif()
795endif()
796
797if(APPLE)
798 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
799endif()
800
801if(NOT MSVC)
802 if(NOT APPLE)
803 list( APPEND ALIB_EXTERNAL_LIBS "m")
804 endif(NOT APPLE)
805endif(NOT MSVC)
806
807
808
809
810# --------------------------------------------------------------------------------------------------
811# A-Worx compiler features and flags
812# --------------------------------------------------------------------------------------------------
813
814# Set minimum required standard C++20
815list( APPEND ALIB_COMPILER_FEATURES "cxx_std_20" )
816
817# if "ALIB_SUPPRESS_COMPILER_WARNINGS" is set prior to invoking this script, this entry is removed
818# and nothing is added.
819if ("ALIB_SUPPRESS_COMPILER_WARNINGS" IN_LIST ALIB_COMPILER_WARNINGS)
820 LIST( REMOVE_ITEM ALIB_COMPILER_WARNINGS "ALIB_SUPPRESS_COMPILER_WARNINGS" )
821else()
822 if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
823 # add -H to generate output "!/x" for use of precompiled header
824 list( APPEND ALIB_COMPILER_WARNINGS "-Wall" )
825 list( APPEND ALIB_COMPILER_WARNINGS "-Wextra" )
826 #list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
827 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-psabi" )
828 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
829
830 # this was "suddenly" needed with GCC 13.2.1 with release compilation
831 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
832
833 # add coverage flags to GCC
834 if( ${ALIB_COVERAGE_COMPILE} )
835 list( APPEND ALIB_COMPILER_OPTIONS "--coverage" )
836 list( APPEND ALIB_LINKER_OPTIONS "--coverage" )
837 endif()
838
839 # force unicode (needed for mingw)
840 if(MINGW)
841 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
842 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
843 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
844 endif()
845
846
847 # Clang: We are using -Weverything, although this is not recommended. We think it should be
848 # recommended. ALib, for example, does not use old-style casts and explicitly cast each
849 # and every type change! The benefit for ALib users is that ALib code can be used in very
850 # strict build environments without using special warning flags.
851 # Of course, some very obvious warnings then have to be removed explicitly:
852 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
853 list( APPEND ALIB_COMPILER_WARNINGS "-pedantic" )
854 list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
855 list( APPEND ALIB_COMPILER_WARNINGS "-Weverything" )
856 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unknown-warning-option" )
857 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++20-extensions" )
858 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++20-compat" )
859 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat" )
860 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat-pedantic" )
861 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-covered-switch-default" )
862 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-decls-in-multiple-modules" )
863 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-deprecated-declarations" )
864 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-documentation-unknown-command" )
865 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-exit-time-destructors" )
866 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-global-constructors" )
867 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-ms-bitfield-padding" )
868 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
869 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-padded" )
870 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-weak-vtables" )
871 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-thread-safety-analysis" )
872
873 # Note: After fighting with this for a while and locally removing the warning in many
874 # places, we gave up with Clang 19 and C++20 module compilation. Strangely, with the
875 # latter activated, Clang became even more suspicious and we decided to switch it off.
876 # It seems that also a bigger part of the community sees it that way. Where is the
877 # point to using a std::array instead of a C-array when std::array does no bounds
878 # check?
879 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-unsafe-buffer-usage" )
880
881 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
882 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
883 endif()
884
885 # MSVC
886 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" )
887 list( APPEND ALIB_COMPILER_WARNINGS "/W4" )
888 list( APPEND ALIB_COMPILER_WARNINGS "/WX" )
889 list( APPEND ALIB_COMPILER_WARNINGS "/EHsc" )
890 endif()
891endif()
892
893# --------------------------------------------------------------------------------------------------
894# A-Worx linker features and flags
895# --------------------------------------------------------------------------------------------------
896if(APPLE)
897 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
898else()
899 list( APPEND ALIB_LINKER_OPTIONS "" )
900endif()
901
902
903# -------------------------------------------------------------------------------------------------
904# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
905# -------------------------------------------------------------------------------------------------
906# TODO(251204 10:40): Respect module App. What else? Check!
907
908if ( NOT ALIB_LIBRARY_FILENAME )
909 # Base stable name used when ALIB_STABLE_OUTPUT_NAME is ON
910 set( ALIB_LIBRARY_FILENAME_STABLE "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
911 # Legacy, feature-encoded name (default)
912 set( ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME_STABLE}" )
913
914 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_DEBUG} )
915 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
916 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBG )
917 else()
918 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}RELDBG )
919 endif()
920 if( DEFINED ALIB_SINGLE_THREADED )
921 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ST )
922 endif()
923 if ( ALIB_DEBUG_CRITICAL_SECTIONS )
924 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DCS )
925 endif()
926 if ( ALIB_DEBUG_ALLOCATIONS )
927 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DALC )
928 endif()
929 elseif( NOT ALIB_STABLE_OUTPUT_NAME )
930 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") )
931 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}DBGREL )
932 endif()
933 endif()
934
935 # Add features
936 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_FEAT_SINGLETON_MAPPED} )
937 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MS )
938 endif()
939 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_CHARACTERS_WIDE} )
940 if ( ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" )
941 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC2 )
942 else()
943 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_WC4 )
944 endif()
945 endif()
946 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_FEAT_BOOST_REGEX} )
947 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BREGEX )
948 endif()
949 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS} )
950 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJCHARS )
951 endif()
952 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_FEAT_BOXING_BIJECTIVE_FLOATS} )
953 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJFLOATS )
954 endif()
955 if ( NOT ALIB_STABLE_OUTPUT_NAME AND ${ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS} )
956 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BIJINTS )
957 endif()
958
959 # Add all module's names, prefixed by "DBG" if special debug flag is set
960 if( NOT ALIB_STABLE_OUTPUT_NAME AND NOT ALibAllModules )
961 FOREACH(modName IN LISTS ALibBuild)
962
963 # BOXING debug mode?
964 IF( modName STREQUAL "BOXING" )
965 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
966 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGBOXING )
967 else()
968 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_BOXING )
969 endif()
970
971 # CONTAINERS debug mode?
972 ELSEIF( modName STREQUAL "CONTAINERS" )
973 if ( ALIB_DEBUG_CONTAINERS AND ALIB_DEBUG )
974 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGCONTAINERS )
975 else()
976 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_CONTAINERS )
977 endif()
978
979 # MONOMEM debug mode?
980 ELSEIF( modName STREQUAL "MONOMEM" )
981 if ( ALIB_DEBUG_MEMORY AND ALIB_DEBUG )
982 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGMONOMEM )
983 else()
984 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_MONOMEM )
985 endif()
986
987 # STRINGS debug mode?
988 ELSEIF( modName STREQUAL "STRINGS" )
989 if ( ALIB_DEBUG_STRINGS AND ALIB_DEBUG )
990 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
991 else()
992 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
993 endif()
994
995 # RESOURCES debug mode?
996 ELSEIF( modName STREQUAL "RESOURCES" )
997 if ( ALIB_DEBUG_RESOURCES AND ALIB_DEBUG )
998 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGRESOURCES )
999 else()
1000 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_RESOURCES )
1001 endif()
1002
1003 # ALOX: add non-default feature s
1004 ELSEIF( modName STREQUAL "ALOX" )
1005 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ALOX )
1006 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT ${ALOX_DBG_LOG}) )
1007 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NDL )
1008 endif()
1009
1010 if ( NOT ALOX_REL_LOG )
1011 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
1012 endif()
1013 ELSE()
1014 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
1015 ENDIF()
1016
1017 ENDFOREACH()
1018
1019
1020 # Remove all dependent modules from the name, which are not added in a debug version:
1021 list( FIND ALibBuild "BOXING" idx )
1022 if( NOT idx LESS 0 )
1023 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1024 endif()
1025
1026 list( FIND ALibBuild "ENUMRECORDS" idx )
1027 if( NOT idx LESS 0 )
1028 STRING(REPLACE "_SINGLETONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1029 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1030 endif()
1031
1032 list( FIND ALibBuild "BITBUFFER" idx )
1033 if( NOT idx LESS 0 )
1034 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1035 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1036 endif()
1037
1038 list( FIND ALibBuild "THREADMODEL" idx )
1039 if( NOT idx LESS 0 )
1040 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1041 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1042 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1043 endif()
1044
1045 list( FIND ALibBuild "SYSTEM" idx )
1046 if( NOT idx LESS 0 )
1047 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1048 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1049 endif()
1050
1051 list( FIND ALibBuild "RESOURCES" idx )
1052 if( NOT idx LESS 0 )
1053 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1054 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1055 STRING(REPLACE "_STRINGS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1056 endif()
1057
1058 list( FIND ALibBuild "EXCEPTIONS" idx )
1059 if( NOT idx LESS 0 )
1060 STRING(REPLACE "_RESOURCES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1061 STRING(REPLACE "_BOXING" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1062 STRING(REPLACE "_ENUMRECORDS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1063 endif()
1064
1065 list( FIND ALibBuild "VARIABLES" idx )
1066 if( NOT idx LESS 0 )
1067 STRING(REPLACE "_SYSTEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1068 STRING(REPLACE "_CONTAINERS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1069 STRING(REPLACE "_MONOMEM" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1070 endif()
1071
1072 list( FIND ALibBuild "FORMAT" idx )
1073 if( NOT idx LESS 0 )
1074 STRING(REPLACE "_EXCEPTIONS" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1075 endif()
1076
1077
1078 list( FIND ALibBuild "CAMP" idx )
1079 if( NOT idx LESS 0 )
1080 STRING(REPLACE "_FORMAT" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1081 STRING(REPLACE "_VARIABLES" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1082 endif()
1083
1084 list( FIND ALibBuild "ALOX" idx )
1085 if( NOT idx LESS 0 )
1086 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1087 endif()
1088
1089 list( FIND ALibBuild "CLI" idx )
1090 if( NOT idx LESS 0 )
1091 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1092 endif()
1093
1094 list( FIND ALibBuild "EXPRESSIONS" idx )
1095 if( NOT idx LESS 0 )
1096 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1097 endif()
1098
1099 list( FIND ALibBuild "FILES" idx )
1100 if( NOT idx LESS 0 )
1101 STRING(REPLACE "_CAMP" "" ALIB_LIBRARY_FILENAME "${ALIB_LIBRARY_FILENAME}")
1102 endif()
1103
1104 endif() # not all modules or stable name enabled
1105
1106 endif()
1107
1108# -------------------------------------------------------------------------------------------------
1109# Display result summary
1110# -------------------------------------------------------------------------------------------------
1111message( "ALib CMake Configuration:" )
1112 message( " Modules requested : ${ALIB_BUILD}" )
1113IF( NOT ALibAllModules )
1114 message( " Resulting Selection: ${ALibBuild}" )
1115 message( " Omitted Modules : ${ALibOmittedModules}" )
1116ELSE()
1117 message( " Resulting Selection: All (${ALibBuild})" )
1118ENDIF()
1119
1120 message( " Single-Threaded : ${ALIB_SINGLE_THREADED}" )
1121
1122 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
1123 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}" )
1124
1125IF( NOT ALIB_CMAKE_VERBOSE )
1126 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
1127ELSE()
1128
1129 message( " Source folder : ${ALIB_SOURCE_DIR}" )
1130 LIST( LENGTH ALIB_H length)
1131 message( " File types : *.H: ${length} files" )
1132 LIST( LENGTH ALIB_MPP length)
1133 message( " *.mpp: ${length} files" )
1134 LIST( LENGTH ALIB_INL length)
1135 message( " *.inl: ${length} files" )
1136 LIST( LENGTH ALIB_CPP length)
1137 message( " *.cpp: ${length} files" )
1138 LIST( LENGTH ALIB_HPP length)
1139 message( " *.hpp: ${length} files" )
1140 SET( result "" )
1141 LIST( APPEND result ${ALIB_H} )
1142 LIST( APPEND result ${ALIB_MPP} )
1143 LIST( APPEND result ${ALIB_INL} )
1144 LIST( APPEND result ${ALIB_CPP} )
1145 LIST( APPEND result ${ALIB_HPP} )
1146 LIST( SORT result )
1147 LIST( LENGTH result length)
1148 message( " Total: ${length} source files." )
1149 message( "\n List of files:" )
1150 FOREACH( entry IN LISTS result )
1151 STRING(REPLACE "${ALIB_SOURCE_DIR}/" "" entry ${entry} )
1152 message( " ${entry}" )
1153 ENDFOREACH()
1154
1155 SET( result "" )
1156 LIST( APPEND result ${ALIB_SYMBOLS} )
1157 LIST( SORT result )
1158 LIST( LENGTH result length)
1159 message( "\n Compiler definitions (${length} items):" )
1160 FOREACH( entry IN LISTS result )
1161 message( " ${entry}" )
1162 ENDFOREACH()
1163 SET( result "" )
1164
1165 SET( result "" )
1166 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
1167 LIST( SORT result )
1168 LIST( LENGTH result length)
1169 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
1170 FOREACH( entry IN LISTS result )
1171 message( " ${entry}" )
1172 ENDFOREACH()
1173 SET( result "" )
1174
1175 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
1176 LIST( SORT result )
1177 LIST( LENGTH result length)
1178 message( "\n Compiler warnings (${length} items):" )
1179 FOREACH( entry IN LISTS result )
1180 message( " ${entry}" )
1181 ENDFOREACH()
1182 SET( result "" )
1183
1184 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
1185 LIST( SORT result )
1186 LIST( LENGTH result length)
1187 message( "\n Compiler flags (${length} items):" )
1188 FOREACH( entry IN LISTS result )
1189 message( " ${entry}" )
1190 ENDFOREACH()
1191 SET( result "" )
1192
1193 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
1194 LIST( SORT result )
1195 LIST( LENGTH result length)
1196 message( "\n Compiler features (${length} items):" )
1197 FOREACH( entry IN LISTS result )
1198 message( " ${entry}" )
1199 ENDFOREACH()
1200 SET( result "" )
1201
1202 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
1203 LIST( SORT result )
1204 LIST( LENGTH result length)
1205 message( "\n External libraries (${length} items):" )
1206 FOREACH( entry IN LISTS result )
1207 message( " ${entry}" )
1208 ENDFOREACH()
1209 SET( result "" )
1210
1211 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
1212 LIST( SORT result )
1213 LIST( LENGTH result length)
1214 message( "\n Linker flags (${length} items):" )
1215 FOREACH( entry IN LISTS result )
1216 message( " ${entry}" )
1217 ENDFOREACH()
1218 SET( result "" )
1219
1220 message( "\n" )
1221ENDIF()
1222
1223# -------------------------------------------------------------------------------------------------
1224# ALibFilterSupportedCompilerFlags()
1225# Checks the flags in the given list for compatibility with current C/C++ compiler.
1226# -------------------------------------------------------------------------------------------------
1227include(CheckCCompilerFlag)
1228include(CheckCXXCompilerFlag)
1229
1230# filter_supported_flags(<C|CXX> <out-var> <flags...>)
1231macro(ALibFilterSupportedCompilerFlags LANG VAR)
1232 # Short-circuit only in actual try_compile sub-configures
1233 if(DEFINED CMAKE_TRY_COMPILE OR PROJECT_NAME MATCHES "^cmTC_")
1234 set(${VAR} "${ARGN}")
1235 return()
1236 endif()
1237
1238 # (Optional) debug
1239 #message(STATUS "filter_supported_flags: LANG=${LANG} input=[${ARGN}]")
1240
1241 set(_saved ${CMAKE_REQUIRED_QUIET})
1242 set(CMAKE_REQUIRED_QUIET ON)
1243
1244 set(_supported)
1245 foreach(FLAG ${ARGN}) # classic form—works on all CMake versions
1246 string(MD5 _key
1247 "${CMAKE_${LANG}_COMPILER_ID};${CMAKE_${LANG}_COMPILER_VERSION};${LANG};${FLAG}")
1248
1249 if(${LANG} STREQUAL "C")
1250 check_c_compiler_flag("${FLAG}" _has_${_key})
1251 if(_has_${_key})
1252 list(APPEND _supported "${FLAG}")
1253 else()
1254 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1255 endif()
1256 elseif(${LANG} STREQUAL "CXX")
1257 check_cxx_compiler_flag("${FLAG}" _has_${_key})
1258 if(_has_${_key})
1259 list(APPEND _supported "${FLAG}")
1260 else()
1261 message("ALib: Dropping compiler flag '${FLAG}' (not supported)")
1262 endif()
1263 else()
1264 message(FATAL_ERROR "filter_supported_flags: LANG must be C or CXX. Given ${LANG}")
1265 endif()
1266 endforeach()
1267
1268 set(CMAKE_REQUIRED_QUIET ${_saved})
1269 set(${VAR} "${_supported}") # macro: mutates caller scope
1270 #message(STATUS "filter_supported_flags: output=[${${VAR}}]")
1271endmacro()
1272
1273
1274# -------------------------------------------------------------------------------------------------
1275# ALibSetCompilerAndLinker(target)
1276#
1277# Simple CMake function that sets
1278# - ALIB_SYMBOLS
1279# - ALIB_COMPILER_FEATURES
1280# - ALIB_COMPILER_OPTIONS
1281# - ALIB_COMPILER_WARNINGS
1282# - ALIB_LINKER_OPTIONS
1283#
1284# In addition, position independent compile (-fPic) is enabled (for static libraries its default
1285# is off with CMake).
1286# -------------------------------------------------------------------------------------------------
1287function( ALibSetCompilerAndLinker target )
1288 message("${target}: Applying ALib compiler and linker settings")
1289
1290 # compiler flags
1291 ALibFilterSupportedCompilerFlags(CXX ALIB_COMPILER_WARNINGS ${ALIB_COMPILER_WARNINGS})
1292 target_compile_features ( ${target} PRIVATE ${ALIB_COMPILER_FEATURES} )
1293 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_OPTIONS} )
1294 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_WARNINGS} )
1295 set_property ( TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON )
1296 # Export proper include dirs for build and install; consumers get INSTALL_INTERFACE
1297 # Use absolute source roots to be robust in superbuilds/IDE subprojects
1298 # Add build-interface include dirs in separate calls to avoid list parsing quirks
1299 target_include_directories( ${target} PUBLIC $<BUILD_INTERFACE:${ALIB_BASE_DIR}/src> )
1300 target_include_directories( ${target} PUBLIC $<BUILD_INTERFACE:${ALIB_BASE_DIR}/src/alib> )
1301 target_include_directories( ${target} PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
1302
1303 IF(DEFINED ALIB_PRECOMPILED_HEADER)
1304 IF(ALIB_PRECOMPILED_HEADER)
1305 target_precompile_headers( ${target} PRIVATE "${ALIB_SOURCE_DIR}/alib_precompile.hpp" )
1306 ENDIF()
1307 ENDIF()
1308
1309 #definitions
1310 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
1311
1312 # linker flags
1313 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
1314 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
1315 ENDIF()
1316 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
1317 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
1318 ENDIF()
1319
1320 # Use clang's own stdc++ library if requested
1321 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND ALIB_CLANG_USE_LIBCPP )
1322 target_compile_options(${target} PRIVATE -stdlib=libc++)
1323 target_link_libraries( ${target} PRIVATE c++)
1324 endif()
1325
1326 # With MSVC force UTF8 encoding of string literals
1327 if (MSVC)
1328 target_compile_options(${target} PRIVATE /utf-8)
1329 endif()
1330
1331endfunction()
1332
1333# -------------------------------------------------------------------------------------------------
1334# Targets
1335# -------------------------------------------------------------------------------------------------
1336function( ALibAddStaticLibrary )
1337 # sources
1338 add_library ( ALib_StaticLib STATIC )
1339
1340 target_sources ( ALib_StaticLib PRIVATE ${ALIB_CPP} )
1341 message("ALib_SharedLib target added")
1342
1343 ALibSetCompilerAndLinker ( ALib_StaticLib )
1344 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1345
1346 # Set up install/export after targets exist
1347 ALibSetupInstallAndConfig()
1348endfunction()
1349
1350function( ALibAddSharedLibrary )
1351 add_library ( ALib_SharedLib SHARED )
1352 target_sources ( ALib_SharedLib PRIVATE ${ALIB_CPP} )
1353 message("ALib_SharedLib target added")
1354
1355 ALibSetCompilerAndLinker ( ALib_SharedLib )
1356 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
1357
1358 if(WIN32)
1359 target_compile_definitions(ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
1360 endif()
1361 # Set up install/export after targets exist
1362 ALibSetupInstallAndConfig()
1363endfunction()
1364
1365## -------------------------------------------------------------------------------------------------
1366## Install/export rules and package config as a function to run after targets exist
1367## -------------------------------------------------------------------------------------------------
1368function(ALibSetupInstallAndConfig)
1369 if(alib_install_config_done)
1370 return()
1371 endif()
1372
1373 # Public headers
1374 set(ALIB_PUBLIC_INCLUDE_DIR "${ALIB_BASE_DIR}/src/alib")
1375
1376 # Provide a real INTERFACE target ALib that links to the preferred lib, exportable for consumers
1377 if(NOT TARGET ALib)
1378 add_library(ALib INTERFACE)
1379 if(TARGET ALib_StaticLib AND NOT ALIB_PREFER_SHARED)
1380 target_link_libraries(ALib INTERFACE ALib_StaticLib)
1381 elseif(TARGET ALib_SharedLib)
1382 target_link_libraries(ALib INTERFACE ALib_SharedLib)
1383 endif()
1384 endif()
1385
1386 # Header installation
1387 if(ALIB_INSTALL_HEADERS_ONLY_SELECTED)
1388 # Install only headers that correspond to the resolved module selection
1389 # Ensure ALIB_SOURCE_DIR is set (provided by ALibSources.cmake)
1390 if(NOT DEFINED ALIB_SOURCE_DIR)
1391 set(ALIB_SOURCE_DIR "${ALIB_BASE_DIR}/src")
1392 endif()
1393
1394 # 1) Public entry headers (live at src root like ALib.Strings.H)
1395# foreach(_h IN LISTS ALIB_H)
1396# install(FILES "${ALIB_SOURCE_DIR}/${_h}"
1397# DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ALib")
1398# endforeach()
1399 foreach(_p IN LISTS ALIB_H)
1400 # _p is already an absolute path (prepared in ALibSources.cmake). Compute subdirectory
1401 # relative to the ALIB_SOURCE_DIR/alib root to mirror the include layout.
1402 file(RELATIVE_PATH _rel "${ALIB_SOURCE_DIR}/" "${_p}")
1403 get_filename_component(_rel_dir "${_rel}" DIRECTORY)
1404 set(_dst "${CMAKE_INSTALL_INCLUDEDIR}/")
1405 if(NOT _rel_dir STREQUAL "" AND NOT _rel_dir STREQUAL ".")
1406 set(_dst "${_dst}/${_rel_dir}")
1407 endif()
1408 install(FILES "${_p}"
1409 DESTINATION "${_dst}")
1410 endforeach()
1411
1412 # 2) Internal headers under src/alib: from ALIB_INL, ALIB_HPP, ALIB_MPP
1413 set(_alib_sel_hdr_lists ${ALIB_INL} ${ALIB_HPP} ${ALIB_MPP})
1414 foreach(_p IN LISTS _alib_sel_hdr_lists)
1415 # _p is already an absolute path (prepared in ALibSources.cmake). Compute subdirectory
1416 # relative to the ALIB_SOURCE_DIR/alib root to mirror the include layout.
1417 file(RELATIVE_PATH _rel "${ALIB_SOURCE_DIR}/alib" "${_p}")
1418 get_filename_component(_rel_dir "${_rel}" DIRECTORY)
1419 set(_dst "${CMAKE_INSTALL_INCLUDEDIR}/alib")
1420 if(NOT _rel_dir STREQUAL "" AND NOT _rel_dir STREQUAL ".")
1421 set(_dst "${_dst}/${_rel_dir}")
1422 endif()
1423 install(FILES "${_p}"
1424 DESTINATION "${_dst}")
1425 endforeach()
1426
1427 else()
1428 # Legacy behavior: install whole header tree from src/alib
1429 install(DIRECTORY "${ALIB_PUBLIC_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/alib" FILES_MATCHING
1430 PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.inl" PATTERN "*.def" PATTERN "*.inc")
1431 endif()
1432
1433 # Library installation and export
1434 if(TARGET ALib_SharedLib)
1435 install(TARGETS ALib_SharedLib
1436 EXPORT ALibTargets
1437 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1438 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1439 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1440 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1441 endif()
1442
1443 if(TARGET ALib_StaticLib)
1444 install(TARGETS ALib_StaticLib
1445 EXPORT ALibTargets
1446 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1447 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1448 endif()
1449
1450 # Export the interface umbrella target as well
1451 if(TARGET ALib)
1452 install(TARGETS ALib EXPORT ALibTargets)
1453 endif()
1454
1455 install(EXPORT ALibTargets
1456 NAMESPACE ${ALIB_EXPORT_NAMESPACE}
1457 FILE ALibTargets.cmake
1458 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ALib)
1459
1460 # Public compile definitions to propagate (only those enabled)
1461 set(ALIB_PUBLIC_COMPILE_DEFINITIONS "")
1462 foreach(_f IN LISTS ALIB_ABI_FLAGS)
1463 if(DEFINED ${_f} AND ${_f})
1464 list(APPEND ALIB_PUBLIC_COMPILE_DEFINITIONS ${_f})
1465 endif()
1466 endforeach()
1467 list(REMOVE_DUPLICATES ALIB_PUBLIC_COMPILE_DEFINITIONS)
1468
1469 # Export include directories and compile definitions via the ALib interface target,
1470 # so consumers get them from ALibTargets.cmake without extra logic in ALibConfig.cmake
1471 if(TARGET ALib)
1472 # Provide build- and install-time include directories
1473 target_include_directories(ALib INTERFACE $<BUILD_INTERFACE:${ALIB_BASE_DIR}/src>)
1474 target_include_directories(ALib INTERFACE $<BUILD_INTERFACE:${ALIB_BASE_DIR}/src/alib>)
1475 target_include_directories(ALib INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
1476 # Provide public compile definitions (ABI flags)
1477 if(ALIB_PUBLIC_COMPILE_DEFINITIONS)
1478 target_compile_definitions(ALib INTERFACE ${ALIB_PUBLIC_COMPILE_DEFINITIONS})
1479 endif()
1480 endif()
1481
1482 # Use ALib version variables if present
1483 # Keep numeric version for CMake package versioning and keep tag format for manifests
1484 if(NOT DEFINED ALIB_VERSION_NUMERIC)
1485 if(DEFINED ALIB_VERSION_NO AND DEFINED ALIB_VERSION_REV)
1486 set(ALIB_VERSION_NUMERIC "${ALIB_VERSION_NO}.${ALIB_VERSION_REV}")
1487 elseif(DEFINED ALIB_VERSION_NO)
1488 set(ALIB_VERSION_NUMERIC "${ALIB_VERSION_NO}")
1489 endif()
1490 endif()
1491
1492 # Expose ALIB_VERSION as numeric as well (used in ALibConfig.cmake)
1493 if(NOT DEFINED ALIB_VERSION)
1494 set(ALIB_VERSION "${ALIB_VERSION_NUMERIC}")
1495 endif()
1496
1497 configure_package_config_file(
1498 "${ALIB_CMAKE_DIR}/ALibConfig.cmake.in"
1499 "${CMAKE_CURRENT_BINARY_DIR}/ALibConfig.cmake"
1500 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ALib
1501 NO_SET_AND_CHECK_MACRO
1502 NO_CHECK_REQUIRED_COMPONENTS_MACRO)
1503
1504 write_basic_package_version_file(
1505 "${CMAKE_CURRENT_BINARY_DIR}/ALibConfigVersion.cmake"
1506 VERSION ${ALIB_VERSION_NUMERIC}
1507 COMPATIBILITY SameMajorVersion)
1508
1509 install(FILES
1510 "${CMAKE_CURRENT_BINARY_DIR}/ALibConfig.cmake"
1511 "${CMAKE_CURRENT_BINARY_DIR}/ALibConfigVersion.cmake"
1512 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ALib)
1513
1514 # Optional: write a simple manifest for debugging
1515 set(_alib_manifest "${CMAKE_CURRENT_BINARY_DIR}/ALibVariant.txt")
1516 file(WRITE "${_alib_manifest}" "ALib Variant\n")
1517 file(APPEND "${_alib_manifest}" "VariantKey: ${ALIB_VARIANT_KEY}\n")
1518 file(APPEND "${_alib_manifest}" "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\n")
1519 file(APPEND "${_alib_manifest}" "StdLib: ${_alib_stdlib}\n")
1520 file(APPEND "${_alib_manifest}" "CXX Standard: ${CMAKE_CXX_STANDARD}\n")
1521 file(APPEND "${_alib_manifest}" "BuildType: ${CMAKE_BUILD_TYPE}\n")
1522 file(APPEND "${_alib_manifest}" "Arch: ${_alib_arch}\n")
1523 file(APPEND "${_alib_manifest}" "Flags: ${_alib_flags_sig}\n")
1524 file(APPEND "${_alib_manifest}" "VersionTag: ${_alib_version_tag}\n")
1525 install(FILES "${_alib_manifest}" DESTINATION ${CMAKE_INSTALL_DATADIR}/ALib)
1526
1527 set(alib_install_config_done TRUE PARENT_SCOPE)
1528 set(alib_install_config_done TRUE)
1529endfunction()
1530
1531# --------------------------------------------------------------------------------------------------
1532# CMake debugging Uncomment a line to have CMake summarize information
1533# --------------------------------------------------------------------------------------------------
1534#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} INCLUDE_DIRECTORIES )
1535#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} SOURCES )
1536#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_DEFINITIONS )
1537#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_OPTIONS )
1538#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_FEATURES )
1539#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} AUTOUIC_OPTIONS )
1540#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} POSITION_INDEPENDENT_CODE )
1541#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} CONTAINER_SIZE_REQUIRED )
1542#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} LIB_VERSION )
1543
1544set(CMAKE_VERBOSE_MAKEFILE ON)
1545set(CMAKE_RULE_MESSAGES ON )
1546