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 claims to be compatible with GNU windres but with that
97 # the \x20 results in "XZx20Utils" in the compiled binary. (At the
98 # same time it works correctly with clang (the C compiler).) The option
99 # --use-temp-file makes no difference.
101 # CMake 3.25 doesn't have CMAKE_RC_COMPILER_ID so we rely on
102 # CMAKE_C_COMPILER_ID. If Clang is used together with GNU windres
103 # then it will fail, but this way the risk of a bad string in
104 # the binary should be fairly low.
105 if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
106 # Use workarounds with GNU windres. The \x20 in PACKAGE_NAME works
107 # with gcc too so we don't need to worry how to pass different flags
108 # to windres and gcc.
109 string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
110 set(PACKAGE_NAME "XZ\\x20Utils")
112 # Elsewhere a space is safe. This also keeps things compatible with
113 # EBCDIC in case CMake-based build is ever done on such a system.
114 set(PACKAGE_NAME "XZ Utils")
117 # Definitions common to all targets:
118 add_compile_definitions(
120 PACKAGE_NAME="${PACKAGE_NAME}"
121 PACKAGE_BUGREPORT="xz@tukaani.org"
122 PACKAGE_URL="https://tukaani.org/xz/"
124 # Standard headers and types are available:
130 # Always enable CRC32 since liblzma should never build without it.
133 # Disable assert() checks when no build type has been specified. Non-empty
134 # build types like "Release" and "Debug" handle this by default.
139 ######################
140 # System definitions #
141 ######################
143 # _GNU_SOURCE and such definitions. This specific macro is special since
144 # it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS.
145 tuklib_use_system_extensions(ALL)
147 # This is needed by liblzma and xz.
150 # Check for clock_gettime(). Do this before checking for threading so
151 # that we know there if CLOCK_MONOTONIC is available.
153 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
155 if(NOT HAVE_CLOCK_GETTIME)
156 # With glibc <= 2.17 or Solaris 10 this needs librt.
157 # Add librt for the next check for HAVE_CLOCK_GETTIME. If it is
158 # found after including the library, we know that librt is required.
159 list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt)
160 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME_LIBRT)
162 # If it was found now, add librt to all targets and keep it in
163 # CMAKE_REQUIRED_LIBRARIES for further tests too.
164 if(HAVE_CLOCK_GETTIME_LIBRT)
167 list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
171 if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_LIBRT)
172 add_compile_definitions(HAVE_CLOCK_GETTIME)
174 # Check if CLOCK_MONOTONIC is available for clock_gettime().
175 check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
176 tuklib_add_definition_if(ALL HAVE_CLOCK_MONOTONIC)
180 # Options for new enough GCC or Clang on any arch or operating system:
181 if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
182 # configure.ac has a long list but it won't be copied here:
183 add_compile_options(-Wall -Wextra)
187 #############################################################################
189 #############################################################################
191 option(BUILD_SHARED_LIBS "Build liblzma as a shared library instead of static")
194 src/common/mythread.h
196 src/common/tuklib_common.h
197 src/common/tuklib_config.h
198 src/common/tuklib_integer.h
199 src/common/tuklib_physmem.c
200 src/common/tuklib_physmem.h
201 src/liblzma/api/lzma.h
202 src/liblzma/api/lzma/base.h
203 src/liblzma/api/lzma/bcj.h
204 src/liblzma/api/lzma/block.h
205 src/liblzma/api/lzma/check.h
206 src/liblzma/api/lzma/container.h
207 src/liblzma/api/lzma/delta.h
208 src/liblzma/api/lzma/filter.h
209 src/liblzma/api/lzma/hardware.h
210 src/liblzma/api/lzma/index.h
211 src/liblzma/api/lzma/index_hash.h
212 src/liblzma/api/lzma/lzma12.h
213 src/liblzma/api/lzma/stream_flags.h
214 src/liblzma/api/lzma/version.h
215 src/liblzma/api/lzma/vli.h
216 src/liblzma/check/check.c
217 src/liblzma/check/check.h
218 src/liblzma/check/crc_macros.h
219 src/liblzma/common/block_util.c
220 src/liblzma/common/common.c
221 src/liblzma/common/common.h
222 src/liblzma/common/easy_preset.c
223 src/liblzma/common/easy_preset.h
224 src/liblzma/common/filter_common.c
225 src/liblzma/common/filter_common.h
226 src/liblzma/common/hardware_physmem.c
227 src/liblzma/common/index.c
228 src/liblzma/common/index.h
229 src/liblzma/common/memcmplen.h
230 src/liblzma/common/stream_flags_common.c
231 src/liblzma/common/stream_flags_common.h
232 src/liblzma/common/string_conversion.c
233 src/liblzma/common/vli_size.c
236 target_include_directories(liblzma PRIVATE
241 src/liblzma/rangecoder
249 ######################
250 # Size optimizations #
251 ######################
253 option(ENABLE_SMALL "Reduce code size at expense of speed. \
254 This may be useful together with CMAKE_BUILD_TYPE=MinSizeRel.")
257 add_compile_definitions(HAVE_SMALL)
265 set(ADDITIONAL_SUPPORTED_CHECKS crc64 sha256)
267 set(ADDITIONAL_CHECK_TYPES "${ADDITIONAL_SUPPORTED_CHECKS}" CACHE STRING
268 "Additional check types to support (crc32 is always built)")
270 foreach(CHECK IN LISTS ADDITIONAL_CHECK_TYPES)
271 if(NOT CHECK IN_LIST ADDITIONAL_SUPPORTED_CHECKS)
272 message(SEND_ERROR "'${CHECK}' is not a supported check type")
277 target_sources(liblzma PRIVATE src/liblzma/check/crc32_small.c)
279 target_sources(liblzma PRIVATE
280 src/liblzma/check/crc32_fast.c
281 src/liblzma/check/crc32_table.c
282 src/liblzma/check/crc32_table_be.h
283 src/liblzma/check/crc32_table_le.h
287 if("crc64" IN_LIST ADDITIONAL_CHECK_TYPES)
288 add_compile_definitions("HAVE_CHECK_CRC64")
291 target_sources(liblzma PRIVATE src/liblzma/check/crc64_small.c)
293 target_sources(liblzma PRIVATE
294 src/liblzma/check/crc64_fast.c
295 src/liblzma/check/crc64_table.c
296 src/liblzma/check/crc64_table_be.h
297 src/liblzma/check/crc64_table_le.h
302 if("sha256" IN_LIST ADDITIONAL_CHECK_TYPES)
303 add_compile_definitions("HAVE_CHECK_SHA256")
304 target_sources(liblzma PRIVATE src/liblzma/check/sha256.c)
312 set(SUPPORTED_MATCH_FINDERS hc3 hc4 bt2 bt3 bt4)
314 set(MATCH_FINDERS "${SUPPORTED_MATCH_FINDERS}" CACHE STRING
315 "Match finders to support (at least one is required for LZMA1 or LZMA2)")
317 foreach(MF IN LISTS MATCH_FINDERS)
318 if(MF IN_LIST SUPPORTED_MATCH_FINDERS)
319 string(TOUPPER "${MF}" MF_UPPER)
320 add_compile_definitions("HAVE_MF_${MF_UPPER}")
322 message(SEND_ERROR "'${MF}' is not a supported match finder")
331 # Supported thread methods:
332 # ON - autodetect the best threading method. The autodetection will
333 # prefer Windows threading (win95 or vista) over posix if both are
334 # available. vista threads will be used over win95 unless it is a
336 # OFF - Disable threading.
337 # posix - Use posix threading, or throw an error if not available.
338 # win95 - Use Windows win95 threading, or throw an error if not available.
339 # vista - Use Windows vista threading, or throw an error if not available.
340 set(SUPPORTED_THREAD_METHODS ON OFF posix win95 vista)
342 set(ENABLE_THREADS ON CACHE STRING
343 "Threading method type to support. Set to 'OFF' to disable threading")
345 # Create dropdown in CMake GUI since only 1 threading method is possible
346 # to select in a build.
347 set_property(CACHE ENABLE_THREADS
348 PROPERTY STRINGS "${SUPPORTED_THREAD_METHODS}")
350 # This is a flag variable set when win95 threads are used. We must ensure
351 # the combination of enable_small and win95 threads is not used without a
352 # compiler supporting attribute __constructor__.
353 set(USE_WIN95_THREADS OFF)
355 if(NOT ENABLE_THREADS IN_LIST SUPPORTED_THREAD_METHODS)
356 message(SEND_ERROR "'${ENABLE_THREADS}' is not a supported thread type")
360 # Also set THREADS_PREFER_PTHREAD_FLAG since the flag has no effect
361 # for Windows threading.
362 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
363 find_package(Threads REQUIRED)
365 # If both Windows and posix threading are available, prefer Windows.
366 # Note that on Cygwin CMAKE_USE_WIN32_THREADS_INIT is false.
367 if(CMAKE_USE_WIN32_THREADS_INIT AND NOT ENABLE_THREADS STREQUAL "posix")
368 if(ENABLE_THREADS STREQUAL "win95"
369 OR (ENABLE_THREADS STREQUAL "ON"
370 AND CMAKE_SIZEOF_VOID_P EQUAL 4))
371 # Use Windows 95 (and thus XP) compatible threads.
372 # This avoids use of features that were added in
373 # Windows Vista. This is used for 32-bit x86 builds for
374 # compatibility reasons since it makes no measurable difference
375 # in performance compared to Vista threads.
376 set(USE_WIN95_THREADS ON)
377 add_compile_definitions(MYTHREAD_WIN95)
379 add_compile_definitions(MYTHREAD_VISTA)
381 elseif(CMAKE_USE_PTHREADS_INIT)
382 if(ENABLE_THREADS STREQUAL "posix" OR ENABLE_THREADS STREQUAL "ON")
383 # Overwrite ENABLE_THREADS in case it was set to "ON".
384 # The threading library only needs to be explicitly linked
385 # for posix threads, so this is needed for creating
386 # liblzma-config.cmake later.
387 set(ENABLE_THREADS "posix")
389 target_link_libraries(liblzma Threads::Threads)
390 add_compile_definitions(MYTHREAD_POSIX)
392 # Check if pthread_condattr_setclock() exists to
393 # use CLOCK_MONOTONIC.
394 if(HAVE_CLOCK_MONOTONIC)
395 list(INSERT CMAKE_REQUIRED_LIBRARIES 0
396 "${CMAKE_THREAD_LIBS_INIT}")
397 check_symbol_exists(pthread_condattr_setclock pthread.h
398 HAVE_PTHREAD_CONDATTR_SETCLOCK)
399 tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK)
403 "Windows thread method requested, but a compatible "
404 "library could not be found")
407 message(SEND_ERROR "No supported threading library found")
410 target_sources(liblzma PRIVATE
411 src/common/tuklib_cpucores.c
412 src/common/tuklib_cpucores.h
413 src/liblzma/common/hardware_cputhreads.c
414 src/liblzma/common/outqueue.c
415 src/liblzma/common/outqueue.h
434 # The SUPPORTED_FILTERS are shared between Encoders and Decoders
435 # since only lzip does not appear in both lists. lzip is a special
436 # case anyway, so it is handled separately in the Decoders section.
437 set(SUPPORTED_FILTERS
444 set(ENCODERS "${SUPPORTED_FILTERS}" CACHE STRING "Encoders to support")
446 # If LZMA2 is enabled, then LZMA1 must also be enabled.
447 if(NOT "lzma1" IN_LIST ENCODERS AND "lzma2" IN_LIST ENCODERS)
448 message(SEND_ERROR "LZMA2 encoder requires that LZMA1 is also enabled")
451 # If LZMA1 is enabled, then at least one match finder must be enabled.
452 if(MATCH_FINDERS STREQUAL "" AND "lzma1" IN_LIST ENCODERS)
453 message(SEND_ERROR "At least 1 match finder is required for an "
457 set(HAVE_DELTA_CODER OFF)
458 set(SIMPLE_ENCODERS OFF)
459 set(HAVE_ENCODERS OFF)
461 foreach(ENCODER IN LISTS ENCODERS)
462 if(ENCODER IN_LIST SUPPORTED_FILTERS)
463 set(HAVE_ENCODERS ON)
465 if(NOT SIMPLE_ENCODERS AND ENCODER IN_LIST SIMPLE_FILTERS)
466 set(SIMPLE_ENCODERS ON)
469 string(TOUPPER "${ENCODER}" ENCODER_UPPER)
470 add_compile_definitions("HAVE_ENCODER_${ENCODER_UPPER}")
472 message(SEND_ERROR "'${ENCODER}' is not a supported encoder")
477 add_compile_definitions(HAVE_ENCODERS)
479 target_sources(liblzma PRIVATE
480 src/liblzma/common/alone_encoder.c
481 src/liblzma/common/block_buffer_encoder.c
482 src/liblzma/common/block_buffer_encoder.h
483 src/liblzma/common/block_encoder.c
484 src/liblzma/common/block_encoder.h
485 src/liblzma/common/block_header_encoder.c
486 src/liblzma/common/easy_buffer_encoder.c
487 src/liblzma/common/easy_encoder.c
488 src/liblzma/common/easy_encoder_memusage.c
489 src/liblzma/common/filter_buffer_encoder.c
490 src/liblzma/common/filter_encoder.c
491 src/liblzma/common/filter_encoder.h
492 src/liblzma/common/filter_flags_encoder.c
493 src/liblzma/common/index_encoder.c
494 src/liblzma/common/index_encoder.h
495 src/liblzma/common/stream_buffer_encoder.c
496 src/liblzma/common/stream_encoder.c
497 src/liblzma/common/stream_flags_encoder.c
498 src/liblzma/common/vli_encoder.c
502 target_sources(liblzma PRIVATE
503 src/liblzma/common/stream_encoder_mt.c
508 target_sources(liblzma PRIVATE
509 src/liblzma/simple/simple_encoder.c
510 src/liblzma/simple/simple_encoder.h
514 if("lzma1" IN_LIST ENCODERS)
515 target_sources(liblzma PRIVATE
516 src/liblzma/lzma/lzma_encoder.c
517 src/liblzma/lzma/lzma_encoder.h
518 src/liblzma/lzma/lzma_encoder_optimum_fast.c
519 src/liblzma/lzma/lzma_encoder_optimum_normal.c
520 src/liblzma/lzma/lzma_encoder_private.h
521 src/liblzma/lzma/fastpos.h
522 src/liblzma/lz/lz_encoder.c
523 src/liblzma/lz/lz_encoder.h
524 src/liblzma/lz/lz_encoder_hash.h
525 src/liblzma/lz/lz_encoder_hash_table.h
526 src/liblzma/lz/lz_encoder_mf.c
527 src/liblzma/rangecoder/price.h
528 src/liblzma/rangecoder/price_table.c
529 src/liblzma/rangecoder/range_encoder.h
533 target_sources(liblzma PRIVATE src/liblzma/lzma/fastpos_table.c)
537 if("lzma2" IN_LIST ENCODERS)
538 target_sources(liblzma PRIVATE
539 src/liblzma/lzma/lzma2_encoder.c
540 src/liblzma/lzma/lzma2_encoder.h
544 if("delta" IN_LIST ENCODERS)
545 set(HAVE_DELTA_CODER ON)
546 target_sources(liblzma PRIVATE
547 src/liblzma/delta/delta_encoder.c
548 src/liblzma/delta/delta_encoder.h
558 set(DECODERS "${SUPPORTED_FILTERS}" CACHE STRING "Decoders to support")
560 set(SIMPLE_DECODERS OFF)
561 set(HAVE_DECODERS OFF)
563 foreach(DECODER IN LISTS DECODERS)
564 if(DECODER IN_LIST SUPPORTED_FILTERS)
565 set(HAVE_DECODERS ON)
567 if(NOT SIMPLE_DECODERS AND DECODER IN_LIST SIMPLE_FILTERS)
568 set(SIMPLE_DECODERS ON)
571 string(TOUPPER "${DECODER}" DECODER_UPPER)
572 add_compile_definitions("HAVE_DECODER_${DECODER_UPPER}")
574 message(SEND_ERROR "'${DECODER}' is not a supported decoder")
579 add_compile_definitions(HAVE_DECODERS)
581 target_sources(liblzma PRIVATE
582 src/liblzma/common/alone_decoder.c
583 src/liblzma/common/alone_decoder.h
584 src/liblzma/common/auto_decoder.c
585 src/liblzma/common/block_buffer_decoder.c
586 src/liblzma/common/block_decoder.c
587 src/liblzma/common/block_decoder.h
588 src/liblzma/common/block_header_decoder.c
589 src/liblzma/common/easy_decoder_memusage.c
590 src/liblzma/common/file_info.c
591 src/liblzma/common/filter_buffer_decoder.c
592 src/liblzma/common/filter_decoder.c
593 src/liblzma/common/filter_decoder.h
594 src/liblzma/common/filter_flags_decoder.c
595 src/liblzma/common/index_decoder.c
596 src/liblzma/common/index_decoder.h
597 src/liblzma/common/index_hash.c
598 src/liblzma/common/stream_buffer_decoder.c
599 src/liblzma/common/stream_decoder.c
600 src/liblzma/common/stream_flags_decoder.c
601 src/liblzma/common/stream_decoder.h
602 src/liblzma/common/vli_decoder.c
606 target_sources(liblzma PRIVATE
607 src/liblzma/common/stream_decoder_mt.c
612 target_sources(liblzma PRIVATE
613 src/liblzma/simple/simple_decoder.c
614 src/liblzma/simple/simple_decoder.h
618 if("lzma1" IN_LIST DECODERS)
619 target_sources(liblzma PRIVATE
620 src/liblzma/lzma/lzma_decoder.c
621 src/liblzma/lzma/lzma_decoder.h
622 src/liblzma/rangecoder/range_decoder.h
623 src/liblzma/lz/lz_decoder.c
624 src/liblzma/lz/lz_decoder.h
628 if("lzma2" IN_LIST DECODERS)
629 target_sources(liblzma PRIVATE
630 src/liblzma/lzma/lzma2_decoder.c
631 src/liblzma/lzma/lzma2_decoder.h
635 if("delta" IN_LIST DECODERS)
636 set(HAVE_DELTA_CODER ON)
637 target_sources(liblzma PRIVATE
638 src/liblzma/delta/delta_decoder.c
639 src/liblzma/delta/delta_decoder.h
644 # Some sources must appear if the filter is configured as either
645 # an encoder or decoder.
646 if("lzma1" IN_LIST ENCODERS OR "lzma1" IN_LIST DECODERS)
647 target_sources(liblzma PRIVATE
648 src/liblzma/rangecoder/range_common.h
649 src/liblzma/lzma/lzma_encoder_presets.c
650 src/liblzma/lzma/lzma_common.h
655 target_sources(liblzma PRIVATE
656 src/liblzma/delta/delta_common.c
657 src/liblzma/delta/delta_common.h
658 src/liblzma/delta/delta_private.h
662 if(SIMPLE_ENCODERS OR SIMPLE_DECODERS)
663 target_sources(liblzma PRIVATE
664 src/liblzma/simple/simple_coder.c
665 src/liblzma/simple/simple_coder.h
666 src/liblzma/simple/simple_private.h
670 foreach(SIMPLE_CODER IN LISTS SIMPLE_FILTERS)
671 if(SIMPLE_CODER IN_LIST ENCODERS OR SIMPLE_CODER IN_LIST DECODERS)
672 target_sources(liblzma PRIVATE "src/liblzma/simple/${SIMPLE_CODER}.c")
681 option(MICROLZMA_ENCODER
682 "MicroLZMA encoder (needed by specific applications only)" ON)
684 option(MICROLZMA_DECODER
685 "MicroLZMA decoder (needed by specific applications only)" ON)
687 if(MICROLZMA_ENCODER)
688 if(NOT "lzma1" IN_LIST ENCODERS)
689 message(SEND_ERROR "The LZMA1 encoder is required to support the "
693 target_sources(liblzma PRIVATE src/liblzma/common/microlzma_encoder.c)
696 if(MICROLZMA_DECODER)
697 if(NOT "lzma1" IN_LIST DECODERS)
698 message(SEND_ERROR "The LZMA1 decoder is required to support the "
702 target_sources(liblzma PRIVATE src/liblzma/common/microlzma_decoder.c)
706 #############################
707 # lzip (.lz) format support #
708 #############################
710 option(LZIP_DECODER "Support lzip decoder" ON)
713 # If lzip decoder support is requested, make sure LZMA1 decoder is enabled.
714 if(NOT "lzma1" IN_LIST DECODERS)
715 message(SEND_ERROR "The LZMA1 decoder is required to support the "
719 add_compile_definitions(HAVE_LZIP_DECODER)
721 target_sources(liblzma PRIVATE
722 src/liblzma/common/lzip_decoder.c
723 src/liblzma/common/lzip_decoder.h
729 # Put the tuklib functions under the lzma_ namespace.
730 target_compile_definitions(liblzma PRIVATE TUKLIB_SYMBOL_PREFIX=lzma_)
731 tuklib_cpucores(liblzma)
732 tuklib_physmem(liblzma)
734 # While liblzma can be built without tuklib_cpucores or tuklib_physmem
735 # modules, the liblzma API functions lzma_cputhreads() and lzma_physmem()
736 # will then be useless (which isn't too bad but still unfortunate). Since
737 # I expect the CMake-based builds to be only used on systems that are
738 # supported by these tuklib modules, problems with these tuklib modules
739 # are considered a hard error for now. This hopefully helps to catch bugs
740 # in the CMake versions of the tuklib checks.
741 if(NOT TUKLIB_CPUCORES_FOUND OR NOT TUKLIB_PHYSMEM_FOUND)
742 # Use SEND_ERROR instead of FATAL_ERROR. If someone reports a bug,
743 # seeing the results of the remaining checks can be useful too.
745 "tuklib_cpucores() or tuklib_physmem() failed. "
746 "Unless you really are building for a system where these "
747 "modules are not supported (unlikely), this is a bug in the "
748 "included cmake/tuklib_*.cmake files that should be fixed. "
749 "To build anyway, edit this CMakeLists.txt to ignore this error.")
752 # Check for __attribute__((__constructor__)) support.
753 # This needs -Werror because some compilers just warn
754 # about this being unsupported.
755 cmake_push_check_state()
756 set(CMAKE_REQUIRED_FLAGS "-Werror")
757 check_c_source_compiles("
758 __attribute__((__constructor__))
759 static void my_constructor_func(void) { return; }
760 int main(void) { return 0; }
762 HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
763 cmake_pop_check_state()
764 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
766 # The Win95 threading lacks a thread-safe one-time initialization function.
767 # The one-time initialization is needed for crc32_small.c and crc64_small.c
768 # create the CRC tables. So if small mode is enabled, the threading mode is
769 # win95, and the compiler does not support attribute constructor, then we
770 # would end up with a multithreaded build that is thread-unsafe. As a
771 # result this configuration is not allowed.
772 if(USE_WIN95_THREADS AND ENABLE_SMALL AND NOT HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
773 message(SEND_ERROR "Threading method win95 and ENABLE_SMALL "
774 "cannot be used at the same time with a compiler "
775 "that doesn't support "
776 "__attribute__((__constructor__))")
780 # Check for __attribute__((__ifunc__())) support.
781 option(ALLOW_ATTR_IFUNC "Allow use of __attribute__((__ifunc__())) if \
782 supported by the system" ON)
785 cmake_push_check_state()
786 set(CMAKE_REQUIRED_FLAGS "-Werror")
787 check_c_source_compiles("
788 static void func(void) { return; }
789 static void (*resolve_func(void)) (void) { return func; }
790 void func_ifunc(void)
791 __attribute__((__ifunc__(\"resolve_func\")));
792 int main(void) { return 0; }
794 HAVE_FUNC_ATTRIBUTE_IFUNC)
795 cmake_pop_check_state()
796 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_IFUNC)
800 check_include_file(cpuid.h HAVE_CPUID_H)
801 tuklib_add_definition_if(liblzma HAVE_CPUID_H)
804 check_include_file(immintrin.h HAVE_IMMINTRIN_H)
806 target_compile_definitions(liblzma PRIVATE HAVE_IMMINTRIN_H)
809 check_c_source_compiles("
810 #include <immintrin.h>
814 _mm_movemask_epi8(x);
818 HAVE__MM_MOVEMASK_EPI8)
819 tuklib_add_definition_if(liblzma HAVE__MM_MOVEMASK_EPI8)
822 check_c_source_compiles("
823 #include <immintrin.h>
824 #if defined(__e2k__) && __iset__ < 6
827 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
828 __attribute__((__target__(\"ssse3,sse4.1,pclmul\")))
830 __m128i my_clmul(__m128i a)
832 const __m128i b = _mm_set_epi64x(1, 2);
833 return _mm_clmulepi64_si128(a, b, 0);
835 int main(void) { return 0; }
838 tuklib_add_definition_if(liblzma HAVE_USABLE_CLMUL)
841 # Support -fvisiblity=hidden when building shared liblzma.
842 # These lines do nothing on Windows (even under Cygwin).
843 # HAVE_VISIBILITY should always be defined to 0 or 1.
844 if(BUILD_SHARED_LIBS)
845 set_target_properties(liblzma PROPERTIES C_VISIBILITY_PRESET hidden)
846 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=1)
848 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=0)
852 if(BUILD_SHARED_LIBS)
853 # Add the Windows resource file for liblzma.dll.
854 target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc)
856 set_target_properties(liblzma PROPERTIES
857 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
860 # Export the public API symbols with __declspec(dllexport).
861 target_compile_definitions(liblzma PRIVATE DLL_EXPORT)
863 # Disable __declspec(dllimport) when linking against static liblzma.
864 target_compile_definitions(liblzma INTERFACE LZMA_API_STATIC)
866 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
867 # GNU/Linux-specific symbol versioning for shared liblzma.
868 # Note that adding link options doesn't affect static builds
869 # but HAVE_SYMBOL_VERSIONS_LINUX must not be used with static builds
870 # because it would put symbol versions into the static library which
871 # can cause problems. It's clearer if all symver related things are
872 # omitted when not building a shared library.
874 # NOTE: Set it explicitly to 1 to make it clear that versioning is
875 # done unconditionally in the C files.
876 target_compile_definitions(liblzma PRIVATE HAVE_SYMBOL_VERSIONS_LINUX=1)
877 target_link_options(liblzma PRIVATE
878 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
880 set_target_properties(liblzma PROPERTIES
881 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
883 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
884 # Symbol versioning for shared liblzma for non-GNU/Linux.
885 # FIXME? What about Solaris?
886 target_link_options(liblzma PRIVATE
887 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
889 set_target_properties(liblzma PROPERTIES
890 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
894 set_target_properties(liblzma PROPERTIES
895 # At least for now the package versioning matches the rules used for
896 # shared library versioning (excluding development releases) so it is
897 # fine to use the package version here.
898 SOVERSION "${xz_VERSION_MAJOR}"
899 VERSION "${xz_VERSION}"
901 # It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll.
902 # Avoid the name lzma.dll because it would conflict with LZMA SDK.
906 # Create liblzma-config-version.cmake.
908 # FIXME: SameMajorVersion is correct for stable releases but it is wrong
909 # for development releases where each release may have incompatible changes.
910 include(CMakePackageConfigHelpers)
911 write_basic_package_version_file(
912 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
913 VERSION "${liblzma_VERSION}"
914 COMPATIBILITY SameMajorVersion)
916 # Create liblzma-config.cmake. We use this spelling instead of
917 # liblzmaConfig.cmake to make find_package work in case insensitive
918 # manner even with case sensitive file systems. This gives more consistent
919 # behavior between operating systems. This optionally includes a dependency
920 # on a threading library, so the contents are created in two separate parts.
921 # The "second half" is always needed, so create it first.
922 set(LZMA_CONFIG_CONTENTS
923 "include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
925 if(NOT TARGET LibLZMA::LibLZMA)
926 # Be compatible with the spelling used by the FindLibLZMA module. This
927 # doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA
928 # to liblzma::liblzma instead of keeping the original spelling. Keeping
929 # the original spelling is important for good FindLibLZMA compatibility.
930 add_library(LibLZMA::LibLZMA INTERFACE IMPORTED)
931 set_target_properties(LibLZMA::LibLZMA PROPERTIES
932 INTERFACE_LINK_LIBRARIES liblzma::liblzma)
936 if(ENABLE_THREADS STREQUAL "posix")
937 set(LZMA_CONFIG_CONTENTS
938 "include(CMakeFindDependencyMacro)
939 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
940 find_dependency(Threads)
942 ${LZMA_CONFIG_CONTENTS}
946 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
947 "${LZMA_CONFIG_CONTENTS}")
949 # Set CMAKE_INSTALL_LIBDIR and friends.
950 include(GNUInstallDirs)
952 # Install the library binary. The INCLUDES specifies the include path that
953 # is exported for other projects to use but it doesn't install any files.
954 install(TARGETS liblzma EXPORT liblzmaTargets
955 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
956 COMPONENT liblzma_Runtime
957 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
958 COMPONENT liblzma_Runtime
959 NAMELINK_COMPONENT liblzma_Development
960 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
961 COMPONENT liblzma_Development
962 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
964 # Install the liblzma API headers. These use a subdirectory so
965 # this has to be done as a separate step.
966 install(DIRECTORY src/liblzma/api/
967 COMPONENT liblzma_Development
968 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
969 FILES_MATCHING PATTERN "*.h")
971 # Install the CMake files that other packages can use to find liblzma.
972 set(liblzma_INSTALL_CMAKEDIR
973 "${CMAKE_INSTALL_LIBDIR}/cmake/liblzma"
974 CACHE STRING "Path to liblzma's .cmake files")
976 install(EXPORT liblzmaTargets
978 FILE liblzma-targets.cmake
979 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
980 COMPONENT liblzma_Development)
982 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
983 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
984 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
985 COMPONENT liblzma_Development)
988 #############################################################################
989 # libgnu (getopt_long)
990 #############################################################################
992 # This mirrors how the Autotools build system handles the getopt_long
993 # replacement, calling the object library libgnu since the replacement
994 # version comes from Gnulib.
995 add_library(libgnu OBJECT)
997 # CMake requires that even an object library must have at least once source
998 # file. So we give it a header file that results in no output files.
999 target_sources(libgnu PRIVATE lib/getopt.in.h)
1001 # Create /lib directory in the build directory and add it to the include path.
1002 file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib")
1003 target_include_directories(libgnu PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/lib")
1005 # Include /lib from the source directory. It does no harm even if none of
1006 # the Gnulib replacements are used.
1007 target_include_directories(libgnu PUBLIC lib)
1009 # The command line tools need getopt_long in order to parse arguments. If
1010 # the system does not have a getopt_long implementation we can use the one
1011 # from Gnulib instead.
1012 check_symbol_exists(getopt_long getopt.h HAVE_GETOPT_LONG)
1014 if(NOT HAVE_GETOPT_LONG)
1015 # Set the __GETOPT_PREFIX definition to "rpl_" (replacement) to avoid
1016 # name conflicts with libc symbols. The same prefix is set if using
1017 # the Autotools build (m4/getopt.m4).
1018 target_compile_definitions(libgnu PUBLIC "__GETOPT_PREFIX=rpl_")
1020 # Create a custom copy command to copy the getopt header to the build
1021 # directory and re-copy it if it is updated. (Gnulib does it this way
1022 # because it allows choosing which .in.h files to actually use in the
1023 # build. We need just getopt.h so this is a bit overcomplicated for
1024 # a single header file only.)
1025 add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1026 COMMAND "${CMAKE_COMMAND}" -E copy
1027 "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
1028 "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1029 MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/lib/getopt.in.h"
1032 target_sources(libgnu PRIVATE
1039 lib/getopt-pfx-core.h
1040 lib/getopt-pfx-ext.h
1041 "${CMAKE_CURRENT_BINARY_DIR}/lib/getopt.h"
1047 #############################################################################
1049 #############################################################################
1051 if(HAVE_DECODERS AND (NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900))
1052 add_executable(xzdec
1053 src/common/sysdefs.h
1054 src/common/tuklib_common.h
1055 src/common/tuklib_config.h
1056 src/common/tuklib_exit.c
1057 src/common/tuklib_exit.h
1058 src/common/tuklib_gettext.h
1059 src/common/tuklib_progname.c
1060 src/common/tuklib_progname.h
1064 target_include_directories(xzdec PRIVATE
1069 target_link_libraries(xzdec PRIVATE liblzma libgnu)
1072 # Add the Windows resource file for xzdec.exe.
1073 target_sources(xzdec PRIVATE src/xzdec/xzdec_w32res.rc)
1074 set_target_properties(xzdec PROPERTIES
1075 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
1079 tuklib_progname(xzdec)
1081 install(TARGETS xzdec
1082 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
1086 install(FILES src/xzdec/xzdec.1
1087 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1093 #############################################################################
1095 #############################################################################
1097 if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900)
1099 src/common/mythread.h
1100 src/common/sysdefs.h
1101 src/common/tuklib_common.h
1102 src/common/tuklib_config.h
1103 src/common/tuklib_exit.c
1104 src/common/tuklib_exit.h
1105 src/common/tuklib_gettext.h
1106 src/common/tuklib_integer.h
1107 src/common/tuklib_mbstr.h
1108 src/common/tuklib_mbstr_fw.c
1109 src/common/tuklib_mbstr_width.c
1110 src/common/tuklib_open_stdxxx.c
1111 src/common/tuklib_open_stdxxx.h
1112 src/common/tuklib_progname.c
1113 src/common/tuklib_progname.h
1139 target_include_directories(xz PRIVATE
1145 target_sources(xz PRIVATE
1151 target_link_libraries(xz PRIVATE liblzma libgnu)
1153 target_compile_definitions(xz PRIVATE ASSUME_RAM=128)
1156 # Add the Windows resource file for xz.exe.
1157 target_sources(xz PRIVATE src/xz/xz_w32res.rc)
1158 set_target_properties(xz PROPERTIES
1159 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
1166 check_symbol_exists(optreset getopt.h HAVE_OPTRESET)
1167 tuklib_add_definition_if(xz HAVE_OPTRESET)
1169 check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
1170 tuklib_add_definition_if(xz HAVE_POSIX_FADVISE)
1172 # How to get file time:
1173 check_struct_has_member("struct stat" st_atim.tv_nsec
1174 "sys/types.h;sys/stat.h"
1175 HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1176 if(HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1177 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
1179 check_struct_has_member("struct stat" st_atimespec.tv_nsec
1180 "sys/types.h;sys/stat.h"
1181 HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1182 if(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1183 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
1185 check_struct_has_member("struct stat" st_atimensec
1186 "sys/types.h;sys/stat.h"
1187 HAVE_STRUCT_STAT_ST_ATIMENSEC)
1188 tuklib_add_definition_if(xz HAVE_STRUCT_STAT_ST_ATIMENSEC)
1192 # How to set file time:
1193 check_symbol_exists(futimens "sys/types.h;sys/stat.h" HAVE_FUTIMENS)
1195 tuklib_add_definitions(xz HAVE_FUTIMENS)
1197 check_symbol_exists(futimes "sys/time.h" HAVE_FUTIMES)
1199 tuklib_add_definitions(xz HAVE_FUTIMES)
1201 check_symbol_exists(futimesat "sys/time.h" HAVE_FUTIMESAT)
1203 tuklib_add_definitions(xz HAVE_FUTIMESAT)
1205 check_symbol_exists(utimes "sys/time.h" HAVE_UTIMES)
1207 tuklib_add_definitions(xz HAVE_UTIMES)
1209 check_symbol_exists(_futime "sys/utime.h" HAVE__FUTIME)
1211 tuklib_add_definitions(xz HAVE__FUTIME)
1213 check_symbol_exists(utime "utime.h" HAVE_UTIME)
1214 tuklib_add_definition_if(xz HAVE_UTIME)
1222 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
1226 install(FILES src/xz/xz.1
1227 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1230 option(CREATE_XZ_SYMLINKS "Create unxz and xzcat symlinks" ON)
1231 option(CREATE_LZMA_SYMLINKS "Create lzma, unlzma, and lzcat symlinks"
1235 if(CREATE_XZ_SYMLINKS)
1236 list(APPEND XZ_LINKS "unxz" "xzcat")
1239 if(CREATE_LZMA_SYMLINKS)
1240 list(APPEND XZ_LINKS "lzma" "unlzma" "lzcat")
1243 # With Windows Cygwin and MSYS2 the symlinking is complicated. Both
1244 # of these environments set the UNIX variable so they will try to
1245 # make the symlinks. The ability for Cygwin and MSYS2 to make
1246 # broken symlinks is determined by the CYGWIN and MSYS2 environment
1247 # variables, respectively. Broken symlinks are needed for the man
1248 # page symlinks and for determining if the xz and lzma symlinks need
1249 # to depend on the xz target or not. If broken symlinks cannot be
1250 # made then the xz binary must be created before the symlinks.
1251 set(ALLOW_BROKEN_SYMLINKS ON)
1253 if(CMAKE_SYSTEM_NAME STREQUAL "CYGWIN")
1254 # The Cygwin env variable can be set to four possible values:
1256 # 1. "lnk". Create symlinks as Windows shortcuts.
1258 # 2. "native". Create symlinks as native Windows symlinks
1259 # if supported by the system. Fallback to "lnk" if native
1260 # symlinks are not supported.
1262 # 3. "nativestrict". Create symlinks as native Windows symlinks
1263 # if supported by the system. If the target of the symlink
1264 # does not exist or the creation of the symlink fails for any
1265 # reason, do not create the symlink.
1267 # 4. "sys". Create symlinks as plain files with a special
1268 # system attribute containing the path to the symlink target.
1270 # So, the only case we care about for broken symlinks is
1271 # "nativestrict" since all other values mean that broken
1272 # symlinks are allowed. If the env variable is not set the
1273 # default is "native". If the env variable is set but not
1274 # assigned one of the four values, then the default is the same
1275 # as option 1 "lnk".
1276 string(FIND "$ENV{CYGWIN}" "winsymlinks:nativestrict" SYMLINK_POS)
1277 if(SYMLINK_POS GREATER -1)
1278 set(ALLOW_BROKEN_SYMLINKS OFF)
1280 elseif(CMAKE_SYSTEM_NAME STREQUAL "MSYS")
1281 # The MSYS env variable behaves similar to the CYGWIN but has a
1282 # different default behavior. If winsymlinks is set but not
1283 # assigned one of the four supported values, the default is to
1284 # *copy* the target to the symlink destination. This will fail
1285 # if the target does not exist so broken symlinks cannot be
1287 string(FIND "$ENV{MSYS}" "winsymlinks" SYMLINK_POS)
1288 if(SYMLINK_POS GREATER -1)
1289 string(FIND "$ENV{MSYS}" "winsymlinks:nativestrict"
1291 if(SYMLINK_POS GREATER -1)
1292 set(ALLOW_BROKEN_SYMLINKS OFF)
1295 set(ALLOW_BROKEN_SYMLINKS OFF)
1299 # Create symlinks in the build directory and then install them.
1301 # The symlinks do not likely need any special extension since
1302 # even on Windows the symlink can still be executed without
1303 # the .exe extension.
1304 foreach(LINK IN LISTS XZ_LINKS)
1305 add_custom_target("${LINK}" ALL
1306 "${CMAKE_COMMAND}" -E create_symlink
1307 "$<TARGET_FILE_NAME:xz>" "${LINK}"
1308 BYPRODUCTS "${LINK}"
1310 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}"
1311 DESTINATION "${CMAKE_INSTALL_BINDIR}"
1314 # Only create the man page symlinks if the symlinks can be
1315 # created broken. The symlinks will not be valid until install
1316 # so they cannot be created on these system environments.
1317 if(ALLOW_BROKEN_SYMLINKS)
1318 add_custom_target("${LINK}.1" ALL
1319 "${CMAKE_COMMAND}" -E create_symlink "xz.1" "${LINK}.1"
1320 BYPRODUCTS "${LINK}.1"
1322 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}.1"
1323 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
1326 # Add the xz target as dependency when broken symlinks
1327 # cannot be made. This ensures parallel builds do not fail
1328 # since it will enforce the order of creating xz first, then
1330 add_dependencies("${LINK}" xz)
1337 #############################################################################
1339 #############################################################################
1359 foreach(TEST IN LISTS LIBLZMA_TESTS)
1360 add_executable("${TEST}" "tests/${TEST}.c")
1362 target_include_directories("${TEST}" PRIVATE
1369 target_link_libraries("${TEST}" PRIVATE liblzma)
1371 # Put the test programs into their own subdirectory so they don't
1372 # pollute the top-level dir which might contain xz and xzdec.
1373 set_target_properties("${TEST}" PROPERTIES
1374 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests_bin"
1377 add_test(NAME "${TEST}"
1378 COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tests_bin/${TEST}"
1381 # Set srcdir environment variable so that the tests find their
1382 # input files from the source tree.
1384 # Set the return code for skipped tests to match Automake convention.
1385 set_tests_properties("${TEST}" PROPERTIES
1386 ENVIRONMENT "srcdir=${CMAKE_CURRENT_LIST_DIR}/tests"