-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
2137 lines (1836 loc) · 79.2 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
# SPDX-License-Identifier: 0BSD
#############################################################################
#
# CMake support for building XZ Utils
#
# The complete CMake-based build hasn't been tested much yet and
# thus it's still slightly experimental. Testing this especially
# outside GNU/Linux and Windows would be great now.
#
# A few things are still missing compared to the Autotools-based build:
#
# - 32-bit x86 assembly code for CRC32 and CRC64 isn't used by default.
# Use the option -DENABLE_X86_ASM=ON on the CMake command line to
# enable the assembly files. They are compatible with Linux, *BSDs,
# Cygwin, MinGW-w64, and Darwin. They are NOT compatible with MSVC.
#
# NOTE: The C code includes a generic version compatible with all
# processors and CLMUL version that requires a new enough processor
# with the PCLMULQDQ instruction. If the 32-bit x86 assembly files
# are used, the CLMUL version in the C code is NOT built. On modern
# processors with CLMUL support, the C code should be faster than
# the assembly code while on old processors the assembly code wins.
#
# - External SHA-256 code isn't supported but it's disabled by
# default in the Autotools build too (--enable-external-sha256).
#
# - Extra compiler warning flags aren't added by default.
#
# About CMAKE_BUILD_TYPE:
#
# - CMake's standard choices are fine to use for production builds,
# including "Release" and "RelWithDebInfo".
#
# NOTE: While "Release" uses -O3 by default with some compilers,
# this file overrides -O3 to -O2 for "Release" builds if
# CMAKE_C_FLAGS_RELEASE is not defined by the user. At least
# with GCC and Clang/LLVM, -O3 doesn't seem useful for this
# package as it can result in bigger binaries without any
# improvement in speed compared to -O2.
#
# - Empty value (the default) is handled slightly specially: It
# adds -DNDEBUG to disable debugging code (assert() and a few
# other things). No optimization flags are added so an empty
# CMAKE_BUILD_TYPE is an easy way to build with whatever
# optimization flags one wants, and so this method is also
# suitable for production builds.
#
# If debugging is wanted when using empty CMAKE_BUILD_TYPE,
# include -UNDEBUG in the CFLAGS environment variable or
# in the CMAKE_C_FLAGS CMake variable to override -DNDEBUG.
# With empty CMAKE_BUILD_TYPE, the -UNDEBUG option will go
# after the -DNDEBUG option on the compiler command line and
# thus NDEBUG will be undefined.
#
# - Non-standard build types like "None" aren't treated specially
# and thus won't have -DNEBUG. Such non-standard build types
# SHOULD BE AVOIDED FOR PRODUCTION BUILDS. Or at least one
# should remember to add -DNDEBUG.
#
# If building from xz.git instead of a release tarball, consider
# the following *before* running cmake:
#
# - To get translated messages, install GNU gettext tools (the
# command msgfmt is needed). Alternatively disable translations
# by setting ENABLE_NLS=OFF.
#
# - To get translated man pages, run po4a/update-po which requires
# the po4a tool. The build works without this step too.
#
# This file provides the following installation components (if you only
# need liblzma, install only its components!):
# - liblzma_Runtime (shared library only)
# - liblzma_Development
# - liblzma_Documentation (examples and Doxygen-generated API docs as HTML)
# - xz_Runtime (xz, the symlinks, and possibly translation files)
# - xz_Documentation (xz man pages and the symlinks)
# - xzdec_Runtime
# - xzdec_Documentation (xzdec *and* lzmadec man pages)
# - lzmadec_Runtime
# - lzmainfo_Runtime
# - lzmainfo_Documentation (lzmainfo man pages)
# - scripts_Runtime (xzdiff, xzgrep, xzless, xzmore)
# - scripts_Documentation (their man pages)
# - Documentation (generic docs like README and licenses)
#
# To find the target liblzma::liblzma from other packages, use the CONFIG
# option with find_package() to avoid a conflict with the FindLibLZMA module
# with case-insensitive file systems. For example, to require liblzma 5.2.5
# or a newer compatible version:
#
# find_package(liblzma 5.2.5 REQUIRED CONFIG)
# target_link_libraries(my_application liblzma::liblzma)
#
#############################################################################
#
# Author: Lasse Collin
#
#############################################################################
# NOTE: Translation support is disabled with CMake older than 3.20.
cmake_minimum_required(VERSION 3.14...3.30 FATAL_ERROR)
include(CMakePushCheckState)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckStructHasMember)
include(CheckCSourceCompiles)
include(cmake/tuklib_large_file_support.cmake)
include(cmake/tuklib_integer.cmake)
include(cmake/tuklib_cpucores.cmake)
include(cmake/tuklib_physmem.cmake)
include(cmake/tuklib_progname.cmake)
include(cmake/tuklib_mbstr.cmake)
set(PACKAGE_NAME "XZ Utils")
set(PACKAGE_BUGREPORT "[email protected]")
set(PACKAGE_URL "https://tukaani.org/xz/")
# Get the package version from version.h into PACKAGE_VERSION variable.
file(READ src/liblzma/api/lzma/version.h PACKAGE_VERSION)
string(REGEX REPLACE
"^.*\n\
#define LZMA_VERSION_MAJOR ([0-9]+)\n\
.*\
#define LZMA_VERSION_MINOR ([0-9]+)\n\
.*\
#define LZMA_VERSION_PATCH ([0-9]+)\n\
.*$"
"\\1.\\2.\\3" PACKAGE_VERSION "${PACKAGE_VERSION}")
# With several compilers, CMAKE_BUILD_TYPE=Release uses -O3 optimization
# which results in bigger code without a clear difference in speed. If
# no user-defined CMAKE_C_FLAGS_RELEASE is present, override -O3 to -O2
# to make it possible to recommend CMAKE_BUILD_TYPE=Release.
if(NOT DEFINED CMAKE_C_FLAGS_RELEASE)
set(OVERRIDE_O3_IN_C_FLAGS_RELEASE ON)
endif()
# Among other things, this gives us variables xz_VERSION and xz_VERSION_MAJOR.
project(xz VERSION "${PACKAGE_VERSION}" LANGUAGES C)
if(OVERRIDE_O3_IN_C_FLAGS_RELEASE)
# Looking at CMake's source, there aren't any _FLAGS_RELEASE_INIT
# entries where "-O3" would appear as part of some other option,
# thus a simple search and replace should be fine.
string(REPLACE -O3 -O2 CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
# Update the cache value while keeping its docstring unchanged.
set_property(CACHE CMAKE_C_FLAGS_RELEASE
PROPERTY VALUE "${CMAKE_C_FLAGS_RELEASE}")
endif()
# We need a compiler that supports enough C99 or newer (variable-length arrays
# aren't needed, those are optional in C11/C17). C11 is preferred since C11
# features may be optionally used if they are available.
#
# Setting CMAKE_C_STANDARD here makes it the default for all targets.
# It doesn't affect the INTERFACE so liblzma::liblzma won't end up with
# INTERFACE_COMPILE_FEATURES "c_std_99" or such (the API headers are C89
# and C++ compatible).
#
# Avoid set(CMAKE_C_STANDARD_REQUIRED ON) because it's fine to decay
# to C99 if C11 isn't supported.
set(CMAKE_C_STANDARD 11)
# Support 32-bit x86 assembly files.
if(NOT MSVC)
option(ENABLE_X86_ASM "Enable 32-bit x86 assembly code" OFF)
if(ENABLE_X86_ASM)
enable_language(ASM)
endif()
endif()
# On Apple OSes, don't build executables as bundles:
set(CMAKE_MACOSX_BUNDLE OFF)
# Set CMAKE_INSTALL_LIBDIR and friends. This needs to be done before
# the LOCALEDIR_DEFINITION workaround below.
include(GNUInstallDirs)
# windres from GNU binutils can be tricky with command line arguments
# that contain spaces or other funny characters. Unfortunately we need
# a space in PACKAGE_NAME. Using \x20 to encode the US-ASCII space seems
# to work in both cmd.exe and /bin/sh.
#
# However, even \x20 isn't enough in all situations, resulting in
# "syntax error" from windres. Using --use-temp-file prevents windres
# from using popen() and this seems to fix the problem.
#
# llvm-windres from Clang/LLVM 16.0.6 and older: The \x20 results
# in "XZx20Utils" in the compiled binary. The option --use-temp-file
# makes no difference.
#
# llvm-windres 17.0.0 and later: It emulates GNU windres more accurately, so
# the workarounds used with GNU windres must be used with llvm-windres too.
#
# CMake 3.27 doesn't have CMAKE_RC_COMPILER_ID so we rely on
# CMAKE_C_COMPILER_ID.
if((MINGW OR CYGWIN) AND (
NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "17"))
# Use workarounds with GNU windres and llvm-windres >= 17.0.0. The \x20
# in PACKAGE_NAME_DEFINITION works with gcc and clang too so we don't need
# to worry how to pass different flags to windres and the C compiler.
# Keep the original PACKAGE_NAME intact for generation of liblzma.pc.
string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
string(REPLACE " " "\\x20" PACKAGE_NAME_DEFINITION "${PACKAGE_NAME}")
# Use octal because "Program Files" would become \x20F.
string(REPLACE " " "\\040" LOCALEDIR_DEFINITION
"${CMAKE_INSTALL_FULL_LOCALEDIR}")
else()
# Elsewhere a space is safe. This also keeps things compatible with
# EBCDIC in case CMake-based build is ever done on such a system.
set(PACKAGE_NAME_DEFINITION "${PACKAGE_NAME}")
set(LOCALEDIR_DEFINITION "${CMAKE_INSTALL_FULL_LOCALEDIR}")
endif()
# When used with MSVC, CMake can merge .manifest files with
# linker-generated manifests and embed the result in an executable.
# However, when paired with MinGW-w64, CMake (3.30) ignores .manifest
# files. Embedding a manifest with a resource file works with both
# toochains. It's also the way to do it with Autotools.
#
# With MSVC, we need to disable the default manifest; attempting to add
# two manifest entries would break the build. The flag /MANIFEST:NO
# goes to the linker and it also affects behavior of CMake itself: it
# looks what flags are being passed to the linker and when CMake sees
# the /MANIFEST:NO option, other manifest-related linker flags are
# no longer added (see the file Source/cmcmd.cxx in CMake).
#
# See: https://gitlab.kitware.com/cmake/cmake/-/issues/23066
if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif()
# Dependencies for all Windows resource files:
set(W32RES_DEPENDENCIES
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/common/w32_application.manifest"
)
# Definitions common to all targets:
add_compile_definitions(
# Package info:
PACKAGE_NAME="${PACKAGE_NAME_DEFINITION}"
PACKAGE_BUGREPORT="${PACKAGE_BUGREPORT}"
PACKAGE_URL="${PACKAGE_URL}"
# Standard headers and types are available:
HAVE_STDBOOL_H
HAVE__BOOL
HAVE_STDINT_H
HAVE_INTTYPES_H
# Always enable CRC32 since liblzma should never build without it.
HAVE_CHECK_CRC32
# Disable assert() checks when no build type has been specified. Non-empty
# build types like "Release" and "Debug" handle this by default.
$<$<CONFIG:>:NDEBUG>
)
######################
# System definitions #
######################
# _GNU_SOURCE and such definitions. This specific macro is special since
# it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS.
tuklib_use_system_extensions(ALL)
# Check for large file support. It's required on some 32-bit platforms and
# even on 64-bit MinGW-w64 to get 64-bit off_t. This can be forced off on
# the CMake command line if needed: -DLARGE_FILE_SUPPORT=OFF
tuklib_large_file_support(ALL)
# This is needed by liblzma and xz.
tuklib_integer(ALL)
# This is used for liblzma.pc generation to add -lrt if needed.
#
# The variable name LIBS comes from Autoconf where AC_SEARCH_LIBS adds the
# libraries it finds into the shell variable LIBS. These libraries need to
# be put into liblzma.pc too, thus liblzma.pc.in has @LIBS@ because that
# matches the Autoconf's variable. When CMake support was added, using
# the same variable with configure_file() was the simplest method.
set(LIBS)
# Check for clock_gettime(). Do this before checking for threading so
# that we know there if CLOCK_MONOTONIC is available.
check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
if(NOT HAVE_CLOCK_GETTIME)
# With glibc <= 2.17 or Solaris 10 this needs librt.
# Add librt for the next check for HAVE_CLOCK_GETTIME. If it is
# found after including the library, we know that librt is required.
list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt)
check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME_LIBRT)
# If it was found now, add librt to all targets and keep it in
# CMAKE_REQUIRED_LIBRARIES for further tests too.
if(HAVE_CLOCK_GETTIME_LIBRT)
link_libraries(rt)
set(LIBS "-lrt ${LIBS}") # For liblzma.pc
else()
list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
endif()
endif()
if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_LIBRT)
add_compile_definitions(HAVE_CLOCK_GETTIME)
# Check if CLOCK_MONOTONIC is available for clock_gettime().
check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
tuklib_add_definition_if(ALL HAVE_CLOCK_MONOTONIC)
endif()
# Translation support requires CMake 3.20 because it added the Intl::Intl
# target so we don't need to play with the individual variables.
#
# The definition ENABLE_NLS is added only to those targets that use it, thus
# it's not done here. (xz has translations, xzdec doesn't.)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
find_package(Intl)
find_package(Gettext)
if(Intl_FOUND)
option(ENABLE_NLS "Native Language Support (translated messages)" ON)
# If translation support is enabled but neither gettext tools or
# pre-generated .gmo files exist, translation support cannot be
# enabled.
#
# The detection of pre-generated .gmo files is done by only
# checking for the existence of a single .gmo file; Ukrainian
# is one of many translations that gets regular updates.
if(ENABLE_NLS AND NOT GETTEXT_FOUND AND
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/uk.gmo")
# This only sets the variable, not the cache variable!
set(ENABLE_NLS OFF)
# This message is shown only when new enough CMake is used and
# library support for translations was found. The assumptions is
# that in this situation the user might have interest in the
# translations. This also keeps this code simpler.
message(WARNING "Native language support (NLS) has been disabled. "
"NLS support requires either gettext tools or "
"pre-generated .gmo files. The latter are only "
"available in distribution tarballs. "
"To avoid this warning, NLS can be explicitly "
"disabled by passing -DENABLE_NLS=OFF to cmake.")
endif()
# Warn if NLS is enabled but translated man pages are missing.
if(UNIX AND ENABLE_NLS AND
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po4a/man")
message(WARNING "Native language support (NLS) has been enabled "
"but pre-generated translated man pages "
"were not found and thus they won't be installed. "
"Run 'po4a/update-po' to generate them.")
endif()
# The *installed* name of the translation files is "xz.mo".
set(TRANSLATION_DOMAIN "xz")
endif()
endif()
# Options for new enough GCC or Clang on any arch or operating system:
if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
# configure.ac has a long list but it won't be copied here:
add_compile_options(-Wall -Wextra)
endif()
#############################################################################
# liblzma
#############################################################################
option(BUILD_SHARED_LIBS "Build liblzma as a shared library instead of static")
if(NOT WIN32)
# Symbol versioning only affects ELF shared libraries. The option is
# ignored for static libraries.
#
# Determine the default value so that it's always set with
# shared libraries in mind which helps if the build dir is reconfigured
# from static to shared libs without resetting the cache variables.
set(SYMBOL_VERSIONING_DEFAULT OFF)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
(CMAKE_SYSTEM_PROCESSOR MATCHES "[Mm]icro[Bb]laze" OR
CMAKE_C_COMPILER_ID STREQUAL "NVHPC"))
# As a special case, GNU/Linux on MicroBlaze gets the generic
# symbol versioning because GCC 12 doesn't support the __symver__
# attribute on MicroBlaze. On Linux, CMAKE_SYSTEM_PROCESSOR comes
# from "uname -m" for native builds (should be "microblaze") or from
# the CMake toolchain file (not perfectly standardized but it very
# likely has "microblaze" in lower case or mixed case somewhere in
# the string).
#
# NVIDIA HPC Compiler doesn't support symbol versioning but
# it uses the linked from the system so the linker script
# can still be used to get the generic symbol versioning.
set(SYMBOL_VERSIONING_DEFAULT "generic")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# GNU/Linux-specific symbol versioning for shared liblzma.
# This includes a few extra compatibility symbols for RHEL/CentOS 7
# which are pointless on non-glibc non-Linux systems.
#
# Avoid symvers on Linux with non-glibc like musl and uClibc.
# In Autoconf it's enough to check that $host_os equals linux-gnu
# instead of, for example, linux-musl. CMake doesn't provide such
# a method.
#
# This check is here for now since it's not strictly required
# by anything else.
check_c_source_compiles(
"#include <features.h>
#if defined(__GLIBC__) && !defined(__UCLIBC__)
int main(void) { return 0; }
#else
compile error
#endif
"
IS_LINUX_WITH_GLIBC)
if(IS_LINUX_WITH_GLIBC)
set(SYMBOL_VERSIONING_DEFAULT "linux")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(SYMBOL_VERSIONING_DEFAULT "generic")
endif()
set(SYMBOL_VERSIONING "${SYMBOL_VERSIONING_DEFAULT}" CACHE STRING
"Enable ELF shared library symbol versioning (OFF, generic, linux)")
# Show a dropdown menu in CMake GUI:
set_property(CACHE SYMBOL_VERSIONING PROPERTY STRINGS "OFF;generic;linux")
endif()
set(LIBLZMA_API_HEADERS
src/liblzma/api/lzma.h
src/liblzma/api/lzma/base.h
src/liblzma/api/lzma/bcj.h
src/liblzma/api/lzma/block.h
src/liblzma/api/lzma/check.h
src/liblzma/api/lzma/container.h
src/liblzma/api/lzma/delta.h
src/liblzma/api/lzma/filter.h
src/liblzma/api/lzma/hardware.h
src/liblzma/api/lzma/index.h
src/liblzma/api/lzma/index_hash.h
src/liblzma/api/lzma/lzma12.h
src/liblzma/api/lzma/stream_flags.h
src/liblzma/api/lzma/version.h
src/liblzma/api/lzma/vli.h
)
add_library(liblzma
src/common/mythread.h
src/common/sysdefs.h
src/common/tuklib_common.h
src/common/tuklib_config.h
src/common/tuklib_integer.h
src/common/tuklib_physmem.c
src/common/tuklib_physmem.h
${LIBLZMA_API_HEADERS}
src/liblzma/check/check.c
src/liblzma/check/check.h
src/liblzma/check/crc_common.h
src/liblzma/check/crc_x86_clmul.h
src/liblzma/check/crc32_arm64.h
src/liblzma/common/block_util.c
src/liblzma/common/common.c
src/liblzma/common/common.h
src/liblzma/common/easy_preset.c
src/liblzma/common/easy_preset.h
src/liblzma/common/filter_common.c
src/liblzma/common/filter_common.h
src/liblzma/common/hardware_physmem.c
src/liblzma/common/index.c
src/liblzma/common/index.h
src/liblzma/common/memcmplen.h
src/liblzma/common/stream_flags_common.c
src/liblzma/common/stream_flags_common.h
src/liblzma/common/string_conversion.c
src/liblzma/common/vli_size.c
)
target_include_directories(liblzma PRIVATE
src/liblzma/api
src/liblzma/common
src/liblzma/check
src/liblzma/lz
src/liblzma/rangecoder
src/liblzma/lzma
src/liblzma/delta
src/liblzma/simple
src/common
)
######################
# Size optimizations #
######################
option(ENABLE_SMALL "Reduce code size at expense of speed. \
This may be useful together with CMAKE_BUILD_TYPE=MinSizeRel.")
if(ENABLE_SMALL)
add_compile_definitions(HAVE_SMALL)
endif()
##########
# Checks #
##########
set(ADDITIONAL_SUPPORTED_CHECKS crc64 sha256)
set(ADDITIONAL_CHECK_TYPES "${ADDITIONAL_SUPPORTED_CHECKS}" CACHE STRING
"Additional check types to support (crc32 is always built)")
foreach(CHECK IN LISTS ADDITIONAL_CHECK_TYPES)
if(NOT CHECK IN_LIST ADDITIONAL_SUPPORTED_CHECKS)
message(FATAL_ERROR "'${CHECK}' is not a supported check type")
endif()
endforeach()
if(ENABLE_SMALL)
target_sources(liblzma PRIVATE src/liblzma/check/crc32_small.c)
else()
target_sources(liblzma PRIVATE
src/liblzma/check/crc32_table.c
src/liblzma/check/crc32_table_be.h
src/liblzma/check/crc32_table_le.h
)
if(ENABLE_X86_ASM)
target_sources(liblzma PRIVATE src/liblzma/check/crc32_x86.S)
else()
target_sources(liblzma PRIVATE src/liblzma/check/crc32_fast.c)
endif()
endif()
if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES)
add_compile_definitions("HAVE_CHECK_CRC64")
if(ENABLE_SMALL)
target_sources(liblzma PRIVATE src/liblzma/check/crc64_small.c)
else()
target_sources(liblzma PRIVATE
src/liblzma/check/crc64_table.c
src/liblzma/check/crc64_table_be.h
src/liblzma/check/crc64_table_le.h
)
if(ENABLE_X86_ASM)
target_sources(liblzma PRIVATE src/liblzma/check/crc64_x86.S)
else()
target_sources(liblzma PRIVATE src/liblzma/check/crc64_fast.c)
endif()
endif()
endif()
if("sha256" IN_LIST ADDITIONAL_CHECK_TYPES)
add_compile_definitions("HAVE_CHECK_SHA256")
target_sources(liblzma PRIVATE src/liblzma/check/sha256.c)
endif()
#################
# Match finders #
#################
set(SUPPORTED_MATCH_FINDERS hc3 hc4 bt2 bt3 bt4)
set(MATCH_FINDERS "${SUPPORTED_MATCH_FINDERS}" CACHE STRING
"Match finders to support (at least one is required for LZMA1 or LZMA2)")
foreach(MF IN LISTS MATCH_FINDERS)
if(MF IN_LIST SUPPORTED_MATCH_FINDERS)
string(TOUPPER "${MF}" MF_UPPER)
add_compile_definitions("HAVE_MF_${MF_UPPER}")
else()
message(FATAL_ERROR "'${MF}' is not a supported match finder")
endif()
endforeach()
#############
# Threading #
#############
# Supported threading methods:
# ON - autodetect the best threading method. The autodetection will
# prefer Windows threading (win95 or vista) over posix if both are
# available. vista threads will be used over win95 unless it is a
# 32-bit build.
# OFF - Disable threading.
# posix - Use posix threading (pthreads), or throw an error if not available.
# win95 - Use Windows win95 threading, or throw an error if not available.
# vista - Use Windows vista threading, or throw an error if not available.
set(SUPPORTED_THREADING_METHODS ON OFF posix win95 vista)
set(ENABLE_THREADS ON CACHE STRING
"Threading method: Set to 'ON' to autodetect, 'OFF' to disable threading.")
# Create dropdown in CMake GUI since only 1 threading method is possible
# to select in a build.
set_property(CACHE ENABLE_THREADS
PROPERTY STRINGS "${SUPPORTED_THREADING_METHODS}")
# This is a flag variable set when win95 threads are used. We must ensure
# the combination of enable_small and win95 threads is not used without a
# compiler supporting attribute __constructor__.
set(USE_WIN95_THREADS OFF)
# This is a flag variable set when posix threads (pthreads) are used.
# It's needed when creating liblzma-config.cmake where dependency on
# Threads::Threads is only needed with pthreads.
set(USE_POSIX_THREADS OFF)
if(NOT ENABLE_THREADS IN_LIST SUPPORTED_THREADING_METHODS)
message(FATAL_ERROR "'${ENABLE_THREADS}' is not a supported "
"threading method")
endif()
if(ENABLE_THREADS)
# Also set THREADS_PREFER_PTHREAD_FLAG since the flag has no effect
# for Windows threading.
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# If both Windows and posix threading are available, prefer Windows.
# Note that on Cygwin CMAKE_USE_WIN32_THREADS_INIT is false.
if(CMAKE_USE_WIN32_THREADS_INIT AND NOT ENABLE_THREADS STREQUAL "posix")
if(ENABLE_THREADS STREQUAL "win95"
OR (ENABLE_THREADS STREQUAL "ON"
AND CMAKE_SIZEOF_VOID_P EQUAL 4))
# Use Windows 95 (and thus XP) compatible threads.
# This avoids use of features that were added in
# Windows Vista. This is used for 32-bit x86 builds for
# compatibility reasons since it makes no measurable difference
# in performance compared to Vista threads.
set(USE_WIN95_THREADS ON)
add_compile_definitions(MYTHREAD_WIN95)
else()
add_compile_definitions(MYTHREAD_VISTA)
endif()
elseif(CMAKE_USE_PTHREADS_INIT)
if(ENABLE_THREADS STREQUAL "posix" OR ENABLE_THREADS STREQUAL "ON")
# The threading library only needs to be explicitly linked
# for posix threads, so this is needed for creating
# liblzma-config.cmake later.
set(USE_POSIX_THREADS ON)
target_link_libraries(liblzma PRIVATE Threads::Threads)
add_compile_definitions(MYTHREAD_POSIX)
# Make the thread libs available in later checks. In practice
# only pthread_condattr_setclock check should need this.
list(INSERT CMAKE_REQUIRED_LIBRARIES 0 "${CMAKE_THREAD_LIBS_INIT}")
# Check if pthread_condattr_setclock() exists to
# use CLOCK_MONOTONIC.
if(HAVE_CLOCK_MONOTONIC)
check_symbol_exists(pthread_condattr_setclock pthread.h
HAVE_PTHREAD_CONDATTR_SETCLOCK)
tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK)
endif()
else()
message(SEND_ERROR
"Windows threading method was requested but a compatible "
"library could not be found")
endif()
else()
message(SEND_ERROR "No supported threading library found")
endif()
target_sources(liblzma PRIVATE
src/common/tuklib_cpucores.c
src/common/tuklib_cpucores.h
src/liblzma/common/hardware_cputhreads.c
src/liblzma/common/outqueue.c
src/liblzma/common/outqueue.h
)
endif()
############
# Encoders #
############
set(SIMPLE_FILTERS
x86
arm
armthumb
arm64
powerpc
ia64
sparc
riscv
)
# The SUPPORTED_FILTERS are shared between Encoders and Decoders
# since only lzip does not appear in both lists. lzip is a special
# case anyway, so it is handled separately in the Decoders section.
set(SUPPORTED_FILTERS
lzma1
lzma2
delta
"${SIMPLE_FILTERS}"
)
set(ENCODERS "${SUPPORTED_FILTERS}" CACHE STRING "Encoders to support")
# If LZMA2 is enabled, then LZMA1 must also be enabled.
if(NOT "lzma1" IN_LIST ENCODERS AND "lzma2" IN_LIST ENCODERS)
message(FATAL_ERROR "LZMA2 encoder requires that LZMA1 is also enabled")
endif()
# If LZMA1 is enabled, then at least one match finder must be enabled.
if(MATCH_FINDERS STREQUAL "" AND "lzma1" IN_LIST ENCODERS)
message(FATAL_ERROR "At least 1 match finder is required for an "
"LZ-based encoder")
endif()
set(HAVE_DELTA_CODER OFF)
set(SIMPLE_ENCODERS OFF)
set(HAVE_ENCODERS OFF)
foreach(ENCODER IN LISTS ENCODERS)
if(ENCODER IN_LIST SUPPORTED_FILTERS)
set(HAVE_ENCODERS ON)
if(NOT SIMPLE_ENCODERS AND ENCODER IN_LIST SIMPLE_FILTERS)
set(SIMPLE_ENCODERS ON)
endif()
string(TOUPPER "${ENCODER}" ENCODER_UPPER)
add_compile_definitions("HAVE_ENCODER_${ENCODER_UPPER}")
else()
message(FATAL_ERROR "'${ENCODER}' is not a supported encoder")
endif()
endforeach()
if(HAVE_ENCODERS)
add_compile_definitions(HAVE_ENCODERS)
target_sources(liblzma PRIVATE
src/liblzma/common/alone_encoder.c
src/liblzma/common/block_buffer_encoder.c
src/liblzma/common/block_buffer_encoder.h
src/liblzma/common/block_encoder.c
src/liblzma/common/block_encoder.h
src/liblzma/common/block_header_encoder.c
src/liblzma/common/easy_buffer_encoder.c
src/liblzma/common/easy_encoder.c
src/liblzma/common/easy_encoder_memusage.c
src/liblzma/common/filter_buffer_encoder.c
src/liblzma/common/filter_encoder.c
src/liblzma/common/filter_encoder.h
src/liblzma/common/filter_flags_encoder.c
src/liblzma/common/index_encoder.c
src/liblzma/common/index_encoder.h
src/liblzma/common/stream_buffer_encoder.c
src/liblzma/common/stream_encoder.c
src/liblzma/common/stream_flags_encoder.c
src/liblzma/common/vli_encoder.c
)
if(ENABLE_THREADS)
target_sources(liblzma PRIVATE
src/liblzma/common/stream_encoder_mt.c
)
endif()
if(SIMPLE_ENCODERS)
target_sources(liblzma PRIVATE
src/liblzma/simple/simple_encoder.c
src/liblzma/simple/simple_encoder.h
)
endif()
if("lzma1" IN_LIST ENCODERS)
target_sources(liblzma PRIVATE
src/liblzma/lzma/lzma_encoder.c
src/liblzma/lzma/lzma_encoder.h
src/liblzma/lzma/lzma_encoder_optimum_fast.c
src/liblzma/lzma/lzma_encoder_optimum_normal.c
src/liblzma/lzma/lzma_encoder_private.h
src/liblzma/lzma/fastpos.h
src/liblzma/lz/lz_encoder.c
src/liblzma/lz/lz_encoder.h
src/liblzma/lz/lz_encoder_hash.h
src/liblzma/lz/lz_encoder_hash_table.h
src/liblzma/lz/lz_encoder_mf.c
src/liblzma/rangecoder/price.h
src/liblzma/rangecoder/price_table.c
src/liblzma/rangecoder/range_encoder.h
)
if(NOT ENABLE_SMALL)
target_sources(liblzma PRIVATE src/liblzma/lzma/fastpos_table.c)
endif()
endif()
if("lzma2" IN_LIST ENCODERS)
target_sources(liblzma PRIVATE
src/liblzma/lzma/lzma2_encoder.c
src/liblzma/lzma/lzma2_encoder.h
)
endif()
if("delta" IN_LIST ENCODERS)
set(HAVE_DELTA_CODER ON)
target_sources(liblzma PRIVATE
src/liblzma/delta/delta_encoder.c
src/liblzma/delta/delta_encoder.h
)
endif()
endif()
############
# Decoders #
############
set(DECODERS "${SUPPORTED_FILTERS}" CACHE STRING "Decoders to support")
set(SIMPLE_DECODERS OFF)
set(HAVE_DECODERS OFF)
foreach(DECODER IN LISTS DECODERS)
if(DECODER IN_LIST SUPPORTED_FILTERS)
set(HAVE_DECODERS ON)
if(NOT SIMPLE_DECODERS AND DECODER IN_LIST SIMPLE_FILTERS)
set(SIMPLE_DECODERS ON)
endif()
string(TOUPPER "${DECODER}" DECODER_UPPER)
add_compile_definitions("HAVE_DECODER_${DECODER_UPPER}")
else()
message(FATAL_ERROR "'${DECODER}' is not a supported decoder")
endif()
endforeach()
if(HAVE_DECODERS)
add_compile_definitions(HAVE_DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/common/alone_decoder.c
src/liblzma/common/alone_decoder.h
src/liblzma/common/auto_decoder.c
src/liblzma/common/block_buffer_decoder.c
src/liblzma/common/block_decoder.c
src/liblzma/common/block_decoder.h
src/liblzma/common/block_header_decoder.c
src/liblzma/common/easy_decoder_memusage.c
src/liblzma/common/file_info.c
src/liblzma/common/filter_buffer_decoder.c
src/liblzma/common/filter_decoder.c
src/liblzma/common/filter_decoder.h
src/liblzma/common/filter_flags_decoder.c
src/liblzma/common/index_decoder.c
src/liblzma/common/index_decoder.h
src/liblzma/common/index_hash.c
src/liblzma/common/stream_buffer_decoder.c
src/liblzma/common/stream_decoder.c
src/liblzma/common/stream_flags_decoder.c
src/liblzma/common/stream_decoder.h
src/liblzma/common/vli_decoder.c
)
if(ENABLE_THREADS)
target_sources(liblzma PRIVATE
src/liblzma/common/stream_decoder_mt.c
)
endif()
if(SIMPLE_DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/simple/simple_decoder.c
src/liblzma/simple/simple_decoder.h
)
endif()
if("lzma1" IN_LIST DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/lzma/lzma_decoder.c
src/liblzma/lzma/lzma_decoder.h
src/liblzma/rangecoder/range_decoder.h
src/liblzma/lz/lz_decoder.c
src/liblzma/lz/lz_decoder.h
)
endif()
if("lzma2" IN_LIST DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/lzma/lzma2_decoder.c
src/liblzma/lzma/lzma2_decoder.h
)
endif()
if("delta" IN_LIST DECODERS)
set(HAVE_DELTA_CODER ON)
target_sources(liblzma PRIVATE
src/liblzma/delta/delta_decoder.c
src/liblzma/delta/delta_decoder.h
)
endif()
endif()
# Some sources must appear if the filter is configured as either
# an encoder or decoder.
if("lzma1" IN_LIST ENCODERS OR "lzma1" IN_LIST DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/rangecoder/range_common.h
src/liblzma/lzma/lzma_encoder_presets.c
src/liblzma/lzma/lzma_common.h
)
endif()
if(HAVE_DELTA_CODER)
target_sources(liblzma PRIVATE
src/liblzma/delta/delta_common.c
src/liblzma/delta/delta_common.h
src/liblzma/delta/delta_private.h
)
endif()
if(SIMPLE_ENCODERS OR SIMPLE_DECODERS)
target_sources(liblzma PRIVATE
src/liblzma/simple/simple_coder.c
src/liblzma/simple/simple_coder.h
src/liblzma/simple/simple_private.h
)
endif()
foreach(SIMPLE_CODER IN LISTS SIMPLE_FILTERS)
if(SIMPLE_CODER IN_LIST ENCODERS OR SIMPLE_CODER IN_LIST DECODERS)
target_sources(liblzma PRIVATE "src/liblzma/simple/${SIMPLE_CODER}.c")
endif()
endforeach()
#############
# MicroLZMA #
#############
option(MICROLZMA_ENCODER
"MicroLZMA encoder (needed by specific applications only)" ON)
option(MICROLZMA_DECODER
"MicroLZMA decoder (needed by specific applications only)" ON)
if(MICROLZMA_ENCODER)
if(NOT "lzma1" IN_LIST ENCODERS)
message(FATAL_ERROR "The LZMA1 encoder is required to support the "
"MicroLZMA encoder")
endif()
target_sources(liblzma PRIVATE src/liblzma/common/microlzma_encoder.c)
endif()
if(MICROLZMA_DECODER)
if(NOT "lzma1" IN_LIST DECODERS)
message(FATAL_ERROR "The LZMA1 decoder is required to support the "
"MicroLZMA decoder")
endif()
target_sources(liblzma PRIVATE src/liblzma/common/microlzma_decoder.c)
endif()
#############################
# lzip (.lz) format support #
#############################
option(LZIP_DECODER "Support lzip decoder" ON)
if(LZIP_DECODER)
# If lzip decoder support is requested, make sure LZMA1 decoder is enabled.
if(NOT "lzma1" IN_LIST DECODERS)
message(FATAL_ERROR "The LZMA1 decoder is required to support the "
"lzip decoder")
endif()
add_compile_definitions(HAVE_LZIP_DECODER)
target_sources(liblzma PRIVATE
src/liblzma/common/lzip_decoder.c
src/liblzma/common/lzip_decoder.h
)