-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1272 lines (1063 loc) · 41.9 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required(VERSION 3.7)
# at least cmake 3.7 is required for:
# * to request source directory path from target:
# `get_target_property(FOO_SOURCE_DIR Foo SOURCE_DIR)`
# * to request BUILDSYSTEM_TARGETS property from a directory.
#
# at least cmake 3.3 is required for:
# * to use IN_LIST in if command:
# (https://cmake.org/cmake/help/v3.3/command/if.html )
# `if(<variable|string> IN_LIST <variable>)`
#
###############################################################################
## cmake policy change ########################################################
###############################################################################
#if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "X.Y.Z")
# # Policy CMP00NN is not set: ...
# #
# # ...
# cmake_policy(SET CMP00NN NEW) # cmake >= X.Y
#endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.1.0")
# Policy CMP0054 is not set: Only interpret if () arguments as variables or
# keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
# details. Use the cmake_policy command to set the policy and suppress this
# warning.
#
# Quoted variables like "MSVC" will no longer be dereferenced when the
# policy is set to NEW. Since the policy is not set the OLD behavior will
# be used.
cmake_policy(SET CMP0054 NEW) # cmake >= 3.1
endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.3.0")
# Policy CMP0057 is not set: Support new IN_LIST if() operator. Run "cmake
# --help-policy CMP0057" for policy details. Use the cmake_policy command to
# set the policy and suppress this warning.
#
# IN_LIST will be interpreted as an operator when the policy is set to NEW.
# Since the policy is not set the OLD behavior will be used.
cmake_policy(SET CMP0057 NEW)
endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
# Policy CMP0074 is not set: find_package uses PackageName_ROOT variables.
# Run "cmake --help-policy CMP0074" for policy details. Use the
# cmake_policy command to set the policy and suppress this warning.
cmake_policy(SET CMP0074 NEW) # cmake >= 3.12
endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
# Policy CMP0075 is not set: Include file check macros honor
# CMAKE_REQUIRED_LIBRARIES. Run "cmake --help-policy CMP0075" for policy
# details. Use the cmake_policy command to set the policy and suppress this
# warning.
#
# CMAKE_REQUIRED_LIBRARIES is set to:
#
# .../_3dparty/arc/xz/lib/Release/Win32/liblzma/liblzma.lib
#
# For compatibility with CMake 3.11 and below this check is ignoring it.
# use global override to avoid policy drop in case where a 3dparty cmake list
# declared cmake version requirement less than 3.12.0
set(CMAKE_POLICY_DEFAULT_CMP0075 NEW)
#cmake_policy(SET CMP0075 NEW) # cmake >= 3.12
endif()
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
# Policy CMP0087 is not set: Install CODE|SCRIPT allow the use of generator
# expressions. Run "cmake --help-policy CMP0087" for policy details. Use
# the cmake_policy command to set the policy and suppress this warning.
cmake_policy(SET CMP0087 NEW) # cmake >= 3.14
endif()
# enable project folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
###############################################################################
## cmake builtin search paths and includes ####################################
###############################################################################
# low level initialization
include(${CMAKE_CURRENT_LIST_DIR}/__init__/__init__.cmake)
include(tacklelib/Project)
include(tacklelib/EnableTargetsExtension)
include(tacklelib/_3dparty/Qt)
###############################################################################
## builtin detection ##########################################################
###############################################################################
## CAUTION:
## Must be called before the `project(...)` to workaround the error:
## `CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.`
## by declare respective variable BEFORE the project main initialization.
##
#tkl_preload_variables(-S -s "CMAKE_MAKE_PROGRAM" "PATH;CMAKE_MAKE_PROGRAM")
# builtin detection runs by the `project` function
project("tacklelib")
set(PROJECT_LIB_NAME tacklelib)
set(LIB_TARGET_NAME ${PROJECT_LIB_NAME})
set(TESTLIB_TARGET_NAME ${PROJECT_NAME}.testlib)
tkl_configure_environment(TACKLELIB_RUNTIME_LINK_TYPE "MSVC;GCC")
###############################################################################
## check environment variables ################################################
###############################################################################
tkl_check_var(REQUIRED . TACKLELIB_ADDRESS_MODEL)
tkl_check_var(REQUIRED . TACKLELIB_RUNTIME_LINK_TYPE)
tkl_check_var(REQUIRED . TACKLELIB_DEP_LIBS)
# utility
tkl_check_var(REQUIRED PATH BOOST_ROOT)
tkl_check_var(REQUIRED . Boost_ARCHITECTURE) # required for boost 1.66 and higher: https://gitlab.kitware.com/cmake/cmake/merge_requests/2568
tkl_check_var(REQUIRED STRING BOOST_COMPONENTS)
tkl_check_var(REQUIRED PATH FMT_ROOT)
# WORKAROUND:
# The issue:
# `CMakeLists.txt tries to override globally visible CMAKE_BUILD_TYPE through the cache` :
# https://github.com/libarchive/libarchive/issues/1163
#
tkl_register_package_var_set(LIBARCHIVE_ROOT CMAKE_BUILD_TYPE Release 0)
###############################################################################
## projects description #######################################################
###############################################################################
set(UNIT_TESTS_MAXOPT_TARGET_NAME tacklelib.unit_tests) # maximal compiler optimization, custom optimization
set(UNIT_TESTS_DEFOPT_TARGET_NAME tacklelib.unit_tests_defopt) # default compiler optimization, no custom optimization
# maximal compiler optimization, custom optimization, referenced project statically linked as library instead as sources
# (even more faster runtime because without unit test asserts from library)
set(UNIT_TESTS_LIBLINKED_TARGET_NAME tacklelib.unit_tests_liblinked)
set(BENCH_TESTS_MAXOPT_TARGET_NAME tacklelib.bench_tests) # maximal compiler optimization, custom optimization
set(BENCH_TESTS_DEFOPT_TARGET_NAME tacklelib.bench_tests_defopt) # default compiler optimization, no custom optimization
set(TESTS_TARGET_NAMES
${UNIT_TESTS_LIBLINKED_TARGET_NAME};
${UNIT_TESTS_MAXOPT_TARGET_NAME};${BENCH_TESTS_MAXOPT_TARGET_NAME};
${UNIT_TESTS_DEFOPT_TARGET_NAME};${BENCH_TESTS_DEFOPT_TARGET_NAME})
# common optimization targets
set(COMMON_OPT_APP_TARGET_NAMES
${LIB_TARGET_NAME};${TESTLIB_TARGET_NAME};${TACKLELIB_DEP_LIBS})
set(TESTS_TARGETS_SRC_DIR
unit;
unit;bench;
unit;bench)
#set(TESTS_TARGETS_PCH_SRC_DIR
# unit/liblinked;
# unit/maxopt;bench/maxopt;
# unit/defopt;bench/defopt)
set(TESTS_TARGETS_DEFINITIONS
"UNIT_TESTS\;MAXOPT\;LIBLINKED"
"UNIT_TESTS\;MAXOPT" "BENCH_TESTS\;MAXOPT\;LIBLINKED" # all bench tests always liblinked
"UNIT_TESTS\;DEFOPT" "BENCH_TESTS\;DEFOPT\;LIBLINKED")
# targets with maximal optimization
set(TESTS_MAXOPT_TARGETS
${UNIT_TESTS_LIBLINKED_TARGET_NAME};
${UNIT_TESTS_MAXOPT_TARGET_NAME};${BENCH_TESTS_MAXOPT_TARGET_NAME})
# targets with library project linkage
set(TESTS_TARGETS_LIBLINKED
1;
0;1
0;1)
# enable c++ standard usage for all targets, basically to avoid the default `--std=gnu++11` parameter for the GCC compiler
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
###############################################################################
## file globbing ##############################################################
###############################################################################
# public headers ONLY
file(GLOB_RECURSE public_headers
${CMAKE_CURRENT_LIST_DIR}/include/*.h*
)
# exclude .bak files
tkl_exclude_paths_from_path_list(. public_headers "${public_headers}" ".bak" 0)
# library
file(GLOB_RECURSE lib_headers
${CMAKE_CURRENT_LIST_DIR}/src/*.h*
)
file(GLOB_RECURSE lib_sources
${CMAKE_CURRENT_LIST_DIR}/src/*.c*
)
# testlib
file(GLOB_RECURSE testlib_headers
${CMAKE_CURRENT_LIST_DIR}/src/testlib/*.h*
)
file(GLOB_RECURSE testlib_sources
${CMAKE_CURRENT_LIST_DIR}/src/testlib/*.c*
)
# exclude .bak files
tkl_exclude_paths_from_path_list(. testlib_headers "${testlib_headers}" ".bak" 0)
tkl_exclude_paths_from_path_list(. testlib_sources "${testlib_sources}" ".bak" 0)
# tests
file(GLOB tests_headers_common
${CMAKE_CURRENT_LIST_DIR}/src/tests/*.h*
)
file(GLOB tests_sources_common
${CMAKE_CURRENT_LIST_DIR}/src/tests/*.c*
)
# exclude .bak files
tkl_exclude_paths_from_path_list(. tests_headers_common "${tests_headers_common}" ".bak" 0)
tkl_exclude_paths_from_path_list(. tests_sources_common "${tests_sources_common}" ".bak" 0)
# exclude tests
tkl_exclude_paths_from_path_list(. lib_sources "${lib_sources}" "/tests" 0)
tkl_exclude_paths_from_path_list(. lib_headers "${lib_headers}" "/tests" 0)
# exclude testlib
tkl_exclude_paths_from_path_list(. lib_sources "${lib_sources}" "/testlib" 0)
tkl_exclude_paths_from_path_list(. lib_headers "${lib_headers}" "/testlib" 0)
set(target_index 0)
foreach(target IN LISTS TESTS_TARGET_NAMES)
list(GET TESTS_TARGETS_SRC_DIR ${target_index} target_src_dir)
file(GLOB_RECURSE tests_sources_${target}
${CMAKE_CURRENT_LIST_DIR}/src/tests/${target_src_dir}/*.c*)
file(GLOB_RECURSE tests_headers_${target}
${CMAKE_CURRENT_LIST_DIR}/src/tests/${target_src_dir}/*.h*)
# exclude marked as "out of project" (/~) files/directories by pattern
tkl_exclude_paths_from_path_list(. tests_sources_${target} "${tests_sources_${target}}" "/~" 0)
tkl_exclude_paths_from_path_list(. tests_headers_${target} "${tests_headers_${target}}" "/~" 0)
# exclude .bak files
tkl_exclude_paths_from_path_list(. tests_sources_${target} "${tests_sources_${target}}" ".bak" 0)
tkl_exclude_paths_from_path_list(. tests_headers_${target} "${tests_headers_${target}}" ".bak" 0)
MATH(EXPR target_index "${target_index}+1")
endforeach()
###############################################################################
## find_package dependencies ##################################################
###############################################################################
# boost
find_package(BOOST_ROOT Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
if (Boost_FOUND)
message(STATUS "(*) Found `Boost`: `${Boost_VERSION}` Location: \"${BOOST_ROOT}\" Libs: [${Boost_LIBRARIES}]")
else()
message(WARNING "(*) Boost is not found")
endif()
# liblzma
if (LIBLZMA_LIBRARY)
find_package(LIBLZMA_LIBRARY LibLZMA)
if (LIBLZMA_FOUND)
message(STATUS "(*) Found `LibLZMA`: `${LIBLZMA_VERSION_STRING}` IncludeDirs: [${LIBLZMA_INCLUDE_DIRS}] Libs: [${LIBLZMA_LIBRARIES}]")
else()
message(WARNING "(*) LibLZMA is not found")
endif()
endif()
###############################################################################
## add_subdirectory dependencies ##############################################
###############################################################################
# test
set(TESTLIB_ENABLED 0)
set(TESTS_ENABLED 0)
if (GTEST_ROOT AND NOT (TACKLELIB_SKIP_TESTLIB AND TACKLELIB_SKIP_TESTS))
if (MSVC)
if (TACKLELIB_LINK_TYPE STREQUAL "dynamic")
set(GTEST_MSVC_SEARCH "MD") # if by `find_package`
set(BUILD_SHARED_LIBS ON) # if by `add_subdirectory`
elseif (TACKLELIB_LINK_TYPE STREQUAL "static")
set(GTEST_MSVC_SEARCH "MT") # if by `find_package`
set(BUILD_SHARED_LIBS OFF) # if by `add_subdirectory`
endif()
elseif (GCC)
# nothing is required
endif()
#find_package(GTest)
#if (GTEST_FOUND AND NOT TACKLELIB_SKIP_TESTLIB)
if (NOT TACKLELIB_SKIP_TESTLIB)
set(TESTLIB_ENABLED 1)
endif()
# automatic tests enable by specific source file
#if (GTEST_FOUND AND NOT TACKLELIB_SKIP_TESTS)
if (NOT TACKLELIB_SKIP_TESTS)
set(tests_sources_common_filtered ${tests_sources_common})
if (tests_sources_common_filtered)
list(FILTER tests_sources_common_filtered EXCLUDE REGEX "(.*)/test_main.cpp")
if (NOT "${tests_sources_common_filtered}" EQUAL "${tests_sources_common}")
tkl_add_target_subdirectory(GTEST_ROOT gtest _3dparty/test/googletest)
set(TESTS_ENABLED 1)
endif()
endif()
endif()
endif()
# fmt
tkl_add_target_subdirectory(FMT_ROOT fmt _3dparty/utility/fmt)
# fmt has it's own cmake list, so we have to call it from here
tkl_initialize_library_target_defaults(fmt "${TACKLELIB_ADDRESS_MODEL}bit")
# pystring
tkl_add_target_subdirectory(PYSTRING_PROXY_ROOT pystring _3dparty/utility/pystring)
# p7 logger
tkl_add_target_subdirectory(P7CLIENT_PROXY_ROOT p7client _3dparty/log/p7client)
if (TARGET p7client)
get_target_property(INCLUDE_DIRS_p7client p7client INCLUDE_DIRECTORIES)
get_target_property(LIBRARIES_p7client p7client LINK_LIBRARIES)
endif()
# 7zip
tkl_add_target_subdirectory(_7ZIP_ROOT 7zip _3dparty/arc/7zip)
if (TARGET 7zip)
get_target_property(INCLUDE_DIRS_7zip 7zip INCLUDE_DIRECTORIES)
get_target_property(LIBRARIES_7zip 7zip LINK_LIBRARIES)
endif()
# libarchive
tkl_add_target_subdirectory(LIBARCHIVE_ROOT libarchive _3dparty/arc/libarchive)
tkl_set_target_property(LIBARCHIVE_ROOT * * "^archive$$|^archive_static$$" * . EXCLUDE_FROM_DEFAULT_BUILD ON) # all except output libraries
tkl_set_target_property(LIBARCHIVE_ROOT * * "^archive$$|^archive_static$$" * . EXCLUDE_FROM_ALL ON) # all except output libraries
if (TARGET archive)
tkl_set_target_property(LIBARCHIVE_ROOT * "^archive$$" . * . EXCLUDE_FROM_DEFAULT_BUILD ON) # all except output libraries
tkl_set_target_property(LIBARCHIVE_ROOT * "^archive$$" . * . EXCLUDE_FROM_ALL ON) # all except output libraries
# libarchive has it's own cmake list, so we have to call it from here
if (TACKLELIB_ADDRESS_MODEL)
tkl_initialize_library_target_defaults(archive "${TACKLELIB_ADDRESS_MODEL}bit")
else()
tkl_initialize_library_target_defaults(archive "")
endif()
endif()
if (TARGET archive_static)
# libarchive has it's own cmake list, so we have to call it from here
if (TACKLELIB_ADDRESS_MODEL)
tkl_initialize_library_target_defaults(archive_static "${TACKLELIB_ADDRESS_MODEL}bit")
else()
tkl_initialize_library_target_defaults(archive_static "")
endif()
endif()
###############################################################################
## target definitions #########################################################
###############################################################################
# library
add_library(${LIB_TARGET_NAME} STATIC
${lib_sources};${lib_headers};${public_headers}
)
tkl_initialize_library_target_defaults(${LIB_TARGET_NAME} "${TACKLELIB_ADDRESS_MODEL}bit")
tkl_source_groups_from_dir_list("Header Files (interface)" FILES ${CMAKE_CURRENT_LIST_DIR}/include *.h*)
tkl_source_groups_from_dir_list("Header Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.h*)
tkl_source_groups_from_dir_list("Source Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.c*)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
PRIVATE
${CMAKE_CURRENT_LIST_DIR}
)
if (FMT_ROOT)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${FMT_ROOT}/include
)
endif()
if (PYSTRING_ROOT)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${PYSTRING_ROOT}
)
endif()
if (Boost_INCLUDE_DIRS)
target_include_directories(${LIB_TARGET_NAME}
PRIVATE
${Boost_INCLUDE_DIRS}
)
endif()
if (INCLUDE_DIRS_p7client)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${INCLUDE_DIRS_p7client}
)
endif()
if (INCLUDE_DIRS_7zip)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${INCLUDE_DIRS_7zip}
)
endif()
if (LIBARCHIVE_ROOT)
target_include_directories(${LIB_TARGET_NAME}
PUBLIC
${LIBARCHIVE_ROOT}
)
endif()
if (LIBLZMA_FOUND)
target_include_directories(${LIB_TARGET_NAME}
PRIVATE
${LIBLZMA_INCLUDE_DIRS}
)
endif()
# to calculate relative path to source files in log output
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
LOG_SRC_ROOT="${LOG_SRC_ROOT}"
)
# to declare export/import from source files
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
LIBRARY_API
LIBRARY_API_EXPORTS_TACKLELIB
)
if (MINGW)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
MINGW
)
endif()
# we need the same Boost definitions here to maintain the link with the same libraries
if (Boost_FOUND)
if (BOOST_ALL_NO_LIB)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
BOOST_ALL_NO_LIB
)
endif()
if (BOOST_ALL_DYN_LINK)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
BOOST_ALL_DYN_LINK
)
endif()
if (BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS # Force to use C++11 lambda functions to implement scope exits
)
endif()
endif()
if (LIBARCHIVE_ROOT)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
LIBARCHIVE_STATIC
)
endif()
if (LIBLZMA_FOUND)
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
LZMA_API_STATIC
)
endif()
if (WIN32)
if (${CMAKE_SIZEOF_VOID_P} EQUAL "8")
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
_AMD64_ # in case of build x64 is required from Windows SDK: `Windows Kits\8.1\Include\shared\stralign.h(120): warning C4090: 'argument': different '__unaligned' qualifiers`
)
else()
tkl_add_target_compile_definitions(${LIB_TARGET_NAME} *
PRIVATE
_X86_ # in case of dynamic library linkage which is required from Windows SDK: `fatal error C1189: #error: "No Target Architecture"`
)
endif()
endif()
# CAUTION:
# The `-lpthread` flag MUST BE after local linking objects and libraries
# dependent on it!
# Either move it to the end of linker command line or use flag `-pthread`
# both for compiler and linker instead the `-lpthread` flag.
# See details here:
# https://stackoverflow.com/questions/19901934/strange-linking-error-dso-missing-from-command-line/19905704#19905704
# https://stackoverflow.com/questions/24814698/how-can-i-add-a-flag-at-the-end-of-the-linking-command-line-using-cmake
#
# CAUTION:
# C++11 is required for at least these:
# * tacklelib/utility/time.hpp: `error: ‘get_time’ is not a member of ‘std’`
# https://stackoverflow.com/questions/46456606/stdget-time-has-not-been-declared/46459130#46459130
#
if (GCC)
tkl_add_target_compile_properties(${LIB_TARGET_NAME} *
#--std=c++11 # minimal required standard
-pthread # compile dependency for `tacklelib/utility/time.hpp` to use `pthread_time.h`
)
tkl_add_target_link_properties(${LIB_TARGET_NAME} NOTSTATIC *
-pthread # compile dependency for `tacklelib/utility/time.hpp` to use `pthread_time.h`
)
endif()
if (Boost_LIBRARY_DIRS)
tkl_add_target_link_directories(${LIB_TARGET_NAME} *
PRIVATE
${Boost_LIBRARY_DIRS}
)
endif()
if (FMT_ROOT)
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC
fmt
)
endif()
if (PYSTRING_ROOT)
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC
pystring
)
endif()
if (Boost_FOUND)
target_link_libraries(${LIB_TARGET_NAME}
PRIVATE
${Boost_LIBRARIES}
)
endif()
if (TARGET p7client)
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC
p7client
)
endif()
if (TARGET 7zip)
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC
7zip
)
endif()
if (TARGET archive_static)
target_link_libraries(${LIB_TARGET_NAME}
PUBLIC
archive_static
)
endif()
if (LIBLZMA_FOUND)
target_link_libraries(${LIB_TARGET_NAME}
PRIVATE
${LIBLZMA_LIBRARIES}
)
endif()
if (WIN32)
target_link_libraries(${LIB_TARGET_NAME}
PRIVATE
Mpr
Netapi32
)
elseif (UNIX AND NOT APPLE)
target_link_libraries(${LIB_TARGET_NAME}
PRIVATE
${CMAKE_DL_LIBS}
)
endif()
# testlib
if (TESTLIB_ENABLED)
add_library(${TESTLIB_TARGET_NAME} STATIC
${testlib_sources};${testlib_headers};${public_headers}
)
tkl_initialize_library_target_defaults(${TESTLIB_TARGET_NAME} "${TACKLELIB_ADDRESS_MODEL}bit")
tkl_source_groups_from_dir_list("Header Files (interface)" FILES ${CMAKE_CURRENT_LIST_DIR}/include *.h*)
tkl_source_groups_from_dir_list("Header Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.h*)
tkl_source_groups_from_dir_list("Source Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.c*)
target_include_directories(${TESTLIB_TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_LIST_DIR}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
)
if (FMT_ROOT)
target_include_directories(${TESTLIB_TARGET_NAME}
PUBLIC
${FMT_ROOT}/include
)
endif()
if (PYSTRING_ROOT)
target_include_directories(${TESTLIB_TARGET_NAME}
PUBLIC
${PYSTRING_ROOT}
)
endif()
if (Boost_INCLUDE_DIRS)
target_include_directories(${TESTLIB_TARGET_NAME}
PRIVATE
${Boost_INCLUDE_DIRS}
)
endif()
# if (GTEST_INCLUDE_DIRS)
# target_include_directories(${TESTLIB_TARGET_NAME}
# PUBLIC
# ${GTEST_INCLUDE_DIRS}
# )
# endif()
tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
PUBLIC
TACKLE_TESTLIB
GTEST_LINKED_AS_SHARED_LIBRARY=1 # gtest links as dynamic by default
)
if (MINGW)
tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
PRIVATE
MINGW
)
endif()
# we need the same Boost definitions here to maintain the link with the same libraries
#if (Boost_FOUND)
# if (BOOST_ALL_NO_LIB)
# tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
# PRIVATE
# BOOST_ALL_NO_LIB
# )
# endif()
#
# if (BOOST_ALL_DYN_LINK)
# tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
# PRIVATE
# BOOST_ALL_DYN_LINK
# )
# endif()
#
# if (BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS)
# tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
# PRIVATE
# BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS # Force to use C++11 lambda functions to implement scope exits
# )
# endif()
#endif()
if (WIN32)
if (${CMAKE_SIZEOF_VOID_P} EQUAL "8")
tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
PRIVATE
_AMD64_ # in case of build x64 is required from Windows SDK: `Windows Kits\8.1\Include\shared\stralign.h(120): warning C4090: 'argument': different '__unaligned' qualifiers`
)
else()
tkl_add_target_compile_definitions(${TESTLIB_TARGET_NAME} *
PRIVATE
_X86_ # in case of dynamic library linkage which is required from Windows SDK: `fatal error C1189: #error: "No Target Architecture"`
)
endif()
endif()
if (Boost_LIBRARY_DIRS)
tkl_add_target_link_directories(${TESTLIB_TARGET_NAME} *
PRIVATE
${Boost_LIBRARY_DIRS}
)
endif()
# if (GTEST_ROOT)
# tkl_add_target_link_directories(${TESTLIB_TARGET_NAME} *
# PRIVATE
# ${GTEST_ROOT}/${_gtest_libpath_suffixes}
# )
# endif()
target_link_libraries(${TESTLIB_TARGET_NAME}
PRIVATE
${LIB_TARGET_NAME}
)
# if (GTEST_LIBRARIES)
# target_link_libraries(${TESTLIB_TARGET_NAME}
# PRIVATE
# ${GTEST_LIBRARIES}
# )
# endif()
if (TARGET gtest)
target_link_libraries(${TESTLIB_TARGET_NAME}
PRIVATE
gtest
)
endif()
else()
list(REMOVE_ITEM COMMON_OPT_APP_TARGET_NAMES ${TESTLIB_TARGET_NAME})
endif()
###############################################################################
## target optimization ########################################################
###############################################################################
# local optimization per target basis
if (MSVC)
tkl_add_target_compile_properties("${COMMON_OPT_APP_TARGET_NAMES}" RELEASE
/Ox # Full Optimization
/Ob2 # Inline Function Expansion: Any Suitable
#/Oi # Enable Intrinsic Functions
/Ot # Enable Intrinsic Functions
/GL # Whole Program Optimization
)
tkl_add_target_compile_properties("${COMMON_OPT_APP_TARGET_NAMES}" *
/MP
)
tkl_add_target_link_properties("${COMMON_OPT_APP_TARGET_NAMES}" * RELEASE
/LTCG # Use Link Time Code Generation
)
elseif (GCC)
tkl_add_target_compile_properties("${COMMON_OPT_APP_TARGET_NAMES}" RELEASE
-O3 # Full Optimization
#/usr/bin/ranlib: .cpp.o: plugin needed to handle lto object
#-flto # Use Link Time Code Generation
)
tkl_add_target_compile_properties("${COMMON_OPT_APP_TARGET_NAMES}" *
-pipe # Use pipes rather than temporary files for communication between the various stages of compilation.
)
#/usr/bin/ranlib: .cpp.o: plugin needed to handle lto object
#tkl_add_target_link_properties("${COMMON_OPT_APP_TARGET_NAMES}" NOTSTATIC RELEASE
# -flto # Use Link Time Code Generation
#)
tkl_add_target_link_properties("${COMMON_OPT_APP_TARGET_NAMES}" NOTSTATIC *
-pipe # Use pipes rather than temporary files for communication between the various stages of compilation.
)
endif()
###############################################################################
## tests ######################################################################
###############################################################################
if (TESTS_ENABLED)
message(STATUS "(*) Tests build: ${TESTS_TARGET_NAMES} (test_main.cpp).")
# inherit dependency include directories and libraries
get_target_property(INTERFACE_COMPILE_DEFINITIONS_${LIB_TARGET_NAME} ${LIB_TARGET_NAME} INTERFACE_COMPILE_DEFINITIONS)
get_target_property(INCLUDE_DIRS_${LIB_TARGET_NAME} ${LIB_TARGET_NAME} INCLUDE_DIRECTORIES)
tkl_get_target_link_libraries_recursively(LIBRARIES_${LIB_TARGET_NAME} ${LIB_TARGET_NAME})
set(target_index 0)
foreach(target IN LISTS TESTS_TARGET_NAMES)
list(GET TESTS_TARGET_NAMES ${target_index} target)
list(GET TESTS_TARGETS_SRC_DIR ${target_index} target_src_dir)
list(GET TESTS_TARGETS_DEFINITIONS ${target_index} target_definitions)
list(GET TESTS_TARGETS_LIBLINKED ${target_index} target_is_liblinked)
set(target_sources_common
${tests_sources_common};${tests_headers_common};
${tests_sources_${target}};${tests_headers_${target}};
${public_headers};${testlib_headers}
)
if (target_is_liblinked)
set(target_sources ${target_sources_common})
else()
set(target_sources ${target_sources_common};${lib_sources};${testlib_sources})
endif()
#tkl_add_pch_header(
# "test_common.hpp" "src/tests/${target_src_dir}/pch.cpp" "pch/${target}/$<CONFIG>/test_common.pch" # create
# "test_common.hpp" "src/tests/test_common.hpp" # use + force include
# "${tests_sources_${target}}" 0) # input + output
add_executable(${target}
${target_sources}
)
tkl_initialize_executable_target_defaults(${target} "${TACKLELIB_ADDRESS_MODEL}bit;console")
# exclude test_common.cpp from compilation to avoid symbols duplications from pch.cpp
#set_source_files_properties(src/tests/test_common.cpp PROPERTIES
# HEADER_FILE_ONLY TRUE)
set_source_files_properties(src/tests/unit/pch.cpp PROPERTIES
HEADER_FILE_ONLY TRUE)
set_source_files_properties(src/tests/bench/pch.cpp PROPERTIES
HEADER_FILE_ONLY TRUE)
tkl_source_groups_from_dir_list("Header Files (interface)" FILES ${CMAKE_CURRENT_LIST_DIR}/include *.h*)
tkl_source_groups_from_dir_list("Header Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.h*)
tkl_source_groups_from_dir_list("Source Files" FILES ${CMAKE_CURRENT_LIST_DIR}/src *.c*)
tkl_source_groups_from_dir_list("tests" FILES ${CMAKE_CURRENT_LIST_DIR}/src/tests *)
target_include_directories(${target}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/tests/${target}
${CMAKE_CURRENT_LIST_DIR}/src/tests
)
target_include_directories(${target}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/include
)
if (FMT_ROOT)
target_include_directories(${target}
PUBLIC
${FMT_ROOT}/include
)
endif()
if (PYSTRING_ROOT)
target_include_directories(${target}
PUBLIC
${PYSTRING_ROOT}
)
endif()
if (Boost_INCLUDE_DIRS)
target_include_directories(${target}
PRIVATE
${Boost_INCLUDE_DIRS}
)
endif()
if (INCLUDE_DIRS_p7client)
target_include_directories(${target}
PUBLIC
${INCLUDE_DIRS_p7client}
)
endif()
if (INCLUDE_DIRS_7zip)
target_include_directories(${target}
PUBLIC
${INCLUDE_DIRS_7zip}
)
endif()
if (LIBARCHIVE_ROOT)
target_include_directories(${target}
PRIVATE
${LIBARCHIVE_ROOT}
)
endif()
if (LIBLZMA_FOUND)
target_include_directories(${target}
PRIVATE
${LIBLZMA_INCLUDE_DIRS}
)
endif()
# if (GTEST_INCLUDE_DIRS)
# target_include_directories(${target}
# PRIVATE
# ${GTEST_INCLUDE_DIRS}
# )
# endif()
tkl_add_target_compile_definitions(${target} *
PRIVATE
${target_definitions}
)
# to calculate relative path to source files in log output
tkl_add_target_compile_definitions(${target} *
PRIVATE
LOG_SRC_ROOT="${LOG_SRC_ROOT}"
)
if (MINGW)
tkl_add_target_compile_definitions(${target} *
PRIVATE
MINGW
)
endif()
if (NOT target_is_liblinked)
# we must include these definitions to link dependency appropriately
if (LIBARCHIVE_ROOT)
tkl_add_target_compile_definitions(${target} *
PRIVATE
LIBARCHIVE_STATIC
)
endif()
if (LIBLZMA_FOUND)
tkl_add_target_compile_definitions(${target} *
PRIVATE
LZMA_API_STATIC
)
endif()
if (INTERFACE_COMPILE_DEFINITIONS_${LIB_TARGET_NAME})
tkl_add_target_compile_definitions(${target} *
PRIVATE
${INTERFACE_COMPILE_DEFINITIONS_${LIB_TARGET_NAME}}
)
endif()
endif()
# we need the same Boost definitions here to maintain the link with the same libraries
#if (Boost_FOUND)
# if (BOOST_ALL_NO_LIB)
# tkl_add_target_compile_definitions(${target} *
# PRIVATE
# BOOST_ALL_NO_LIB
# )
# endif()
#
# if (BOOST_ALL_DYN_LINK)
# tkl_add_target_compile_definitions(${target} *
# PRIVATE
# BOOST_ALL_DYN_LINK
# )
# endif()
#
# if (BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS)
# tkl_add_target_compile_definitions(${target} *
# PRIVATE
# BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS # Force to use C++11 lambda functions to implement scope exits
# )
# endif()
#endif()
if (WIN32)
if (${CMAKE_SIZEOF_VOID_P} EQUAL "8")
tkl_add_target_compile_definitions(${target} *
PRIVATE
_AMD64_ # in case of build x64 is required from Windows SDK: `Windows Kits\8.1\Include\shared\stralign.h(120): warning C4090: 'argument': different '__unaligned' qualifiers`
)
else()
tkl_add_target_compile_definitions(${target} *