1# #################################################################################################
2# ALib.cmake - CMake file for projects using ALib
4# Copyright 2015-2024 A-Worx GmbH, Germany
5# Published under 'Boost Software License' (a free software license, see LICENSE.txt)
8# CMake file for projects using ALib
9# #################################################################################################
11# --------------------------------------------------------------------------------------------------
13# --------------------------------------------------------------------------------------------------
14 cmake_minimum_required( VERSION 3.18.0 )
17 if (tmp_alib_included_marker)
18 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
21 set(tmp_alib_included_marker "1")
24 # Infer base directory from this script's location
25 if( NOT DEFINED ALIB_BASE_DIR )
26 set( temp "${CMAKE_CURRENT_LIST_DIR}/../.." )
27 get_filename_component(temp ${temp} ABSOLUTE)
28 set( ALIB_BASE_DIR ${temp} CACHE PATH
29 "The base path to ALib containing source code, project files, tools, docs, etc.")
34 if (NOT EXISTS "${ALIB_BASE_DIR}/src/alib" )
35 message( FATAL_ERROR "ALib.cmake: Can't read sources in ALIB_BASE_DIR= ${ALIB_BASE_DIR}" )
40 # build type defaults to "Debug"
41 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
42 set( CMAKE_BUILD_TYPE "Debug" )
45 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
48 # include tool functions
49 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
51# --------------------------------------------------------------------------------------------------
52# ALib Module Dependency Resolution
53# --------------------------------------------------------------------------------------------------
55 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
57# --------------------------------------------------------------------------------------------------
59# The variables are only set, if not already predefined prior to invoking this script.
60# --------------------------------------------------------------------------------------------------
62set( ALIB_VERSION "2402R1" CACHE STRING
63 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
65set( ALIB_VERSION_NO "2402" )
66set( ALIB_VERSION_REV "1" )
68if( NOT DEFINED ALIB_DEBUG )
69 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
70 set( defaultALIB_DEBUG "On" )
72 set( defaultALIB_DEBUG "Off" )
75 set( defaultALIB_DEBUG ALIB_DEBUG )
78set( ALIB_DEBUG ${defaultALIB_DEBUG} CACHE BOOL
79 "Enable/disable ALib debug code. Defaults to true with debug builds, otherwise to false." )
82if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
83 if( NOT DEFINED ALIB_DEBUG_GLIB )
84 set( ALIB_DEBUG_GLIB "Off" CACHE BOOL
85 "Defaults to false. If true, compiler symbols '_GLIBCXX_DEBUG', '_GLIBCXX_DEBUG_PEDANTIC' and '_GLIBCPP_CONCEPT_CHECKS' are set." )
89 if( NOT DEFINED ALIB_AVOID_ANALYZER_WARNINGS )
90 set( ALIB_AVOID_ANALYZER_WARNINGS "Off" CACHE BOOL
91 "Defaults to false. If true, minor code modifications are made to avoid unnecessary warnings with tools like 'valgrind'.")
95 if( NOT DEFINED ALIB_COVERAGE_COMPILE )
96 set( ALIB_COVERAGE_COMPILE "Off" CACHE BOOL
97 "Defaults to false. If true, option --coverage is added to GNU compiler command line.")
100 if ( $ENV{CLION_IDE} )
101 set( tmpDefault "On" )
103 set( tmpDefault "Off" )
106 set( ALIB_GDB_PP_SUPPRESS_CHILDREN ${tmpDefault} CACHE BOOL
107 "Defaults to false except if CMake is run from within JetBrains CLion. If true, a corresponding symbol gets set with debug builds which is detected by GDB pretty printer scripts provided with ALib.")
109 set( ALIB_GDB_PP_FIND_POINTER_TYPES ${tmpDefault} CACHE BOOL
110 "Defaults to false. If true, a corresponding symbol gets set with debug builds which is detected by GDB pretty printer scripts provided with ALib.")
113if( NOT DEFINED ALIB_CMAKE_COTIRE )
114 set( ALIB_CMAKE_COTIRE "Off" CACHE BOOL
115 "If true, CMake compilation tool 'cotire' (https://github.com/sakra/cotire/) is downloaded and may be used to speedup builds." )
119if( NOT DEFINED ALIB_PRECOMPILED_HEADER )
120 set( ALIB_PRECOMPILED_HEADER "Off" CACHE BOOL
121 "If on, header file ’alib/alib_precompile.hpp' will included some default headers, depending on the selected modules. Defaults to off." )
125if( NOT DEFINED ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH )
126 set( ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH "Off" CACHE BOOL
127 "If true, no thread library is searched and bound to the target. If false, a thread library is searched and bound even if module Threads is not included. This is to allow debug assertions with multi-threaded use of a single-threaded ALib distribution." )
131if( NOT DEFINED ALIB_CMAKE_VERBOSE )
132 set( ALIB_CMAKE_VERBOSE "Off" CACHE BOOL
133 "If true, CMake generation runs will provide a detailed report." )
137if( "SINGLETONS" IN_LIST ALIB_DISTRIBUTION )
139 set( platformDefaultFor_SINGLETON_MAPPED "On" )
141 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
143 if( NOT DEFINED ALIB_FEAT_SINGLETON_MAPPED )
144 set( ALIB_FEAT_SINGLETON_MAPPED ${platformDefaultFor_SINGLETON_MAPPED} CACHE BOOL
145 "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.")
149if( "MONOMEM" IN_LIST ALIB_DISTRIBUTION )
150 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
151 if( NOT DEFINED ALIB_DEBUG_MONOMEM )
152 set( ALIB_DEBUG_MONOMEM "Off" CACHE BOOL
153 "Adds consistency checks and collection of statistics with module ALib Memory. Defaults to false." )
158if( "BITBUFFER" IN_LIST ALIB_DISTRIBUTION )
159 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
160 if( NOT DEFINED ALIB_DEBUG_ARRAY_COMPRESSION )
161 set( ALIB_DEBUG_ARRAY_COMPRESSION "On" CACHE BOOL
162 "If true, in debug compilations, compressed arrays are read back to check if result is same. Defaults to true." )
168if( "BOXING" IN_LIST ALIB_DISTRIBUTION )
169 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
170 set( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS "Off" CACHE BOOL
171 "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.")
174 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
175 set( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS "Off" CACHE BOOL
176 "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.")
179 if( NOT DEFINED ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
180 set( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS "Off" CACHE BOOL
181 "If true, type float will be boxed as float. If false (the default) float will be boxed as double and can not be unboxed.")
184 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
185 if( NOT DEFINED ALIB_DEBUG_BOXING )
186 set( ALIB_DEBUG_BOXING "Off" CACHE BOOL
187 "Adds collection of statistics and debug methods to module ALib Boxing. Defaults to false." )
192if( "CHARACTERS" IN_LIST ALIB_DISTRIBUTION )
194 set( defaultALIB_CHARACTERS_WIDE "On" )
195 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
197 set( defaultALIB_CHARACTERS_WIDE "Off" )
198 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
201 if( NOT DEFINED ALIB_CHARACTERS_WIDE )
202 set( ALIB_CHARACTERS_WIDE ${defaultALIB_CHARACTERS_WIDE} CACHE BOOL
203 "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.")
206 if( NOT DEFINED ALIB_CHARACTERS_SIZEOF_WCHAR )
207 set( ALIB_CHARACTERS_SIZEOF_WCHAR ${defaultALIB_CHARACTERS_SIZEOF_WCHAR} CACHE STRING
208 "The width of wide characters, maybe 2 or 4. Default value depends on platform/compiler preference.")
212if( "STRINGS" IN_LIST ALIB_DISTRIBUTION )
213 if( NOT DEFINED ALIB_FEAT_BOOST_REGEX )
214 set( ALIB_FEAT_BOOST_REGEX "Off" CACHE BOOL
215 "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.")
218 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
219 if( NOT DEFINED ALIB_DEBUG_STRINGS )
220 set( ALIB_DEBUG_STRINGS "Off" CACHE BOOL
221 "Defaults to false. Adds consistency checks to ALib string classes. Useful when developing code to manipulate strings externally, i.e T_Append to specializations.")
227if( "CAMP" IN_LIST ALIB_DISTRIBUTION )
228 if( NOT DEFINED ALIB_RESOURCES_OMIT_DEFAULTS )
229 set( ALIB_RESOURCES_OMIT_DEFAULTS "Off" CACHE BOOL
230 "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.")
233 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
234 if( NOT DEFINED ALIB_DEBUG_RESOURCES )
235 set( ALIB_DEBUG_RESOURCES "Off" CACHE BOOL
236 "Adds collection of statistics and resource export with module ALib Resources. Defaults to false." )
242if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
244 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
245 set( defaultALOX_DBG_LOG "On" )
247 set( defaultALOX_DBG_LOG "Off" )
249 if( NOT DEFINED ALOX_DBG_LOG )
250 set( ALOX_DBG_LOG ${defaultALOX_DBG_LOG} CACHE BOOL
251 "Enable/disable debug log statements. Defaults to true with debug builds, otherwise to false." )
254 if( NOT DEFINED ALOX_DBG_LOG_CI )
255 set( ALOX_DBG_LOG_CI "On" CACHE BOOL
256 "Defaults to true. If set, caller information is used with debug log statements." )
259 if( NOT DEFINED ALOX_REL_LOG )
260 set( ALOX_REL_LOG "On" CACHE BOOL
261 "Enable/disable release log statements. Defaults to true." )
264 if( NOT DEFINED ALOX_REL_LOG_CI )
265 set( ALOX_REL_LOG_CI "Off" CACHE BOOL
266 "Defaults to false. If set, caller information is used even with release log statements (and even in release builds!)" )
270# --------------------------------------------------------------------------------------------------
272# --------------------------------------------------------------------------------------------------
277 LIST( APPEND moduleList "EXPRESSIONS;CLI;ALOX" )
278 LIST( APPEND moduleList "CONFIGURATION;CAMP" )
279 LIST( APPEND moduleList "THREADS;FILES" )
280 LIST( APPEND moduleList "ENUMS;BOXING;STRINGS" )
281 LIST( APPEND moduleList "SINGLETONS;MONOMEM;BITBUFFER;CHARACTERS;TIME" )
282 FOREACH( module IN LISTS moduleList )
283 IF( module IN_LIST ALIB_DISTRIBUTION )
284 list( APPEND ALIB_SYMBOLS "ALIB_${module}" )
291 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
293 if ( ${ALIB_DEBUG_GLIB} )
294 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
295 "_GLIBCXX_DEBUG_PEDANTIC"
296 "_GLIBCPP_CONCEPT_CHECKS" )
298 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
299 "_GLIBCXX_DEBUG_PEDANTIC"
300 "_GLIBCPP_CONCEPT_CHECKS" )
303 if ( ${ALIB_GDB_PP_SUPPRESS_CHILDREN} )
304 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
306 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
308 if ( ${ALIB_GDB_PP_FIND_POINTER_TYPES} )
309 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_FIND_POINTER_TYPES" )
311 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_FIND_POINTER_TYPES" )
316if ( ${ALIB_AVOID_ANALYZER_WARNINGS} )
317 list( APPEND ALIB_SYMBOLS "ALIB_AVOID_ANALYZER_WARNINGS" )
319 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_AVOID_ANALYZER_WARNINGS" )
323if ( ${ALIB_PRECOMPILED_HEADER} )
324 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
326 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
330if( "SINGLETONS" IN_LIST ALIB_DISTRIBUTION )
331 if (NOT platformDefaultFor_SINGLETON_MAPPED STREQUAL ALIB_FEAT_SINGLETON_MAPPED)
332 if ( ALIB_FEAT_SINGLETON_MAPPED )
333 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED" )
335 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
338 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
342if( "MONOMEM" IN_LIST ALIB_DISTRIBUTION )
343 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
344 if ( ALIB_DEBUG_MONOMEM )
345 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_MONOMEM" )
347 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MONOMEM" )
352if( "BITBUFFER" IN_LIST ALIB_DISTRIBUTION )
353 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
354 if ( ALIB_DEBUG_ARRAY_COMPRESSION )
355 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_ARRAY_COMPRESSION" )
357 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ARRAY_COMPRESSION" )
362if( "BOXING" IN_LIST ALIB_DISTRIBUTION )
363 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
364 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
366 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
368 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
369 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
371 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
373 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
374 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
376 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
378 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
379 if( ALIB_DEBUG_BOXING )
380 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
382 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
387if( "CHARACTERS" IN_LIST ALIB_DISTRIBUTION )
388 if (NOT (defaultALIB_CHARACTERS_WIDE STREQUAL ALIB_CHARACTERS_WIDE ))
389 if ( ALIB_CHARACTERS_WIDE )
390 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE" )
392 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
395 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
398 if (NOT defaultALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL ALIB_CHARACTERS_SIZEOF_WCHAR)
399 if ( NOT (ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "2" OR ALIB_CHARACTERS_SIZEOF_WCHAR STREQUAL "4") )
400 message( FATAL_ERROR "Value of ALIB_CHARACTERS_SIZEOF_WCHAR must be 2 or 4" )
403 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
405 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
410if( "STRINGS" IN_LIST ALIB_DISTRIBUTION )
411 if ( ALIB_FEAT_BOOST_REGEX )
412 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
414 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
417 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
418 if ( ALIB_DEBUG_STRINGS )
419 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
421 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
426if( "CAMP" IN_LIST ALIB_DISTRIBUTION )
428 if( ALIB_RESOURCES_OMIT_DEFAULTS )
429 list( APPEND ALIB_SYMBOLS "ALIB_RESOURCES_OMIT_DEFAULTS" )
431 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_RESOURCES_OMIT_DEFAULTS" )
434 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
435 if( ALIB_DEBUG_RESOURCES )
436 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
438 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
443if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
445 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
446 if( NOT ALOX_DBG_LOG )
447 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
449 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
452 if ( NOT ${ALOX_DBG_LOG_CI} )
453 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
455 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
458 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
459 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
462 if ( NOT ALOX_REL_LOG )
463 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
465 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
467 if ( ALOX_REL_LOG_CI )
468 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
470 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
476# --------------------------------------------------------------------------------------------------
477# ALib Source File Definition
478# --------------------------------------------------------------------------------------------------
479include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
482# --------------------------------------------------------------------------------------------------
484# --------------------------------------------------------------------------------------------------
485if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
486 find_package(Threads)
488 if(CMAKE_THREAD_LIBS_INIT)
489 list( APPEND ALIB_SYMBOLS "ALIB_EXT_LIB_THREADS_AVAILABLE" )
490 if(CMAKE_USE_PTHREADS_INIT)
491 list( APPEND ALIB_COMPILER_OPTIONS "-pthread" )
495 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
498if ( ${ALIB_FEAT_BOOST_REGEX} )
499 set(Boost_USE_STATIC_LIBS "On" CACHE BOOL "Link boost statically" )
500 if( "THREADS" IN_LIST ALIB_DISTRIBUTION )
501 set(Boost_USE_MULTITHREADED "On" CACHE BOOL "Use multi-threaded version of boost")
503 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
506 find_package( Boost REQUIRED COMPONENTS regex )
509 list( APPEND ALIB_EXTERNAL_LIBS Boost::regex )
510 if(${Boost_USE_STATIC_LIBS})
511 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost static libraries")
513 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
516 MESSAGE("Attention: Boost::regex requested, but library not found!")
521 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
524# lib math, needed with GCC (suddenly, we don't really know why, added 221205)
527 list( APPEND ALIB_EXTERNAL_LIBS "m")
531# --------------------------------------------------------------------------------------------------
532# A-Worx compiler features and flags
533# --------------------------------------------------------------------------------------------------
535# Set minimum required standard C++ 17
536list( APPEND ALIB_COMPILER_FEATURES "cxx_std_17" )
539# if "ALIB_SUPPRESS_COMPILER_WARNINGS" is set prior to invoking this script, this entry is removed
540# and nothing is added.
541if ("ALIB_SUPPRESS_COMPILER_WARNINGS" IN_LIST ALIB_COMPILER_WARNINGS)
542 LIST( REMOVE_ITEM ALIB_COMPILER_WARNINGS "ALIB_SUPPRESS_COMPILER_WARNINGS" )
544 if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
545 # add -H to generate output "!/x" for use of precompiled header
546 list( APPEND ALIB_COMPILER_WARNINGS "-Wall" )
547 list( APPEND ALIB_COMPILER_WARNINGS "-Wextra" )
548 list( APPEND ALIB_COMPILER_WARNINGS "-Werror" )
549 #list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
550 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-psabi" )
551 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
553 # this was "suddenly" needed with GCC 13.2.1 with release compilation
554 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
556 # add coverage flags to GCC
557 if( ${ALIB_COVERAGE_COMPILE} )
558 list( APPEND ALIB_COMPILER_OPTIONS "--coverage" )
559 list( APPEND ALIB_LINKER_OPTIONS "--coverage" )
562 # force unicode (needed for mingw)
564 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
565 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
566 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
570 # Clang: We are using -Weverything, although this is not recommended. We think it should be
571 # recommended. ALib for example does not use old-style casts and explicitly cast each
572 # and every type change! The benefit for ALib users is that ALib code can be used in very
573 # strict build environments without using special warning flags.
574 # Of-course, some very obvious things like C++98 compatibility warnings have to be
575 # removed explicitly:
576 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
577 list( APPEND ALIB_COMPILER_WARNINGS "-pedantic" )
578 list( APPEND ALIB_COMPILER_WARNINGS "-Weffc++" )
579 list( APPEND ALIB_COMPILER_WARNINGS "-Weverything" )
580 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat" )
581 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-c++98-compat-pedantic" )
582 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-global-constructors" )
583 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-exit-time-destructors" )
584 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-padded" )
585 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-weak-vtables" )
586 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-documentation-unknown-command" )
587 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-misleading-indentation" )
589 if ( ${ALIB_CMAKE_COTIRE} )
590 # needs to be off of due to "unity builds" of cotire
591 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-header-hygiene" )
594 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
595 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
599 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" )
600 list( APPEND ALIB_COMPILER_WARNINGS "/W4" )
601 list( APPEND ALIB_COMPILER_WARNINGS "/WX" )
602 list( APPEND ALIB_COMPILER_WARNINGS "/EHsc" )
604 #! NEVER TESTED YET !
605 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
606 list( APPEND ALIB_COMPILER_WARNINGS "" )
611# --------------------------------------------------------------------------------------------------
612# A-Worx linker features and flags
613# --------------------------------------------------------------------------------------------------
615 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
617 list( APPEND ALIB_LINKER_OPTIONS "" )
621# -------------------------------------------------------------------------------------------------
622# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
623# -------------------------------------------------------------------------------------------------
624if ( NOT ALIB_LIBRARY_FILENAME )
626 set( ALIB_LIBRARY_FILENAME "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
629 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBG )
634 # create copy of module list and remove all dependent modules
635 SET( modules ${ALIB_DISTRIBUTION} )
637 list( FIND modules "BOXING" idx )
639 LIST( REMOVE_ITEM modules "SINGLETONS" )
642 list( FIND modules "STRINGS" idx )
644 LIST( REMOVE_ITEM modules "CHARACTERS" )
647 list( FIND modules "BITBUFFER" idx )
649 LIST( REMOVE_ITEM modules "MONOMEM" )
650 LIST( REMOVE_ITEM modules "ENUMS" )
653 list( FIND modules "THREADS" idx )
655 LIST( REMOVE_ITEM modules "STRINGS" )
658 list( FIND modules "CAMP" idx )
660 LIST( REMOVE_ITEM modules "STRINGS" )
661 LIST( REMOVE_ITEM modules "SINGLETONS" )
662 LIST( REMOVE_ITEM modules "MONOMEM" )
663 LIST( REMOVE_ITEM modules "BOXING" )
664 LIST( REMOVE_ITEM modules "ENUMS" )
665 LIST( REMOVE_ITEM modules "TIME" )
668 list( FIND modules "CONFIGURATION" idx )
670 LIST( REMOVE_ITEM modules "CAMP" )
673 list( FIND modules "ALOX" idx )
675 LIST( REMOVE_ITEM modules "CONFIGURATION")
678 list( FIND modules "EXPRESSIONS" idx )
680 LIST( REMOVE_ITEM modules "CAMP" )
683 list( FIND modules "FILES" idx )
685 LIST( REMOVE_ITEM modules "CAMP" )
688 list( FIND modules "CLI" idx )
690 LIST( REMOVE_ITEM modules "CAMP" )
693 FOREACH(modName IN LISTS modules)
695 # STRINGS: debug mode?
696 IF( modName STREQUAL "STRINGS" )
697 if ( ALIB_DEBUG_STRINGS )
698 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
700 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
703 # ALOX: add non-default feature s
704 ELSEIF( modName STREQUAL "ALOX" )
705 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_ALOX )
706 if ( (CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT ALOX_DBG_LOG) )
707 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NDL )
710 if ( NOT ALOX_REL_LOG )
711 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
714 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
722# -------------------------------------------------------------------------------------------------
723# Display result summary
724# -------------------------------------------------------------------------------------------------
725message( "ALib CMake Configuration:" )
727 message( " Module Selection : ${ALIB_DISTRIBUTION}" )
729 message( " Module Selection : All (${ALIB_DISTRIBUTION})" )
732 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
733 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
735IF( NOT ALIB_CMAKE_VERBOSE )
736 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
739 message( " Source folder: ${ALIB_SOURCE_DIR}" )
741 LIST( APPEND result ${ALIB_INCLUDE_FILES} )
742 LIST( APPEND result ${ALIB_SOURCE_FILES} )
744 LIST( LENGTH result length)
745 message( "\n List of header and source files (${length} items):" )
746 FOREACH( entry IN LISTS result )
747 string(REPLACE "${ALIB_SOURCE_DIR}/" "" entry ${entry} )
748 message( " ${entry}" )
752 LIST( APPEND result ${ALIB_SYMBOLS} )
754 LIST( LENGTH result length)
755 message( "\n Compiler definitions (${length} items):" )
756 FOREACH( entry IN LISTS result )
757 message( " ${entry}" )
762 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
764 LIST( LENGTH result length)
765 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
766 FOREACH( entry IN LISTS result )
767 message( " ${entry}" )
771 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
773 LIST( LENGTH result length)
774 message( "\n Compiler warnings (${length} items):" )
775 FOREACH( entry IN LISTS result )
776 message( " ${entry}" )
780 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
782 LIST( LENGTH result length)
783 message( "\n Compiler flags (${length} items):" )
784 FOREACH( entry IN LISTS result )
785 message( " ${entry}" )
789 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
791 LIST( LENGTH result length)
792 message( "\n Compiler features (${length} items):" )
793 FOREACH( entry IN LISTS result )
794 message( " ${entry}" )
798 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
800 LIST( LENGTH result length)
801 message( "\n External libraries (${length} items):" )
802 FOREACH( entry IN LISTS result )
803 message( " ${entry}" )
807 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
809 LIST( LENGTH result length)
810 message( "\n Linker flags (${length} items):" )
811 FOREACH( entry IN LISTS result )
812 message( " ${entry}" )
819# -------------------------------------------------------------------------------------------------
820# ALibSetCompilerAndLinker(target)
822# Simple CMake function that sets
824# - ALIB_COMPILER_FEATURES
825# - ALIB_COMPILER_OPTIONS
826# - ALIB_COMPILER_WARNINGS
827# - ALIB_LINKER_OPTIONS
829# In addition, postion independent compile (-fPic) is enabled (for static libraries its default
831# -------------------------------------------------------------------------------------------------
832function( ALibSetCompilerAndLinker target )
835 target_compile_features ( ${target} PRIVATE ${ALIB_COMPILER_FEATURES} )
836 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_OPTIONS} )
837 target_compile_options ( ${target} PRIVATE ${ALIB_COMPILER_WARNINGS} )
838 set_property ( TARGET ${target} PROPERTY POSITION_INDEPENDENT_CODE ON )
839 target_include_directories( ${target} PUBLIC ${ALIB_SOURCE_DIR} )
842 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
845 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
846 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
848 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
849 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
854# -------------------------------------------------------------------------------------------------
855# ALibSetCotire(target)
857# If global variable \b ALIB_CMAKE_COTIRE is set and \c true, then the given project is setup to use
859# -------------------------------------------------------------------------------------------------
860function( ALibSetCotire target )
862 if ( ${ALIB_CMAKE_COTIRE} )
864 # use multiple processor cores
865 set_target_properties( ${target} PROPERTIES COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "-j" )
867 # header for precomp is "alib/alib_precompile.hpp"
868 set_target_properties( ${target} PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "${ALIB_SOURCE_DIR}/alib/alib_precompile.hpp" )
870 # add cotire to projects
877# -------------------------------------------------------------------------------------------------
879# -------------------------------------------------------------------------------------------------
881function( ALibAddStaticLibrary )
883 add_library ( ALib_StaticLib STATIC ${ALIB_INCLUDE_FILES} ${ALIB_SOURCE_FILES} )
884 ALibSetCompilerAndLinker ( ALib_StaticLib )
885 set_target_properties ( ALib_StaticLib PROPERTIES ARCHIVE_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
886 ALibSetCotire ( ALib_StaticLib )
889function( ALibAddSharedLibrary )
890 add_library ( ALib_SharedLib SHARED ${ALIB_INCLUDE_FILES} ${ALIB_SOURCE_FILES} )
891 ALibSetCompilerAndLinker ( ALib_SharedLib )
892 set_target_properties ( ALib_SharedLib PROPERTIES LIBRARY_OUTPUT_NAME ${ALIB_LIBRARY_FILENAME} )
895 target_compile_definitions ( ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
898 ALibSetCotire ( ALib_SharedLib )
901# -------------------------------------------------------------------------------------------------
902# Precompiled headers and unity build with 'cotire' CMake script.
903# More Info at: https://github.com/sakra/cotire/
906# To enable/disable change CMake cache variable ALIB_CMAKE_COTIRE.
907# To change the variable permanently (on clean cmake builds), set the variable prior
908# to invoking this script.
909# -------------------------------------------------------------------------------------------------
911# download cotire (once)
912if ( ${ALIB_CMAKE_COTIRE} )
913 CheckDownloadCotire()
914 # the include itself has to remain on this "source/scope level"
915 # (aka: must not be done in the function/script above)
916 include(${CMAKE_CURRENT_LIST_DIR}/cotire.cmake)
921# --------------------------------------------------------------------------------------------------
922# CMake debugging Uncomment a line to have CMake summarize information
923# --------------------------------------------------------------------------------------------------
924#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} INCLUDE_DIRECTORIES )
925#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} SOURCES )
926#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_DEFINITIONS )
927#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_OPTIONS )
928#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} COMPILE_FEATURES )
929#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} AUTOUIC_OPTIONS )
930#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} POSITION_INDEPENDENT_CODE )
931#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} CONTAINER_SIZE_REQUIRED )
932#set(CMAKE_DEBUG_TARGET_PROPERTIES ${CMAKE_DEBUG_TARGET_PROPERTIES} LIB_VERSION )
934#set(CMAKE_VERBOSE_MAKEFILE ON)