ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
ALib.cmake
1# #################################################################################################
2# ALib.cmake - CMake file for projects using ALib
3#
4# Copyright 2015-2024 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.18.0 )
15
16 # check
17 if (tmp_alib_included_marker)
18 message( FATAL_ERROR "ALib.cmake: Already included (included twice!)" )
19 return()
20 endif()
21 set(tmp_alib_included_marker "1")
22
23
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.")
30 endif()
31
32
33 # check
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}" )
36 return()
37 endif()
38
39
40 # build type defaults to "Debug"
41 if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
42 set( CMAKE_BUILD_TYPE "Debug" )
43 endif()
44
45 MESSAGE( STATUS "Build type: ${CMAKE_BUILD_TYPE}" )
46
47
48 # include tool functions
49 include( ${CMAKE_CURRENT_LIST_DIR}/ALibTools.cmake )
50
51# --------------------------------------------------------------------------------------------------
52# ALib Module Dependency Resolution
53# --------------------------------------------------------------------------------------------------
54
55 include( ${CMAKE_CURRENT_LIST_DIR}/ALibModules.cmake )
56
57# --------------------------------------------------------------------------------------------------
58# ALib Cache Variables
59# The variables are only set, if not already predefined prior to invoking this script.
60# --------------------------------------------------------------------------------------------------
61
62set( ALIB_VERSION "2402R1" CACHE STRING
63 "The ALib version. Not modifiable (will be overwritten on generation!)" FORCE )
64
65set( ALIB_VERSION_NO "2402" )
66set( ALIB_VERSION_REV "1" )
67
68if( NOT DEFINED ALIB_DEBUG )
69 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
70 set( defaultALIB_DEBUG "On" )
71 else()
72 set( defaultALIB_DEBUG "Off" )
73 endif()
74else()
75 set( defaultALIB_DEBUG ALIB_DEBUG )
76endif()
77
78set( ALIB_DEBUG ${defaultALIB_DEBUG} CACHE BOOL
79 "Enable/disable ALib debug code. Defaults to true with debug builds, otherwise to false." )
80
81
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." )
86 endif()
87
88
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'.")
92 endif()
93
94
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.")
98 endif()
99
100 if ( $ENV{CLION_IDE} )
101 set( tmpDefault "On" )
102 else()
103 set( tmpDefault "Off" )
104 endif()
105
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.")
108
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.")
111endif()
112
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." )
116endif()
117
118
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." )
122endif()
123
124
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." )
128endif()
129
130
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." )
134endif()
135
136
137if( "SINGLETONS" IN_LIST ALIB_DISTRIBUTION )
138 if ( ${WIN32} )
139 set( platformDefaultFor_SINGLETON_MAPPED "On" )
140 else()
141 set( platformDefaultFor_SINGLETON_MAPPED "Off" )
142 endif()
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.")
146 endif()
147endif()
148
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." )
154 endif()
155 endif()
156endif()
157
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." )
163 endif()
164 endif()
165endif()
166
167
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.")
172 endif()
173
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.")
177 endif()
178
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.")
182 endif()
183
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." )
188 endif()
189 endif()
190endif()
191
192if( "CHARACTERS" IN_LIST ALIB_DISTRIBUTION )
193 if ( ${WIN32} )
194 set( defaultALIB_CHARACTERS_WIDE "On" )
195 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "2" )
196 else()
197 set( defaultALIB_CHARACTERS_WIDE "Off" )
198 set( defaultALIB_CHARACTERS_SIZEOF_WCHAR "4" )
199 endif()
200
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.")
204 endif()
205
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.")
209 endif()
210endif()
211
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.")
216 endif()
217
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.")
222 endif()
223 endif()
224endif()
225
226
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.")
231 endif()
232
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." )
237 endif()
238 endif()
239
240endif()
241
242if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
243
244 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
245 set( defaultALOX_DBG_LOG "On" )
246 else()
247 set( defaultALOX_DBG_LOG "Off" )
248 endif()
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." )
252 endif()
253
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." )
257 endif()
258
259 if( NOT DEFINED ALOX_REL_LOG )
260 set( ALOX_REL_LOG "On" CACHE BOOL
261 "Enable/disable release log statements. Defaults to true." )
262 endif()
263
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!)" )
267 endif()
268endif()
269
270# --------------------------------------------------------------------------------------------------
271# Compiler symbols
272# --------------------------------------------------------------------------------------------------
273
274# module selection
275if( NOT allModules )
276 SET( moduleList "" )
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}" )
285 ENDIF()
286 ENDFOREACH()
287endif()
288
289# debug
290if ( ${ALIB_DEBUG} )
291 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG" )
292
293 if ( ${ALIB_DEBUG_GLIB} )
294 list( APPEND ALIB_SYMBOLS "_GLIBCXX_DEBUG"
295 "_GLIBCXX_DEBUG_PEDANTIC"
296 "_GLIBCPP_CONCEPT_CHECKS" )
297 else()
298 list( APPEND ALIB_SYMBOLS_UNUSED "_GLIBCXX_DEBUG"
299 "_GLIBCXX_DEBUG_PEDANTIC"
300 "_GLIBCPP_CONCEPT_CHECKS" )
301 endif()
302
303 if ( ${ALIB_GDB_PP_SUPPRESS_CHILDREN} )
304 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
305 else()
306 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_SUPPRESS_CHILDREN" )
307 endif()
308 if ( ${ALIB_GDB_PP_FIND_POINTER_TYPES} )
309 list( APPEND ALIB_SYMBOLS "ALIB_GDB_PP_FIND_POINTER_TYPES" )
310 else()
311 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_GDB_PP_FIND_POINTER_TYPES" )
312 endif()
313
314endif()
315
316if ( ${ALIB_AVOID_ANALYZER_WARNINGS} )
317 list( APPEND ALIB_SYMBOLS "ALIB_AVOID_ANALYZER_WARNINGS" )
318else()
319 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_AVOID_ANALYZER_WARNINGS" )
320endif()
321
322# precompiled header
323if ( ${ALIB_PRECOMPILED_HEADER} )
324 list( APPEND ALIB_SYMBOLS "ALIB_PRECOMPILED_HEADER" )
325else()
326 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_PRECOMPILED_HEADER" )
327endif()
328
329# ALib features
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" )
334 else()
335 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_SINGLETON_MAPPED=0" )
336 endif()
337 else()
338 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_SINGLETON_MAPPED=0" )
339 endif()
340endif()
341
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" )
346 else()
347 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_MONOMEM" )
348 endif()
349 endif()
350endif()
351
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" )
356 else()
357 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_ARRAY_COMPRESSION" )
358 endif()
359 endif()
360endif()
361
362if( "BOXING" IN_LIST ALIB_DISTRIBUTION )
363 if ( ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS )
364 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
365 else()
366 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS" )
367 endif()
368 if ( ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS )
369 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
370 else()
371 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS" )
372 endif()
373 if ( ALIB_FEAT_BOXING_BIJECTIVE_FLOATS )
374 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
375 else()
376 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOXING_BIJECTIVE_FLOATS" )
377 endif()
378 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
379 if( ALIB_DEBUG_BOXING )
380 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_BOXING" )
381 else()
382 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_BOXING" )
383 endif()
384 endif()
385endif()
386
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" )
391 else()
392 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_WIDE=0" )
393 endif()
394 else()
395 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_WIDE" )
396 endif()
397
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" )
401 return()
402 endif()
403 list( APPEND ALIB_SYMBOLS "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
404 else()
405 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_CHARACTERS_SIZEOF_WCHAR=${ALIB_CHARACTERS_SIZEOF_WCHAR}" )
406 endif()
407
408endif()
409
410if( "STRINGS" IN_LIST ALIB_DISTRIBUTION )
411 if ( ALIB_FEAT_BOOST_REGEX )
412 list( APPEND ALIB_SYMBOLS "ALIB_FEAT_BOOST_REGEX" )
413 else()
414 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_FEAT_BOOST_REGEX" )
415 endif()
416
417 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
418 if ( ALIB_DEBUG_STRINGS )
419 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_STRINGS" )
420 else()
421 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_STRINGS" )
422 endif()
423 endif()
424endif()
425
426if( "CAMP" IN_LIST ALIB_DISTRIBUTION )
427
428 if( ALIB_RESOURCES_OMIT_DEFAULTS )
429 list( APPEND ALIB_SYMBOLS "ALIB_RESOURCES_OMIT_DEFAULTS" )
430 else()
431 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_RESOURCES_OMIT_DEFAULTS" )
432 endif()
433
434 if ( CMAKE_BUILD_TYPE STREQUAL "Debug" )
435 if( ALIB_DEBUG_RESOURCES )
436 list( APPEND ALIB_SYMBOLS "ALIB_DEBUG_RESOURCES" )
437 else()
438 list( APPEND ALIB_SYMBOLS_UNUSED "ALIB_DEBUG_RESOURCES" )
439 endif()
440 endif()
441endif()
442
443if( "ALOX" IN_LIST ALIB_DISTRIBUTION )
444
445 if (NOT defaultALOX_DBG_LOG STREQUAL ALOX_DBG_LOG)
446 if( NOT ALOX_DBG_LOG )
447 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG" )
448 else()
449 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
450 endif()
451
452 if ( NOT ${ALOX_DBG_LOG_CI} )
453 list( APPEND ALIB_SYMBOLS "ALOX_DBG_LOG_CI=0" )
454 else()
455 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI=0" )
456 endif()
457 else()
458 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG" )
459 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_DBG_LOG_CI" )
460 endif()
461
462 if ( NOT ALOX_REL_LOG )
463 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG=0" )
464 else()
465 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG=0" )
466 endif()
467 if ( ALOX_REL_LOG_CI )
468 list( APPEND ALIB_SYMBOLS "ALOX_REL_LOG_CI" )
469 else()
470 list( APPEND ALIB_SYMBOLS_UNUSED "ALOX_REL_LOG_CI" )
471 endif()
472endif()
473
474
475
476# --------------------------------------------------------------------------------------------------
477# ALib Source File Definition
478# --------------------------------------------------------------------------------------------------
479include( ${CMAKE_CURRENT_LIST_DIR}/ALibSources.cmake )
480
481
482# --------------------------------------------------------------------------------------------------
483# External libraries
484# --------------------------------------------------------------------------------------------------
485if ( NOT ${ALIB_CMAKE_SKIP_THREAD_LIB_SEARCH} )
486 find_package(Threads)
487
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" )
492 endif()
493 endif()
494
495 list( APPEND ALIB_EXTERNAL_LIBS ${CMAKE_THREAD_LIBS_INIT} )
496endif()
497
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")
502 else()
503 set(Boost_USE_MULTITHREADED "Off" CACHE BOOL "Use single-threaded version of boost")
504 endif()
505
506 find_package( Boost REQUIRED COMPONENTS regex )
507
508 if(Boost_FOUND)
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")
512 else()
513 message(STATUS "Found Boost version ${Boost_LIB_VERSION}, linking against boost shared libraries")
514 endif()
515 else()
516 MESSAGE("Attention: Boost::regex requested, but library not found!")
517 endif()
518endif()
519
520if(APPLE)
521 list( APPEND ALIB_EXTERNAL_LIBS "-framework Foundation")
522endif()
523
524# lib math, needed with GCC (suddenly, we don't really know why, added 221205)
525if(NOT MSVC)
526 if(NOT APPLE)
527 list( APPEND ALIB_EXTERNAL_LIBS "m")
528 endif(NOT APPLE)
529endif(NOT MSVC)
530
531# --------------------------------------------------------------------------------------------------
532# A-Worx compiler features and flags
533# --------------------------------------------------------------------------------------------------
534
535# Set minimum required standard C++ 17
536list( APPEND ALIB_COMPILER_FEATURES "cxx_std_17" )
537
538
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" )
543else()
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" )
552
553 # this was "suddenly" needed with GCC 13.2.1 with release compilation
554 list( APPEND ALIB_COMPILER_WARNINGS "-Wno-stringop-overread" )
555
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" )
560 endif()
561
562 # force unicode (needed for mingw)
563 if(MINGW)
564 list( APPEND ALIB_COMPILER_OPTIONS "-municode" )
565 list( APPEND ALIB_COMPILER_OPTIONS "-DUNICODE" )
566 list( APPEND ALIB_COMPILER_OPTIONS "-D_UNICODE" )
567 endif()
568
569
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" )
588
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" )
592 endif()
593
594 if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
595 list( APPEND ALIB_COMPILER_OPTIONS "-fno-limit-debug-info" )
596 endif()
597
598 # MSVC
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" )
603
604 #! NEVER TESTED YET !
605 elseif ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
606 list( APPEND ALIB_COMPILER_WARNINGS "" )
607
608 endif()
609endif()
610
611# --------------------------------------------------------------------------------------------------
612# A-Worx linker features and flags
613# --------------------------------------------------------------------------------------------------
614if(APPLE)
615 list( APPEND ALIB_LINKER_OPTIONS "-lObjc" )
616else()
617 list( APPEND ALIB_LINKER_OPTIONS "" )
618endif()
619
620
621# -------------------------------------------------------------------------------------------------
622# Set filename of ALib library (if not given in ALIB_LIBRARY_FILENAME)
623# -------------------------------------------------------------------------------------------------
624if ( NOT ALIB_LIBRARY_FILENAME )
625
626 set( ALIB_LIBRARY_FILENAME "alib_${ALIB_VERSION_NO}R${ALIB_VERSION_REV}" )
627
628 if ( ${ALIB_DEBUG} )
629 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBG )
630 endif()
631
632 if( NOT allModules )
633
634 # create copy of module list and remove all dependent modules
635 SET( modules ${ALIB_DISTRIBUTION} )
636
637 list( FIND modules "BOXING" idx )
638 if( NOT idx LESS 0 )
639 LIST( REMOVE_ITEM modules "SINGLETONS" )
640 endif()
641
642 list( FIND modules "STRINGS" idx )
643 if( NOT idx LESS 0 )
644 LIST( REMOVE_ITEM modules "CHARACTERS" )
645 endif()
646
647 list( FIND modules "BITBUFFER" idx )
648 if( NOT idx LESS 0 )
649 LIST( REMOVE_ITEM modules "MONOMEM" )
650 LIST( REMOVE_ITEM modules "ENUMS" )
651 endif()
652
653 list( FIND modules "THREADS" idx )
654 if( NOT idx LESS 0 )
655 LIST( REMOVE_ITEM modules "STRINGS" )
656 endif()
657
658 list( FIND modules "CAMP" idx )
659 if( NOT idx LESS 0 )
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" )
666 endif()
667
668 list( FIND modules "CONFIGURATION" idx )
669 if( NOT idx LESS 0 )
670 LIST( REMOVE_ITEM modules "CAMP" )
671 endif()
672
673 list( FIND modules "ALOX" idx )
674 if( NOT idx LESS 0 )
675 LIST( REMOVE_ITEM modules "CONFIGURATION")
676 endif()
677
678 list( FIND modules "EXPRESSIONS" idx )
679 if( NOT idx LESS 0 )
680 LIST( REMOVE_ITEM modules "CAMP" )
681 endif()
682
683 list( FIND modules "FILES" idx )
684 if( NOT idx LESS 0 )
685 LIST( REMOVE_ITEM modules "CAMP" )
686 endif()
687
688 list( FIND modules "CLI" idx )
689 if( NOT idx LESS 0 )
690 LIST( REMOVE_ITEM modules "CAMP" )
691 endif()
692
693 FOREACH(modName IN LISTS modules)
694
695 # STRINGS: debug mode?
696 IF( modName STREQUAL "STRINGS" )
697 if ( ALIB_DEBUG_STRINGS )
698 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_DBGSTRINGS )
699 else()
700 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_STRINGS )
701 endif()
702
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 )
708 endif()
709
710 if ( NOT ALOX_REL_LOG )
711 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}NRL )
712 endif()
713 ELSE()
714 set ( ALIB_LIBRARY_FILENAME ${ALIB_LIBRARY_FILENAME}_${modName} )
715 ENDIF()
716
717 ENDFOREACH()
718 endif()
719
720endif()
721
722# -------------------------------------------------------------------------------------------------
723# Display result summary
724# -------------------------------------------------------------------------------------------------
725message( "ALib CMake Configuration:" )
726IF( NOT allModules )
727 message( " Module Selection : ${ALIB_DISTRIBUTION}" )
728ELSE()
729 message( " Module Selection : All (${ALIB_DISTRIBUTION})" )
730ENDIF()
731
732 message( " Library filename : ${ALIB_LIBRARY_FILENAME}" )
733 message( " Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
734
735IF( NOT ALIB_CMAKE_VERBOSE )
736 message( " (For further details enable CMake variable 'ALIB_CMAKE_VERBOSE')" )
737ELSE()
738
739 message( " Source folder: ${ALIB_SOURCE_DIR}" )
740 SET( result "" )
741 LIST( APPEND result ${ALIB_INCLUDE_FILES} )
742 LIST( APPEND result ${ALIB_SOURCE_FILES} )
743 LIST( SORT result )
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}" )
749 ENDFOREACH()
750
751 SET( result "" )
752 LIST( APPEND result ${ALIB_SYMBOLS} )
753 LIST( SORT result )
754 LIST( LENGTH result length)
755 message( "\n Compiler definitions (${length} items):" )
756 FOREACH( entry IN LISTS result )
757 message( " ${entry}" )
758 ENDFOREACH()
759 SET( result "" )
760
761 SET( result "" )
762 LIST( APPEND result ${ALIB_SYMBOLS_UNUSED} )
763 LIST( SORT result )
764 LIST( LENGTH result length)
765 message( "\n Compiler definitions NOT given/omitted (${length} items):" )
766 FOREACH( entry IN LISTS result )
767 message( " ${entry}" )
768 ENDFOREACH()
769 SET( result "" )
770
771 LIST( APPEND result ${ALIB_COMPILER_WARNINGS} )
772 LIST( SORT result )
773 LIST( LENGTH result length)
774 message( "\n Compiler warnings (${length} items):" )
775 FOREACH( entry IN LISTS result )
776 message( " ${entry}" )
777 ENDFOREACH()
778 SET( result "" )
779
780 LIST( APPEND result ${ALIB_COMPILER_OPTIONS} )
781 LIST( SORT result )
782 LIST( LENGTH result length)
783 message( "\n Compiler flags (${length} items):" )
784 FOREACH( entry IN LISTS result )
785 message( " ${entry}" )
786 ENDFOREACH()
787 SET( result "" )
788
789 LIST( APPEND result ${ALIB_COMPILER_FEATURES} )
790 LIST( SORT result )
791 LIST( LENGTH result length)
792 message( "\n Compiler features (${length} items):" )
793 FOREACH( entry IN LISTS result )
794 message( " ${entry}" )
795 ENDFOREACH()
796 SET( result "" )
797
798 LIST( APPEND result ${ALIB_EXTERNAL_LIBS} )
799 LIST( SORT result )
800 LIST( LENGTH result length)
801 message( "\n External libraries (${length} items):" )
802 FOREACH( entry IN LISTS result )
803 message( " ${entry}" )
804 ENDFOREACH()
805 SET( result "" )
806
807 LIST( APPEND result ${ALIB_LINKER_OPTIONS} )
808 LIST( SORT result )
809 LIST( LENGTH result length)
810 message( "\n Linker flags (${length} items):" )
811 FOREACH( entry IN LISTS result )
812 message( " ${entry}" )
813 ENDFOREACH()
814 SET( result "" )
815
816 message( "\n" )
817ENDIF()
818
819# -------------------------------------------------------------------------------------------------
820# ALibSetCompilerAndLinker(target)
821#
822# Simple CMake function that sets
823# - ALIB_SYMBOLS
824# - ALIB_COMPILER_FEATURES
825# - ALIB_COMPILER_OPTIONS
826# - ALIB_COMPILER_WARNINGS
827# - ALIB_LINKER_OPTIONS
828#
829# In addition, postion independent compile (-fPic) is enabled (for static libraries its default
830# is off with CMake).
831# -------------------------------------------------------------------------------------------------
832function( ALibSetCompilerAndLinker target )
833
834 # compiler flags
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} )
840
841 #definitions
842 target_compile_definitions( ${target} PUBLIC ${ALIB_SYMBOLS} )
843
844 # linker flags
845 IF( NOT "${ALIB_LINKER_OPTIONS}" STREQUAL "" )
846 set_target_properties ( ${target} PROPERTIES LINK_FLAGS ${ALIB_LINKER_OPTIONS} )
847 ENDIF()
848 IF( NOT "${ALIB_EXTERNAL_LIBS}" STREQUAL "" )
849 target_link_libraries ( ${target} PRIVATE ${ALIB_EXTERNAL_LIBS} )
850 ENDIF()
851
852endfunction()
853
854# -------------------------------------------------------------------------------------------------
855# ALibSetCotire(target)
856#
857# If global variable \b ALIB_CMAKE_COTIRE is set and \c true, then the given project is setup to use
858# cotire.
859# -------------------------------------------------------------------------------------------------
860function( ALibSetCotire target )
861
862 if ( ${ALIB_CMAKE_COTIRE} )
863
864 # use multiple processor cores
865 set_target_properties( ${target} PROPERTIES COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "-j" )
866
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" )
869
870 # add cotire to projects
871 cotire ( ${target} )
872
873 endif()
874endfunction()
875
876
877# -------------------------------------------------------------------------------------------------
878# Targets
879# -------------------------------------------------------------------------------------------------
880
881function( ALibAddStaticLibrary )
882 # sources
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 )
887endfunction()
888
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} )
893
894 if(WIN32)
895 target_compile_definitions ( ALib_SharedLib PRIVATE "ALIB_API_IS_DLL" )
896 endif()
897
898 ALibSetCotire ( ALib_SharedLib )
899endfunction()
900
901# -------------------------------------------------------------------------------------------------
902# Precompiled headers and unity build with 'cotire' CMake script.
903# More Info at: https://github.com/sakra/cotire/
904#
905# Note:
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# -------------------------------------------------------------------------------------------------
910
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)
917endif()
918
919
920
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 )
933
934#set(CMAKE_VERBOSE_MAKEFILE ON)