1 #############################################################################
3 # Very limited CMake support for building some parts of XZ Utils
5 # For now, this is intended to be useful to build static or shared liblzma
6 # on Windows with MSVC (to avoid the need to maintain Visual Studio project
7 # files). Building liblzma on a few other platforms should work too but it
8 # is somewhat experimental and not as portable as using ./configure.
10 # On some platforms this builds also xz and xzdec, but these are
11 # highly experimental and meant for testing only:
12 # - No large file support on those 32-bit platforms that need it
13 # - No sandboxing support
16 # Other missing things:
17 # - No xzgrep or other scripts or their symlinks
18 # - No xz tests (liblzma tests only)
20 # NOTE: Even if the code compiles without warnings, the end result may be
21 # different than via ./configure. Specifically, the list of #defines
22 # may be different (if so, probably this CMakeLists.txt got them wrong).
24 # This file provides the following installation components (if you only
25 # need liblzma, install only its components!):
27 # - liblzma_Development
28 # - xz (on some platforms only)
29 # - xzdec (on some platforms only)
31 # To find the target liblzma::liblzma from other packages, use the CONFIG
32 # option with find_package() to avoid a conflict with the FindLibLZMA module
33 # with case-insensitive file systems. For example, to require liblzma 5.2.5
34 # or a newer compatible version:
36 # find_package(liblzma 5.2.5 REQUIRED CONFIG)
37 # target_link_libraries(my_application liblzma::liblzma)
39 #############################################################################
41 # Author: Lasse Collin
43 # This file has been put into the public domain.
44 # You can do whatever you want with this file.
46 #############################################################################
48 cmake_minimum_required(VERSION 3.13...3.27 FATAL_ERROR)
50 include(CMakePushCheckState)
51 include(CheckIncludeFile)
52 include(CheckSymbolExists)
53 include(CheckStructHasMember)
54 include(CheckCSourceCompiles)
55 include(cmake/tuklib_integer.cmake)
56 include(cmake/tuklib_cpucores.cmake)
57 include(cmake/tuklib_physmem.cmake)
58 include(cmake/tuklib_progname.cmake)
59 include(cmake/tuklib_mbstr.cmake)
61 # Get the package version from version.h into XZ_VERSION variable.
62 file(READ src/liblzma/api/lzma/version.h XZ_VERSION)
65 #define LZMA_VERSION_MAJOR ([0-9]+)\n\
67 #define LZMA_VERSION_MINOR ([0-9]+)\n\
69 #define LZMA_VERSION_PATCH ([0-9]+)\n\
71 "\\1.\\2.\\3" XZ_VERSION "${XZ_VERSION}")
73 # Among other things, this gives us variables xz_VERSION and xz_VERSION_MAJOR.
74 project(xz VERSION "${XZ_VERSION}" LANGUAGES C)
76 # We need a compiler that supports enough C99 or newer (variable-length arrays
77 # aren't needed, those are optional in C17). Setting CMAKE_C_STANDARD here
78 # makes it the default for all targets. It doesn't affect the INTERFACE so
79 # liblzma::liblzma won't end up with INTERFACE_COMPILE_FEATURES "c_std_99"
80 # (the API headers are C89 and C++ compatible).
81 set(CMAKE_C_STANDARD 99)
82 set(CMAKE_C_STANDARD_REQUIRED ON)
84 # On Apple OSes, don't build executables as bundles:
85 set(CMAKE_MACOSX_BUNDLE OFF)
87 # windres from GNU binutils can be tricky with command line arguments
88 # that contain spaces or other funny characters. Unfortunately we need
89 # a space in PACKAGE_NAME. Using \x20 to encode the US-ASCII space seems
90 # to work in both cmd.exe and /bin/sh.
92 # However, even \x20 isn't enough in all situations, resulting in
93 # "syntax error" from windres. Using --use-temp-file prevents windres
94 # from using popen() and this seems to fix the problem.
96 # llvm-windres from Clang/LLVM 16.0.6 and older: The \x20 results
97 # in "XZx20Utils" in the compiled binary. The option --use-temp-file
98 # makes no difference.
100 # llvm-windres 17.0.0 and later: It emulates GNU windres more accurately, so
101 # the workarounds used with GNU windres must be used with llvm-windres too.
103 # CMake 3.27 doesn't have CMAKE_RC_COMPILER_ID so we rely on
104 # CMAKE_C_COMPILER_ID.
105 if(WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR (
106 CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
107 CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "17")))
108 # Use workarounds with GNU windres and llvm-windres >= 17.0.0. The \x20
109 # in PACKAGE_NAME works with gcc and clang too so we don't need to worry
110 # how to pass different flags to windres and the C compiler.
111 string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
112 set(PACKAGE_NAME "XZ\\x20Utils")
114 # Elsewhere a space is safe. This also keeps things compatible with
115 # EBCDIC in case CMake-based build is ever done on such a system.
116 set(PACKAGE_NAME "XZ Utils")
119 # Definitions common to all targets:
120 add_compile_definitions(
122 PACKAGE_NAME="${PACKAGE_NAME}"
123 PACKAGE_BUGREPORT="xz@tukaani.org"
124 PACKAGE_URL="https://tukaani.org/xz/"
126 # Standard headers and types are available:
132 # Always enable CRC32 since liblzma should never build without it.
135 # Disable assert() checks when no build type has been specified. Non-empty
136 # build types like "Release" and "Debug" handle this by default.
141 ######################
142 # System definitions #
143 ######################
145 # _GNU_SOURCE and such definitions. This specific macro is special since
146 # it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS.
147 tuklib_use_system_extensions(ALL)
149 # This is needed by liblzma and xz.
152 # Check for clock_gettime(). Do this before checking for threading so
153 # that we know there if CLOCK_MONOTONIC is available.
155 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
157 if(NOT HAVE_CLOCK_GETTIME)
158 # With glibc <= 2.17 or Solaris 10 this needs librt.
159 # Add librt for the next check for HAVE_CLOCK_GETTIME. If it is
160 # found after including the library, we know that librt is required.
161 list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt)
162 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME_LIBRT)
164 # If it was found now, add librt to all targets and keep it in
165 # CMAKE_REQUIRED_LIBRARIES for further tests too.
166 if(HAVE_CLOCK_GETTIME_LIBRT)
169 list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
173 if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_LIBRT)
174 add_compile_definitions(HAVE_CLOCK_GETTIME)
176 # Check if CLOCK_MONOTONIC is available for clock_gettime().
177 check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
178 tuklib_add_definition_if(ALL HAVE_CLOCK_MONOTONIC)
182 # Options for new enough GCC or Clang on any arch or operating system:
183 if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
184 # configure.ac has a long list but it won't be copied here:
185 add_compile_options(-Wall -Wextra)
189 #############################################################################
191 #############################################################################
193 option(BUILD_SHARED_LIBS "Build liblzma as a shared library instead of static")
196 src/common/mythread.h
198 src/common/tuklib_common.h
199 src/common/tuklib_config.h
200 src/common/tuklib_integer.h
201 src/common/tuklib_physmem.c
202 src/common/tuklib_physmem.h
203 src/liblzma/api/lzma.h
204 src/liblzma/api/lzma/base.h
205 src/liblzma/api/lzma/bcj.h
206 src/liblzma/api/lzma/block.h
207 src/liblzma/api/lzma/check.h
208 src/liblzma/api/lzma/container.h
209 src/liblzma/api/lzma/delta.h
210 src/liblzma/api/lzma/filter.h
211 src/liblzma/api/lzma/hardware.h
212 src/liblzma/api/lzma/index.h
213 src/liblzma/api/lzma/index_hash.h
214 src/liblzma/api/lzma/lzma12.h
215 src/liblzma/api/lzma/stream_flags.h
216 src/liblzma/api/lzma/version.h
217 src/liblzma/api/lzma/vli.h
218 src/liblzma/check/check.c
219 src/liblzma/check/check.h
220 src/liblzma/check/crc_macros.h
221 src/liblzma/common/block_util.c
222 src/liblzma/common/common.c
223 src/liblzma/common/common.h
224 src/liblzma/common/easy_preset.c
225 src/liblzma/common/easy_preset.h
226 src/liblzma/common/filter_common.c
227 src/liblzma/common/filter_common.h
228 src/liblzma/common/hardware_physmem.c
229 src/liblzma/common/index.c
230 src/liblzma/common/index.h
231 src/liblzma/common/memcmplen.h
232 src/liblzma/common/stream_flags_common.c
233 src/liblzma/common/stream_flags_common.h
234 src/liblzma/common/string_conversion.c
235 src/liblzma/common/vli_size.c
238 target_include_directories(liblzma PRIVATE
243 src/liblzma/rangecoder
251 ######################
252 # Size optimizations #
253 ######################
255 option(ENABLE_SMALL "Reduce code size at expense of speed. \
256 This may be useful together with CMAKE_BUILD_TYPE=MinSizeRel.")
259 add_compile_definitions(HAVE_SMALL)
267 set(ADDITIONAL_SUPPORTED_CHECKS crc64 sha256)
269 set(ADDITIONAL_CHECK_TYPES "${ADDITIONAL_SUPPORTED_CHECKS}" CACHE STRING
270 "Additional check types to support (crc32 is always built)")
272 foreach(CHECK IN LISTS ADDITIONAL_CHECK_TYPES)
273 if(NOT CHECK IN_LIST ADDITIONAL_SUPPORTED_CHECKS)
274 message(SEND_ERROR "'${CHECK}' is not a supported check type")
279 target_sources(liblzma PRIVATE src/liblzma/check/crc32_small.c)
281 target_sources(liblzma PRIVATE
282 src/liblzma/check/crc32_fast.c
283 src/liblzma/check/crc32_table.c
284 src/liblzma/check/crc32_table_be.h
285 src/liblzma/check/crc32_table_le.h
289 if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES)
290 add_compile_definitions("HAVE_CHECK_CRC64")
293 target_sources(liblzma PRIVATE src/liblzma/check/crc64_small.c)
295 target_sources(liblzma PRIVATE
296 src/liblzma/check/crc64_fast.c
297 src/liblzma/check/crc64_table.c
298 src/liblzma/check/crc64_table_be.h
299 src/liblzma/check/crc64_table_le.h
304 if("sha256" IN_LIST ADDITIONAL_CHECK_TYPES)
305 add_compile_definitions("HAVE_CHECK_SHA256")
306 target_sources(liblzma PRIVATE src/liblzma/check/sha256.c)
314 set(SUPPORTED_MATCH_FINDERS hc3 hc4 bt2 bt3 bt4)
316 set(MATCH_FINDERS "${SUPPORTED_MATCH_FINDERS}" CACHE STRING
317 "Match finders to support (at least one is required for LZMA1 or LZMA2)")
319 foreach(MF IN LISTS MATCH_FINDERS)
320 if(MF IN_LIST SUPPORTED_MATCH_FINDERS)
321 string(TOUPPER "${MF}" MF_UPPER)
322 add_compile_definitions("HAVE_MF_${MF_UPPER}")
324 message(SEND_ERROR "'${MF}' is not a supported match finder")
333 # Supported thread methods:
334 # ON - autodetect the best threading method. The autodetection will
335 # prefer Windows threading (win95 or vista) over posix if both are
336 # available. vista threads will be used over win95 unless it is a
338 # OFF - Disable threading.
339 # posix - Use posix threading, or throw an error if not available.
340 # win95 - Use Windows win95 threading, or throw an error if not available.
341 # vista - Use Windows vista threading, or throw an error if not available.
342 set(SUPPORTED_THREAD_METHODS ON OFF posix win95 vista)
344 set(ENABLE_THREADS ON CACHE STRING
345 "Threading method type to support. Set to 'OFF' to disable threading")
347 # Create dropdown in CMake GUI since only 1 threading method is possible
348 # to select in a build.
349 set_property(CACHE ENABLE_THREADS
350 PROPERTY STRINGS "${SUPPORTED_THREAD_METHODS}")
352 # This is a flag variable set when win95 threads are used. We must ensure
353 # the combination of enable_small and win95 threads is not used without a
354 # compiler supporting attribute __constructor__.
355 set(USE_WIN95_THREADS OFF)
357 if(NOT ENABLE_THREADS IN_LIST SUPPORTED_THREAD_METHODS)
358 message(SEND_ERROR "'${ENABLE_THREADS}' is not a supported thread type")
362 # Also set THREADS_PREFER_PTHREAD_FLAG since the flag has no effect
363 # for Windows threading.
364 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
365 find_package(Threads REQUIRED)
367 # If both Windows and posix threading are available, prefer Windows.
368 # Note that on Cygwin CMAKE_USE_WIN32_THREADS_INIT is false.
369 if(CMAKE_USE_WIN32_THREADS_INIT AND NOT ENABLE_THREADS STREQUAL "posix")
370 if(ENABLE_THREADS STREQUAL "win95"
371 OR (ENABLE_THREADS STREQUAL "ON"
372 AND CMAKE_SIZEOF_VOID_P EQUAL 4))
373 # Use Windows 95 (and thus XP) compatible threads.
374 # This avoids use of features that were added in
375 # Windows Vista. This is used for 32-bit x86 builds for
376 # compatibility reasons since it makes no measurable difference
377 # in performance compared to Vista threads.
378 set(USE_WIN95_THREADS ON)
379 add_compile_definitions(MYTHREAD_WIN95)
381 add_compile_definitions(MYTHREAD_VISTA)
383 elseif(CMAKE_USE_PTHREADS_INIT)
384 if(ENABLE_THREADS STREQUAL "posix" OR ENABLE_THREADS STREQUAL "ON")
385 # Overwrite ENABLE_THREADS in case it was set to "ON".
386 # The threading library only needs to be explicitly linked
387 # for posix threads, so this is needed for creating
388 # liblzma-config.cmake later.
389 set(ENABLE_THREADS "posix")
391 target_link_libraries(liblzma Threads::Threads)
392 add_compile_definitions(MYTHREAD_POSIX)
394 # Check if pthread_condattr_setclock() exists to
395 # use CLOCK_MONOTONIC.
396 if(HAVE_CLOCK_MONOTONIC)
397 list(INSERT CMAKE_REQUIRED_LIBRARIES 0
398 "${CMAKE_THREAD_LIBS_INIT}")
399 check_symbol_exists(pthread_condattr_setclock pthread.h
400 HAVE_PTHREAD_CONDATTR_SETCLOCK)
401 tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK)
405 "Windows thread method requested, but a compatible "
406 "library could not be found")
409 message(SEND_ERROR "No supported threading library found")
412 target_sources(liblzma PRIVATE
413 src/common/tuklib_cpucores.c
414 src/common/tuklib_cpucores.h
415 src/liblzma/common/hardware_cputhreads.c
416 src/liblzma/common/outqueue.c
417 src/liblzma/common/outqueue.h
436 # The SUPPORTED_FILTERS are shared between Encoders and Decoders
437 # since only lzip does not appear in both lists. lzip is a special
438 # case anyway, so it is handled separately in the Decoders section.
439 set(SUPPORTED_FILTERS
446 set(ENCODERS "${SUPPORTED_FILTERS}" CACHE STRING "Encoders to support")
448 # If LZMA2 is enabled, then LZMA1 must also be enabled.
449 if(NOT "lzma1" IN_LIST ENCODERS AND "lzma2" IN_LIST ENCODERS)
450 message(SEND_ERROR "LZMA2 encoder requires that LZMA1 is also enabled")
453 # If LZMA1 is enabled, then at least one match finder must be enabled.
454 if(MATCH_FINDERS STREQUAL "" AND "lzma1" IN_LIST ENCODERS)
455 message(SEND_ERROR "At least 1 match finder is required for an "
459 set(HAVE_DELTA_CODER OFF)
460 set(SIMPLE_ENCODERS OFF)
461 set(HAVE_ENCODERS OFF)
463 foreach(ENCODER IN LISTS ENCODERS)
464 if(ENCODER IN_LIST SUPPORTED_FILTERS)
465 set(HAVE_ENCODERS ON)
467 if(NOT SIMPLE_ENCODERS AND ENCODER IN_LIST SIMPLE_FILTERS)
468 set(SIMPLE_ENCODERS ON)
471 string(TOUPPER "${ENCODER}" ENCODER_UPPER)
472 add_compile_definitions("HAVE_ENCODER_${ENCODER_UPPER}")
474 message(SEND_ERROR "'${ENCODER}' is not a supported encoder")
479 add_compile_definitions(HAVE_ENCODERS)
481 target_sources(liblzma PRIVATE
482 src/liblzma/common/alone_encoder.c
483 src/liblzma/common/block_buffer_encoder.c
484 src/liblzma/common/block_buffer_encoder.h
485 src/liblzma/common/block_encoder.c
486 src/liblzma/common/block_encoder.h
487 src/liblzma/common/block_header_encoder.c
488 src/liblzma/common/easy_buffer_encoder.c
489 src/liblzma/common/easy_encoder.c
490 src/liblzma/common/easy_encoder_memusage.c
491 src/liblzma/common/filter_buffer_encoder.c
492 src/liblzma/common/filter_encoder.c
493 src/liblzma/common/filter_encoder.h
494 src/liblzma/common/filter_flags_encoder.c
495 src/liblzma/common/index_encoder.c
496 src/liblzma/common/index_encoder.h
497 src/liblzma/common/stream_buffer_encoder.c
498 src/liblzma/common/stream_encoder.c
499 src/liblzma/common/stream_flags_encoder.c
500 src/liblzma/common/vli_encoder.c
504 target_sources(liblzma PRIVATE
505 src/liblzma/common/stream_encoder_mt.c
510 target_sources(liblzma PRIVATE
511 src/liblzma/simple/simple_encoder.c
512 src/liblzma/simple/simple_encoder.h
516 if("lzma1" IN_LIST ENCODERS)
517 target_sources(liblzma PRIVATE
518 src/liblzma/lzma/lzma_encoder.c
519 src/liblzma/lzma/lzma_encoder.h
520 src/liblzma/lzma/lzma_encoder_optimum_fast.c
521 src/liblzma/lzma/lzma_encoder_optimum_normal.c
522 src/liblzma/lzma/lzma_encoder_private.h
523 src/liblzma/lzma/fastpos.h
524 src/liblzma/lz/lz_encoder.c
525 src/liblzma/lz/lz_encoder.h
526 src/liblzma/lz/lz_encoder_hash.h
527 src/liblzma/lz/lz_encoder_hash_table.h
528 src/liblzma/lz/lz_encoder_mf.c
529 src/liblzma/rangecoder/price.h
530 src/liblzma/rangecoder/price_table.c
531 src/liblzma/rangecoder/range_encoder.h
535 target_sources(liblzma PRIVATE src/liblzma/lzma/fastpos_table.c)
539 if("lzma2" IN_LIST ENCODERS)
540 target_sources(liblzma PRIVATE
541 src/liblzma/lzma/lzma2_encoder.c
542 src/liblzma/lzma/lzma2_encoder.h
546 if("delta" IN_LIST ENCODERS)
547 set(HAVE_DELTA_CODER ON)
548 target_sources(liblzma PRIVATE
549 src/liblzma/delta/delta_encoder.c
550 src/liblzma/delta/delta_encoder.h
560 set(DECODERS "${SUPPORTED_FILTERS}" CACHE STRING "Decoders to support")
562 set(SIMPLE_DECODERS OFF)
563 set(HAVE_DECODERS OFF)
565 foreach(DECODER IN LISTS DECODERS)
566 if(DECODER IN_LIST SUPPORTED_FILTERS)
567 set(HAVE_DECODERS ON)
569 if(NOT SIMPLE_DECODERS AND DECODER IN_LIST SIMPLE_FILTERS)
570 set(SIMPLE_DECODERS ON)
573 string(TOUPPER "${DECODER}" DECODER_UPPER)
574 add_compile_definitions("HAVE_DECODER_${DECODER_UPPER}")
576 message(SEND_ERROR "'${DECODER}' is not a supported decoder")
581 add_compile_definitions(HAVE_DECODERS)
583 target_sources(liblzma PRIVATE
584 src/liblzma/common/alone_decoder.c
585 src/liblzma/common/alone_decoder.h
586 src/liblzma/common/auto_decoder.c
587 src/liblzma/common/block_buffer_decoder.c
588 src/liblzma/common/block_decoder.c
589 src/liblzma/common/block_decoder.h
590 src/liblzma/common/block_header_decoder.c
591 src/liblzma/common/easy_decoder_memusage.c
592 src/liblzma/common/file_info.c
593 src/liblzma/common/filter_buffer_decoder.c
594 src/liblzma/common/filter_decoder.c
595 src/liblzma/common/filter_decoder.h
596 src/liblzma/common/filter_flags_decoder.c
597 src/liblzma/common/index_decoder.c
598 src/liblzma/common/index_decoder.h
599 src/liblzma/common/index_hash.c
600 src/liblzma/common/stream_buffer_decoder.c
601 src/liblzma/common/stream_decoder.c
602 src/liblzma/common/stream_flags_decoder.c
603 src/liblzma/common/stream_decoder.h
604 src/liblzma/common/vli_decoder.c
608 target_sources(liblzma PRIVATE
609 src/liblzma/common/stream_decoder_mt.c
614 target_sources(liblzma PRIVATE
615 src/liblzma/simple/simple_decoder.c
616 src/liblzma/simple/simple_decoder.h
620 if("lzma1" IN_LIST DECODERS)
621 target_sources(liblzma PRIVATE
622 src/liblzma/lzma/lzma_decoder.c
623 src/liblzma/lzma/lzma_decoder.h
624 src/liblzma/rangecoder/range_decoder.h
625 src/liblzma/lz/lz_decoder.c
626 src/liblzma/lz/lz_decoder.h
630 if("lzma2" IN_LIST DECODERS)
631 target_sources(liblzma PRIVATE
632 src/liblzma/lzma/lzma2_decoder.c
633 src/liblzma/lzma/lzma2_decoder.h
637 if("delta" IN_LIST DECODERS)
638 set(HAVE_DELTA_CODER ON)
639 target_sources(liblzma PRIVATE
640 src/liblzma/delta/delta_decoder.c
641 src/liblzma/delta/delta_decoder.h
646 # Some sources must appear if the filter is configured as either
647 # an encoder or decoder.
648 if("lzma1" IN_LIST ENCODERS OR "lzma1" IN_LIST DECODERS)
649 target_sources(liblzma PRIVATE
650 src/liblzma/rangecoder/range_common.h
651 src/liblzma/lzma/lzma_encoder_presets.c
652 src/liblzma/lzma/lzma_common.h
657 target_sources(liblzma PRIVATE
658 src/liblzma/delta/delta_common.c
659 src/liblzma/delta/delta_common.h
660 src/liblzma/delta/delta_private.h
664 if(SIMPLE_ENCODERS OR SIMPLE_DECODERS)
665 target_sources(liblzma PRIVATE
666 src/liblzma/simple/simple_coder.c
667 src/liblzma/simple/simple_coder.h
668 src/liblzma/simple/simple_private.h
672 foreach(SIMPLE_CODER IN LISTS SIMPLE_FILTERS)
673 if(SIMPLE_CODER IN_LIST ENCODERS OR SIMPLE_CODER IN_LIST DECODERS)
674 target_sources(liblzma PRIVATE "src/liblzma/simple/${SIMPLE_CODER}.c")
683 option(MICROLZMA_ENCODER
684 "MicroLZMA encoder (needed by specific applications only)" ON)
686 option(MICROLZMA_DECODER
687 "MicroLZMA decoder (needed by specific applications only)" ON)
689 if(MICROLZMA_ENCODER)
690 if(NOT "lzma1" IN_LIST ENCODERS)
691 message(SEND_ERROR "The LZMA1 encoder is required to support the "
695 target_sources(liblzma PRIVATE src/liblzma/common/microlzma_encoder.c)
698 if(MICROLZMA_DECODER)
699 if(NOT "lzma1" IN_LIST DECODERS)
700 message(SEND_ERROR "The LZMA1 decoder is required to support the "
704 target_sources(liblzma PRIVATE src/liblzma/common/microlzma_decoder.c)
708 #############################
709 # lzip (.lz) format support #
710 #############################
712 option(LZIP_DECODER "Support lzip decoder" ON)
715 # If lzip decoder support is requested, make sure LZMA1 decoder is enabled.
716 if(NOT "lzma1" IN_LIST DECODERS)
717 message(SEND_ERROR "The LZMA1 decoder is required to support the "
721 add_compile_definitions(HAVE_LZIP_DECODER)
723 target_sources(liblzma PRIVATE
724 src/liblzma/common/lzip_decoder.c
725 src/liblzma/common/lzip_decoder.h
731 # Put the tuklib functions under the lzma_ namespace.
732 target_compile_definitions(liblzma PRIVATE TUKLIB_SYMBOL_PREFIX=lzma_)
733 tuklib_cpucores(liblzma)
734 tuklib_physmem(liblzma)
736 # While liblzma can be built without tuklib_cpucores or tuklib_physmem
737 # modules, the liblzma API functions lzma_cputhreads() and lzma_physmem()
738 # will then be useless (which isn't too bad but still unfortunate). Since
739 # I expect the CMake-based builds to be only used on systems that are
740 # supported by these tuklib modules, problems with these tuklib modules
741 # are considered a hard error for now. This hopefully helps to catch bugs
742 # in the CMake versions of the tuklib checks.
743 if(NOT TUKLIB_CPUCORES_FOUND OR NOT TUKLIB_PHYSMEM_FOUND)
744 # Use SEND_ERROR instead of FATAL_ERROR. If someone reports a bug,
745 # seeing the results of the remaining checks can be useful too.
747 "tuklib_cpucores() or tuklib_physmem() failed. "
748 "Unless you really are building for a system where these "
749 "modules are not supported (unlikely), this is a bug in the "
750 "included cmake/tuklib_*.cmake files that should be fixed. "
751 "To build anyway, edit this CMakeLists.txt to ignore this error.")
754 # Check for __attribute__((__constructor__)) support.
755 # This needs -Werror because some compilers just warn
756 # about this being unsupported.
757 cmake_push_check_state()
758 set(CMAKE_REQUIRED_FLAGS "-Werror")
759 check_c_source_compiles("
760 __attribute__((__constructor__))
761 static void my_constructor_func(void) { return; }
762 int main(void) { return 0; }
764 HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
765 cmake_pop_check_state()
766 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
768 # The Win95 threading lacks a thread-safe one-time initialization function.
769 # The one-time initialization is needed for crc32_small.c and crc64_small.c
770 # create the CRC tables. So if small mode is enabled, the threading mode is
771 # win95, and the compiler does not support attribute constructor, then we
772 # would end up with a multithreaded build that is thread-unsafe. As a
773 # result this configuration is not allowed.
774 if(USE_WIN95_THREADS AND ENABLE_SMALL AND NOT HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
775 message(SEND_ERROR "Threading method win95 and ENABLE_SMALL "
776 "cannot be used at the same time with a compiler "
777 "that doesn't support "
778 "__attribute__((__constructor__))")
782 # Check for __attribute__((__ifunc__())) support.
783 option(ALLOW_ATTR_IFUNC "Allow use of __attribute__((__ifunc__())) if \
784 supported by the system" ON)
787 cmake_push_check_state()
788 set(CMAKE_REQUIRED_FLAGS "-Werror")
789 check_c_source_compiles("
790 static void func(void) { return; }
791 static void (*resolve_func(void)) (void) { return func; }
792 void func_ifunc(void)
793 __attribute__((__ifunc__(\"resolve_func\")));
794 int main(void) { return 0; }
796 * 'clang -Wall' incorrectly warns that resolve_func is
797 * unused (-Wunused-function). Correct assembly output is
798 * still produced. This problem exists at least in Clang
799 * versions 4 to 17. The following silences the bogus warning:
801 void make_clang_quiet(void);
802 void make_clang_quiet(void) { resolve_func()(); }
804 HAVE_FUNC_ATTRIBUTE_IFUNC)
805 cmake_pop_check_state()
806 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_IFUNC)
810 check_include_file(cpuid.h HAVE_CPUID_H)
811 tuklib_add_definition_if(liblzma HAVE_CPUID_H)
814 check_include_file(immintrin.h HAVE_IMMINTRIN_H)
816 target_compile_definitions(liblzma PRIVATE HAVE_IMMINTRIN_H)
819 check_c_source_compiles("
820 #include <immintrin.h>
824 _mm_movemask_epi8(x);
828 HAVE__MM_MOVEMASK_EPI8)
829 tuklib_add_definition_if(liblzma HAVE__MM_MOVEMASK_EPI8)
832 check_c_source_compiles("
833 #include <immintrin.h>
834 #if defined(__e2k__) && __iset__ < 6
837 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
838 __attribute__((__target__(\"ssse3,sse4.1,pclmul\")))
840 __m128i my_clmul(__m128i a)
842 const __m128i b = _mm_set_epi64x(1, 2);
843 return _mm_clmulepi64_si128(a, b, 0);
845 int main(void) { return 0; }
848 tuklib_add_definition_if(liblzma HAVE_USABLE_CLMUL)
851 # Support -fvisiblity=hidden when building shared liblzma.
852 # These lines do nothing on Windows (even under Cygwin).
853 # HAVE_VISIBILITY should always be defined to 0 or 1.
854 if(BUILD_SHARED_LIBS)
855 set_target_properties(liblzma PROPERTIES C_VISIBILITY_PRESET hidden)
856 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=1)
858 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=0)
862 if(BUILD_SHARED_LIBS)
863 # Add the Windows resource file for liblzma.dll.
864 target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc)
866 set_target_properties(liblzma PROPERTIES
867 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
870 # Export the public API symbols with __declspec(dllexport).
871 target_compile_definitions(liblzma PRIVATE DLL_EXPORT)
873 # Disable __declspec(dllimport) when linking against static liblzma.
874 target_compile_definitions(liblzma INTERFACE LZMA_API_STATIC)
876 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
877 # GNU/Linux-specific symbol versioning for shared liblzma.
878 # Note that adding link options doesn't affect static builds
879 # but HAVE_SYMBOL_VERSIONS_LINUX must not be used with static builds
880 # because it would put symbol versions into the static library which
881 # can cause problems. It's clearer if all symver related things are
882 # omitted when not building a shared library.
884 # NOTE: Set it explicitly to 1 to make it clear that versioning is
885 # done unconditionally in the C files.
886 target_compile_definitions(liblzma PRIVATE HAVE_SYMBOL_VERSIONS_LINUX=1)
887 target_link_options(liblzma PRIVATE
888 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
890 set_target_properties(liblzma PROPERTIES
891 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
893 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
894 # Symbol versioning for shared liblzma for non-GNU/Linux.
895 # FIXME? What about Solaris?
896 target_link_options(liblzma PRIVATE
897 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
899 set_target_properties(liblzma PROPERTIES
900 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
904 set_target_properties(liblzma PROPERTIES
905 # At least for now the package versioning matches the rules used for
906 # shared library versioning (excluding development releases) so it is
907 # fine to use the package version here.
908 SOVERSION "${xz_VERSION_MAJOR}"
909 VERSION "${xz_VERSION}"
911 # It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll.
912 # Avoid the name lzma.dll because it would conflict with LZMA SDK.
916 # Create liblzma-config-version.cmake.
918 # FIXME: SameMajorVersion is correct for stable releases but it is wrong
919 # for development releases where each release may have incompatible changes.
920 include(CMakePackageConfigHelpers)
921 write_basic_package_version_file(
922 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
923 VERSION "${liblzma_VERSION}"
924 COMPATIBILITY SameMajorVersion)
926 # Create liblzma-config.cmake. We use this spelling instead of
927 # liblzmaConfig.cmake to make find_package work in case insensitive
928 # manner even with case sensitive file systems. This gives more consistent
929 # behavior between operating systems. This optionally includes a dependency
930 # on a threading library, so the contents are created in two separate parts.
931 # The "second half" is always needed, so create it first.
932 set(LZMA_CONFIG_CONTENTS
933 "include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
935 if(NOT TARGET LibLZMA::LibLZMA)
936 # Be compatible with the spelling used by the FindLibLZMA module. This
937 # doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA
938 # to liblzma::liblzma instead of keeping the original spelling. Keeping
939 # the original spelling is important for good FindLibLZMA compatibility.
940 add_library(LibLZMA::LibLZMA INTERFACE IMPORTED)
941 set_target_properties(LibLZMA::LibLZMA PROPERTIES
942 INTERFACE_LINK_LIBRARIES liblzma::liblzma)
946 if(ENABLE_THREADS STREQUAL "posix")
947 set(LZMA_CONFIG_CONTENTS
948 "include(CMakeFindDependencyMacro)
949 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
950 find_dependency(Threads)
952 ${LZMA_CONFIG_CONTENTS}
956 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
957 "${LZMA_CONFIG_CONTENTS}")
959 # Set CMAKE_INSTALL_LIBDIR and friends.
960 include(GNUInstallDirs)
962 # Install the library binary. The INCLUDES specifies the include path that
963 # is exported for other projects to use but it doesn't install any files.
964 install(TARGETS liblzma EXPORT liblzmaTargets
965 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
966 COMPONENT liblzma_Runtime
967 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
968 COMPONENT liblzma_Runtime
969 NAMELINK_COMPONENT liblzma_Development
970 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
971 COMPONENT liblzma_Development
972 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
974 # Install the liblzma API headers. These use a subdirectory so
975 # this has to be done as a separate step.
976 install(DIRECTORY src/liblzma/api/
977 COMPONENT liblzma_Development
978 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
979 FILES_MATCHING PATTERN "*.h")
981 # Install the CMake files that other packages can use to find liblzma.
982 set(liblzma_INSTALL_CMAKEDIR
983 "${CMAKE_INSTALL_LIBDIR}/cmake/liblzma"
984 CACHE STRING "Path to liblzma's .cmake files")
986 install(EXPORT liblzmaTargets
988 FILE liblzma-targets.cmake
989 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
990 COMPONENT liblzma_Development)
992 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
993 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
994 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
995 COMPONENT liblzma_Development)
998 #############################################################################
999 # libgnu (getopt_long)
1000 #############################################################################
1002 # This mirrors how the Autotools build system handles the getopt_long
1003 # replacement, calling the object library libgnu since the replacement
1004 # version comes from Gnulib.
1005 add_library(libgnu OBJECT)
1007 # CMake requires that even an object library must have at least once source
1008 # file. So we give it a header file that results in no output files.
1009 target_sources(libgnu PRIVATE lib/getopt.in.h)
1011 # Create /lib directory in the build directory and add it to the include path.
1012 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
1013 target_include_directories(libgnu PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib")
1015 # Include /lib from the source directory. It does no harm even if none of
1016 # the Gnulib replacements are used.
1017 target_include_directories(libgnu PUBLIC lib)
1019 # The command line tools need getopt_long in order to parse arguments. If
1020 # the system does not have a getopt_long implementation we can use the one
1021 # from Gnulib instead.
1022 check_symbol_exists(getopt_long getopt.h HAVE_GETOPT_LONG)
1024 if(NOT HAVE_GETOPT_LONG)
1025 # Set the __GETOPT_PREFIX definition to "rpl_" (replacement) to avoid
1026 # name conflicts with libc symbols. The same prefix is set if using
1027 # the Autotools build (m4/getopt.m4).
1028 target_compile_definitions(libgnu PUBLIC "__GETOPT_PREFIX=rpl_")
1030 # Create a custom copy command to copy the getopt header to the build
1031 # directory and re-copy it if it is updated. (Gnulib does it this way
1032 # because it allows choosing which .in.h files to actually use in the
1033 # build. We need just getopt.h so this is a bit overcomplicated for
1034 # a single header file only.)
1035 add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1036 COMMAND "${CMAKE_COMMAND}" -E copy
1037 "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
1038 "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1039 MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
1042 target_sources(libgnu PRIVATE
1049 lib/getopt-pfx-core.h
1050 lib/getopt-pfx-ext.h
1051 "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1056 #############################################################################
1058 #############################################################################
1060 if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
1061 add_executable(xzdec
1062 src/common/sysdefs.h
1063 src/common/tuklib_common.h
1064 src/common/tuklib_config.h
1065 src/common/tuklib_exit.c
1066 src/common/tuklib_exit.h
1067 src/common/tuklib_gettext.h
1068 src/common/tuklib_progname.c
1069 src/common/tuklib_progname.h
1073 target_include_directories(xzdec PRIVATE
1078 target_link_libraries(xzdec PRIVATE liblzma libgnu)
1081 # Add the Windows resource file for xzdec.exe.
1082 target_sources(xzdec PRIVATE src/xzdec/xzdec_w32res.rc)
1083 set_target_properties(xzdec PROPERTIES
1084 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
1088 tuklib_progname(xzdec)
1090 install(TARGETS xzdec
1091 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
1095 install(FILES src/xzdec/xzdec.1
1096 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1102 #############################################################################
1104 #############################################################################
1106 if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900)
1108 src/common/mythread.h
1109 src/common/sysdefs.h
1110 src/common/tuklib_common.h
1111 src/common/tuklib_config.h
1112 src/common/tuklib_exit.c
1113 src/common/tuklib_exit.h
1114 src/common/tuklib_gettext.h
1115 src/common/tuklib_integer.h
1116 src/common/tuklib_mbstr.h
1117 src/common/tuklib_mbstr_fw.c
1118 src/common/tuklib_mbstr_width.c
1119 src/common/tuklib_open_stdxxx.c
1120 src/common/tuklib_open_stdxxx.h
1121 src/common/tuklib_progname.c
1122 src/common/tuklib_progname.h
1148 target_include_directories(xz PRIVATE
1154 target_sources(xz PRIVATE
1160 target_link_libraries(xz PRIVATE liblzma libgnu)
1162 target_compile_definitions(xz PRIVATE ASSUME_RAM=128)
1165 # Add the Windows resource file for xz.exe.
1166 target_sources(xz PRIVATE src/xz/xz_w32res.rc)
1167 set_target_properties(xz PROPERTIES
1168 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
1175 check_symbol_exists(optreset getopt.h HAVE_OPTRESET)
1176 tuklib_add_definition_if(xz HAVE_OPTRESET)
1178 check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
1179 tuklib_add_definition_if(xz HAVE_POSIX_FADVISE)
1181 # How to get file time:
1182 check_struct_has_member("struct stat" st_atim.tv_nsec
1183 "sys/types.h;sys/stat.h"
1184 HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1185 if(HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1186 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1188 check_struct_has_member("struct stat" st_atimespec.tv_nsec
1189 "sys/types.h;sys/stat.h"
1190 HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1191 if(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1192 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1194 check_struct_has_member("struct stat" st_atimensec
1195 "sys/types.h;sys/stat.h"
1196 HAVE_STRUCT_STAT_ST_ATIMENSEC)
1197 tuklib_add_definition_if(xz HAVE_STRUCT_STAT_ST_ATIMENSEC)
1201 # How to set file time:
1202 check_symbol_exists(futimens "sys/types.h;sys/stat.h" HAVE_FUTIMENS)
1204 tuklib_add_definitions(xz HAVE_FUTIMENS)
1206 check_symbol_exists(futimes "sys/time.h" HAVE_FUTIMES)
1208 tuklib_add_definitions(xz HAVE_FUTIMES)
1210 check_symbol_exists(futimesat "sys/time.h" HAVE_FUTIMESAT)
1212 tuklib_add_definitions(xz HAVE_FUTIMESAT)
1214 check_symbol_exists(utimes "sys/time.h" HAVE_UTIMES)
1216 tuklib_add_definitions(xz HAVE_UTIMES)
1218 check_symbol_exists(_futime "sys/utime.h" HAVE__FUTIME)
1220 tuklib_add_definitions(xz HAVE__FUTIME)
1222 check_symbol_exists(utime "utime.h" HAVE_UTIME)
1223 tuklib_add_definition_if(xz HAVE_UTIME)
1231 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
1235 install(FILES src/xz/xz.1
1236 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1239 option(CREATE_XZ_SYMLINKS "Create unxz and xzcat symlinks" ON)
1240 option(CREATE_LZMA_SYMLINKS "Create lzma, unlzma, and lzcat symlinks"
1244 if(CREATE_XZ_SYMLINKS)
1245 list(APPEND XZ_LINKS "unxz" "xzcat")
1248 if(CREATE_LZMA_SYMLINKS)
1249 list(APPEND XZ_LINKS "lzma" "unlzma" "lzcat")
1252 # With Windows Cygwin and MSYS2 the symlinking is complicated. Both
1253 # of these environments set the UNIX variable so they will try to
1254 # make the symlinks. The ability for Cygwin and MSYS2 to make
1255 # broken symlinks is determined by the CYGWIN and MSYS2 environment
1256 # variables, respectively. Broken symlinks are needed for the man
1257 # page symlinks and for determining if the xz and lzma symlinks need
1258 # to depend on the xz target or not. If broken symlinks cannot be
1259 # made then the xz binary must be created before the symlinks.
1260 set(ALLOW_BROKEN_SYMLINKS ON)
1262 if(CMAKE_SYSTEM_NAME STREQUAL "CYGWIN")
1263 # The Cygwin env variable can be set to four possible values:
1265 # 1. "lnk". Create symlinks as Windows shortcuts.
1267 # 2. "native". Create symlinks as native Windows symlinks
1268 # if supported by the system. Fallback to "lnk" if native
1269 # symlinks are not supported.
1271 # 3. "nativestrict". Create symlinks as native Windows symlinks
1272 # if supported by the system. If the target of the symlink
1273 # does not exist or the creation of the symlink fails for any
1274 # reason, do not create the symlink.
1276 # 4. "sys". Create symlinks as plain files with a special
1277 # system attribute containing the path to the symlink target.
1279 # So, the only case we care about for broken symlinks is
1280 # "nativestrict" since all other values mean that broken
1281 # symlinks are allowed. If the env variable is not set the
1282 # default is "native". If the env variable is set but not
1283 # assigned one of the four values, then the default is the same
1284 # as option 1 "lnk".
1285 string(FIND "$ENV{CYGWIN}" "winsymlinks:nativestrict" SYMLINK_POS)
1286 if(SYMLINK_POS GREATER -1)
1287 set(ALLOW_BROKEN_SYMLINKS OFF)
1289 elseif(CMAKE_SYSTEM_NAME STREQUAL "MSYS")
1290 # The MSYS env variable behaves similar to the CYGWIN but has a
1291 # different default behavior. If winsymlinks is set but not
1292 # assigned one of the four supported values, the default is to
1293 # *copy* the target to the symlink destination. This will fail
1294 # if the target does not exist so broken symlinks cannot be
1296 string(FIND "$ENV{MSYS}" "winsymlinks" SYMLINK_POS)
1297 if(SYMLINK_POS GREATER -1)
1298 string(FIND "$ENV{MSYS}" "winsymlinks:nativestrict"
1300 if(SYMLINK_POS GREATER -1)
1301 set(ALLOW_BROKEN_SYMLINKS OFF)
1304 set(ALLOW_BROKEN_SYMLINKS OFF)
1308 # Create symlinks in the build directory and then install them.
1310 # The symlinks do not likely need any special extension since
1311 # even on Windows the symlink can still be executed without
1312 # the .exe extension.
1313 foreach(LINK IN LISTS XZ_LINKS)
1314 add_custom_target("${LINK}" ALL
1315 "${CMAKE_COMMAND}" -E create_symlink
1316 "$<TARGET_FILE_NAME:xz>" "${LINK}"
1317 BYPRODUCTS "${LINK}"
1319 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}"
1320 DESTINATION "${CMAKE_INSTALL_BINDIR}"
1323 # Only create the man page symlinks if the symlinks can be
1324 # created broken. The symlinks will not be valid until install
1325 # so they cannot be created on these system environments.
1326 if(ALLOW_BROKEN_SYMLINKS)
1327 add_custom_target("${LINK}.1" ALL
1328 "${CMAKE_COMMAND}" -E create_symlink "xz.1" "${LINK}.1"
1329 BYPRODUCTS "${LINK}.1"
1331 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}.1"
1332 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1335 # Add the xz target as dependency when broken symlinks
1336 # cannot be made. This ensures parallel builds do not fail
1337 # since it will enforce the order of creating xz first, then
1339 add_dependencies("${LINK}" xz)
1346 #############################################################################
1348 #############################################################################
1368 foreach(TEST IN LISTS LIBLZMA_TESTS)
1369 add_executable("${TEST}" "tests/${TEST}.c")
1371 target_include_directories("${TEST}" PRIVATE
1377 target_link_libraries("${TEST}" PRIVATE liblzma)
1379 # Put the test programs into their own subdirectory so they don't
1380 # pollute the top-level dir which might contain xz and xzdec.
1381 set_target_properties("${TEST}" PROPERTIES
1382 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests_bin"
1385 add_test(NAME "${TEST}"
1386 COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tests_bin/${TEST}"
1389 # Set srcdir environment variable so that the tests find their
1390 # input files from the source tree.
1392 # Set the return code for skipped tests to match Automake convention.
1393 set_tests_properties("${TEST}" PROPERTIES
1394 ENVIRONMENT "srcdir=${CMAKE_CURRENT_LIST_DIR}/tests"