1 #############################################################################
3 # Very limited CMake support for building some parts of XZ Utils
5 # For now, this is indented 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 replacement getopt_long(), libc must have it
14 # - No sandboxing support
17 # Other missing things:
18 # - No xzgrep or other scripts or their symlinks
19 # - No xz tests (liblzma tests only)
21 # NOTE: Even if the code compiles without warnings, the end result may be
22 # different than via ./configure. Specifically, the list of #defines
23 # may be different (if so, probably this CMakeLists.txt got them wrong).
25 # This file provides the following installation components (if you only
26 # need liblzma, install only its components!):
28 # - liblzma_Development
29 # - xz (on some platforms only)
30 # - xzdec (on some platforms only)
32 # To find the target liblzma::liblzma from other packages, use the CONFIG
33 # option with find_package() to avoid a conflict with the FindLibLZMA module
34 # with case-insensitive file systems. For example, to require liblzma 5.2.5
35 # or a newer compatible version:
37 # find_package(liblzma 5.2.5 REQUIRED CONFIG)
38 # target_link_libraries(my_application liblzma::liblzma)
40 #############################################################################
42 # Author: Lasse Collin
44 # This file has been put into the public domain.
45 # You can do whatever you want with this file.
47 #############################################################################
49 cmake_minimum_required(VERSION 3.13...3.16 FATAL_ERROR)
51 include(CMakePushCheckState)
52 include(CheckIncludeFile)
53 include(CheckSymbolExists)
54 include(CheckStructHasMember)
55 include(CheckCSourceCompiles)
56 include(cmake/tuklib_integer.cmake)
57 include(cmake/tuklib_cpucores.cmake)
58 include(cmake/tuklib_physmem.cmake)
59 include(cmake/tuklib_progname.cmake)
60 include(cmake/tuklib_mbstr.cmake)
62 # Get the package version from version.h into XZ_VERSION variable.
63 file(READ src/liblzma/api/lzma/version.h XZ_VERSION)
66 #define LZMA_VERSION_MAJOR ([0-9]+)\n\
67 #define LZMA_VERSION_MINOR ([0-9]+)\n\
68 #define LZMA_VERSION_PATCH ([0-9]+)\n\
70 "\\1.\\2.\\3" XZ_VERSION "${XZ_VERSION}")
72 # Among other things, this gives us variables xz_VERSION and xz_VERSION_MAJOR.
73 project(xz VERSION "${XZ_VERSION}" LANGUAGES C)
75 # On Apple OSes, don't build executables as bundles:
76 set(CMAKE_MACOSX_BUNDLE OFF)
78 # Definitions common to all targets:
79 add_compile_definitions(
81 PACKAGE_NAME="XZ Utils"
82 PACKAGE_BUGREPORT="xz@tukaani.org"
83 PACKAGE_URL="https://tukaani.org/xz/"
102 HAVE_ENCODER_ARMTHUMB
118 # Standard headers and types are available:
124 # Disable assert() checks when no build type has been specified. Non-empty
125 # build types like "Release" and "Debug" handle this by default.
129 # _GNU_SOURCE and such definitions. This specific macro is special since
130 # it also adds the definitions to CMAKE_REQUIRED_DEFINITIONS.
131 tuklib_use_system_extensions(ALL)
133 # This is needed by liblzma and xz.
136 # Check for clock_gettime(). Do this before checking for threading so
137 # that we know there if CLOCK_MONOTONIC is available.
138 if(NOT WIN32 AND NOT DEFINED HAVE_CLOCK_GETTIME)
139 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
140 if(NOT HAVE_CLOCK_GETTIME)
141 # With glibc <= 2.17 or Solaris 10 this needs librt.
142 unset(HAVE_CLOCK_GETTIME CACHE)
144 list(INSERT CMAKE_REQUIRED_LIBRARIES 0 rt)
145 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
147 # If it was found now, add it to all targets and keep it
148 # in CMAKE_REQUIRED_LIBRARIES for further tests too.
149 if(HAVE_CLOCK_GETTIME)
152 list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
155 if(HAVE_CLOCK_GETTIME)
156 # Check if CLOCK_MONOTONIC is available for clock_gettime().
157 check_symbol_exists(CLOCK_MONOTONIC time.h HAVE_CLOCK_MONOTONIC)
159 add_compile_definitions(
167 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
168 find_package(Threads REQUIRED)
169 if(CMAKE_USE_WIN32_THREADS_INIT)
170 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
171 # Define to 1 when using Windows 95 (and thus XP) compatible threads. This
172 # avoids use of features that were added in Windows Vista.
173 # This is used for 32-bit x86 builds for compatibility reasons since it
174 # makes no measurable difference in performance compared to Vista threads.
175 add_compile_definitions(MYTHREAD_WIN95)
177 # Define to 1 when using Windows Vista compatible threads. This uses features
178 # that are not available on Windows XP.
179 add_compile_definitions(MYTHREAD_VISTA)
182 add_compile_definitions(MYTHREAD_POSIX)
184 # Check if pthread_condattr_setclock() exists to use CLOCK_MONOTONIC.
185 if(HAVE_CLOCK_MONOTONIC)
186 list(INSERT CMAKE_REQUIRED_LIBRARIES 0 "${CMAKE_THREAD_LIBS_INIT}")
187 check_symbol_exists(pthread_condattr_setclock pthread.h
188 HAVE_PTHREAD_CONDATTR_SETCLOCK)
189 tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK)
193 # Options for new enough GCC or Clang on any arch or operating system:
194 if(CMAKE_C_COMPILER_ID MATCHES GNU|Clang)
195 # configure.ac has a long list but it won't be copied here:
196 add_compile_options(-Wall -Wextra)
200 #############################################################################
202 #############################################################################
204 option(BUILD_SHARED_LIBS "Build liblzma as a shared library instead of static")
207 src/common/mythread.h
209 src/common/tuklib_common.h
210 src/common/tuklib_config.h
211 src/common/tuklib_cpucores.c
212 src/common/tuklib_cpucores.h
213 src/common/tuklib_integer.h
214 src/common/tuklib_physmem.c
215 src/common/tuklib_physmem.h
216 src/liblzma/api/lzma.h
217 src/liblzma/api/lzma/base.h
218 src/liblzma/api/lzma/bcj.h
219 src/liblzma/api/lzma/block.h
220 src/liblzma/api/lzma/check.h
221 src/liblzma/api/lzma/container.h
222 src/liblzma/api/lzma/delta.h
223 src/liblzma/api/lzma/filter.h
224 src/liblzma/api/lzma/hardware.h
225 src/liblzma/api/lzma/index.h
226 src/liblzma/api/lzma/index_hash.h
227 src/liblzma/api/lzma/lzma12.h
228 src/liblzma/api/lzma/stream_flags.h
229 src/liblzma/api/lzma/version.h
230 src/liblzma/api/lzma/vli.h
231 src/liblzma/check/check.c
232 src/liblzma/check/check.h
233 src/liblzma/check/crc32_fast.c
234 src/liblzma/check/crc32_table.c
235 src/liblzma/check/crc32_table_be.h
236 src/liblzma/check/crc32_table_le.h
237 src/liblzma/check/crc64_fast.c
238 src/liblzma/check/crc64_table.c
239 src/liblzma/check/crc64_table_be.h
240 src/liblzma/check/crc64_table_le.h
241 src/liblzma/check/crc_macros.h
242 src/liblzma/check/sha256.c
243 src/liblzma/common/alone_decoder.c
244 src/liblzma/common/alone_decoder.h
245 src/liblzma/common/alone_encoder.c
246 src/liblzma/common/auto_decoder.c
247 src/liblzma/common/block_buffer_decoder.c
248 src/liblzma/common/block_buffer_encoder.c
249 src/liblzma/common/block_buffer_encoder.h
250 src/liblzma/common/block_decoder.c
251 src/liblzma/common/block_decoder.h
252 src/liblzma/common/block_encoder.c
253 src/liblzma/common/block_encoder.h
254 src/liblzma/common/block_header_decoder.c
255 src/liblzma/common/block_header_encoder.c
256 src/liblzma/common/block_util.c
257 src/liblzma/common/common.c
258 src/liblzma/common/common.h
259 src/liblzma/common/easy_buffer_encoder.c
260 src/liblzma/common/easy_decoder_memusage.c
261 src/liblzma/common/easy_encoder.c
262 src/liblzma/common/easy_encoder_memusage.c
263 src/liblzma/common/easy_preset.c
264 src/liblzma/common/easy_preset.h
265 src/liblzma/common/file_info.c
266 src/liblzma/common/filter_buffer_decoder.c
267 src/liblzma/common/filter_buffer_encoder.c
268 src/liblzma/common/filter_common.c
269 src/liblzma/common/filter_common.h
270 src/liblzma/common/filter_decoder.c
271 src/liblzma/common/filter_decoder.h
272 src/liblzma/common/filter_encoder.c
273 src/liblzma/common/filter_encoder.h
274 src/liblzma/common/filter_flags_decoder.c
275 src/liblzma/common/filter_flags_encoder.c
276 src/liblzma/common/hardware_cputhreads.c
277 src/liblzma/common/hardware_physmem.c
278 src/liblzma/common/index.c
279 src/liblzma/common/index.h
280 src/liblzma/common/index_decoder.c
281 src/liblzma/common/index_decoder.h
282 src/liblzma/common/index_encoder.c
283 src/liblzma/common/index_encoder.h
284 src/liblzma/common/index_hash.c
285 src/liblzma/common/lzip_decoder.c
286 src/liblzma/common/lzip_decoder.h
287 src/liblzma/common/memcmplen.h
288 src/liblzma/common/outqueue.c
289 src/liblzma/common/outqueue.h
290 src/liblzma/common/stream_buffer_decoder.c
291 src/liblzma/common/stream_buffer_encoder.c
292 src/liblzma/common/stream_decoder.c
293 src/liblzma/common/stream_decoder_mt.c
294 src/liblzma/common/stream_decoder.h
295 src/liblzma/common/stream_encoder.c
296 src/liblzma/common/stream_encoder_mt.c
297 src/liblzma/common/stream_flags_common.c
298 src/liblzma/common/stream_flags_common.h
299 src/liblzma/common/stream_flags_decoder.c
300 src/liblzma/common/stream_flags_encoder.c
301 src/liblzma/common/string_conversion.c
302 src/liblzma/common/vli_decoder.c
303 src/liblzma/common/vli_encoder.c
304 src/liblzma/common/vli_size.c
305 src/liblzma/delta/delta_common.c
306 src/liblzma/delta/delta_common.h
307 src/liblzma/delta/delta_decoder.c
308 src/liblzma/delta/delta_decoder.h
309 src/liblzma/delta/delta_encoder.c
310 src/liblzma/delta/delta_encoder.h
311 src/liblzma/delta/delta_private.h
312 src/liblzma/lz/lz_decoder.c
313 src/liblzma/lz/lz_decoder.h
314 src/liblzma/lz/lz_encoder.c
315 src/liblzma/lz/lz_encoder.h
316 src/liblzma/lz/lz_encoder_hash.h
317 src/liblzma/lz/lz_encoder_hash_table.h
318 src/liblzma/lz/lz_encoder_mf.c
319 src/liblzma/lzma/fastpos.h
320 src/liblzma/lzma/fastpos_table.c
321 src/liblzma/lzma/lzma2_decoder.c
322 src/liblzma/lzma/lzma2_decoder.h
323 src/liblzma/lzma/lzma2_encoder.c
324 src/liblzma/lzma/lzma2_encoder.h
325 src/liblzma/lzma/lzma_common.h
326 src/liblzma/lzma/lzma_decoder.c
327 src/liblzma/lzma/lzma_decoder.h
328 src/liblzma/lzma/lzma_encoder.c
329 src/liblzma/lzma/lzma_encoder.h
330 src/liblzma/lzma/lzma_encoder_optimum_fast.c
331 src/liblzma/lzma/lzma_encoder_optimum_normal.c
332 src/liblzma/lzma/lzma_encoder_presets.c
333 src/liblzma/lzma/lzma_encoder_private.h
334 src/liblzma/rangecoder/price.h
335 src/liblzma/rangecoder/price_table.c
336 src/liblzma/rangecoder/range_common.h
337 src/liblzma/rangecoder/range_decoder.h
338 src/liblzma/rangecoder/range_encoder.h
339 src/liblzma/simple/arm.c
340 src/liblzma/simple/armthumb.c
341 src/liblzma/simple/arm64.c
342 src/liblzma/simple/ia64.c
343 src/liblzma/simple/powerpc.c
344 src/liblzma/simple/simple_coder.c
345 src/liblzma/simple/simple_coder.h
346 src/liblzma/simple/simple_decoder.c
347 src/liblzma/simple/simple_decoder.h
348 src/liblzma/simple/simple_encoder.c
349 src/liblzma/simple/simple_encoder.h
350 src/liblzma/simple/simple_private.h
351 src/liblzma/simple/sparc.c
352 src/liblzma/simple/x86.c
355 target_include_directories(liblzma PRIVATE
360 src/liblzma/rangecoder
367 target_link_libraries(liblzma Threads::Threads)
369 # Put the tuklib functions under the lzma_ namespace.
370 target_compile_definitions(liblzma PRIVATE TUKLIB_SYMBOL_PREFIX=lzma_)
371 tuklib_cpucores(liblzma)
372 tuklib_physmem(liblzma)
374 # While liblzma can be built without tuklib_cpucores or tuklib_physmem
375 # modules, the liblzma API functions lzma_cputhreads() and lzma_physmem()
376 # will then be useless (which isn't too bad but still unfortunate). Since
377 # I expect the CMake-based builds to be only used on systems that are
378 # supported by these tuklib modules, problems with these tuklib modules
379 # are considered a hard error for now. This hopefully helps to catch bugs
380 # in the CMake versions of the tuklib checks.
381 if(NOT TUKLIB_CPUCORES_FOUND OR NOT TUKLIB_PHYSMEM_FOUND)
382 # Use SEND_ERROR instead of FATAL_ERROR. If someone reports a bug,
383 # seeing the results of the remaining checks can be useful too.
385 "tuklib_cpucores() or tuklib_physmem() failed. "
386 "Unless you really are building for a system where these "
387 "modules are not supported (unlikely), this is a bug in the "
388 "included cmake/tuklib_*.cmake files that should be fixed. "
389 "To build anyway, edit this CMakeLists.txt to ignore this error.")
392 # Check for __attribute__((__constructor__)) support.
393 # This needs -Werror because some compilers just warn
394 # about this being unsupported.
395 cmake_push_check_state()
396 set(CMAKE_REQUIRED_FLAGS "-Werror")
397 check_c_source_compiles("
398 __attribute__((__constructor__))
399 static void my_constructor_func(void) { return; }
400 int main(void) { return 0; }
402 HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
403 cmake_pop_check_state()
404 tuklib_add_definition_if(liblzma HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
407 check_include_file(cpuid.h HAVE_CPUID_H)
408 tuklib_add_definition_if(liblzma HAVE_CPUID_H)
411 check_include_file(immintrin.h HAVE_IMMINTRIN_H)
413 target_compile_definitions(liblzma PRIVATE HAVE_IMMINTRIN_H)
416 check_c_source_compiles("
417 #include <immintrin.h>
421 _mm_movemask_epi8(x);
425 HAVE__MM_MOVEMASK_EPI8)
426 tuklib_add_definition_if(liblzma HAVE__MM_MOVEMASK_EPI8)
429 check_c_source_compiles("
430 #include <immintrin.h>
431 #if defined(__e2k__) && __iset__ < 6
434 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
435 __attribute__((__target__(\"ssse3,sse4.1,pclmul\")))
437 __m128i my_clmul(__m128i a, __m128i b)
439 return _mm_clmulepi64_si128(a, b, 0);
441 int main(void) { return 0; }
444 tuklib_add_definition_if(liblzma HAVE_USABLE_CLMUL)
447 # Support -fvisiblity=hidden when building shared liblzma.
448 # These lines do nothing on Windows (even under Cygwin).
449 # HAVE_VISIBILITY should always be defined to 0 or 1.
450 if(BUILD_SHARED_LIBS)
451 set_target_properties(liblzma PROPERTIES C_VISIBILITY_PRESET hidden)
452 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=1)
454 target_compile_definitions(liblzma PRIVATE HAVE_VISIBILITY=0)
458 if(BUILD_SHARED_LIBS)
459 # Add the Windows resource file for liblzma.dll.
460 target_sources(liblzma PRIVATE src/liblzma/liblzma_w32res.rc)
462 set_target_properties(liblzma PROPERTIES
463 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
466 # Export the public API symbols with __declspec(dllexport).
467 target_compile_definitions(liblzma PRIVATE DLL_EXPORT)
469 # Disable __declspec(dllimport) when linking against static liblzma.
470 target_compile_definitions(liblzma INTERFACE LZMA_API_STATIC)
472 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
473 # GNU/Linux-specific symbol versioning for shared liblzma.
474 # Note that adding link options doesn't affect static builds
475 # but HAVE_SYMBOL_VERSIONS_LINUX must not be used with static builds
476 # because it would put symbol versions into the static library which
477 # can cause problems. It's clearer if all symver related things are
478 # omitted when not building a shared library.
480 # NOTE: Set it explicitly to 1 to make it clear that versioning is
481 # done unconditionally in the C files.
482 target_compile_definitions(liblzma PRIVATE HAVE_SYMBOL_VERSIONS_LINUX=1)
483 target_link_options(liblzma PRIVATE
484 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
486 set_target_properties(liblzma PROPERTIES
487 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_linux.map"
489 elseif(BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
490 # Symbol versioning for shared liblzma for non-GNU/Linux.
491 # FIXME? What about Solaris?
492 target_link_options(liblzma PRIVATE
493 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
495 set_target_properties(liblzma PROPERTIES
496 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma_generic.map"
500 set_target_properties(liblzma PROPERTIES
501 # At least for now the package versioning matches the rules used for
502 # shared library versioning (excluding development releases) so it is
503 # fine to use the package version here.
504 SOVERSION "${xz_VERSION_MAJOR}"
505 VERSION "${xz_VERSION}"
507 # It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll.
508 # Avoid the name lzma.dll because it would conflict with LZMA SDK.
512 # Create liblzma-config-version.cmake. We use this spelling instead of
513 # liblzmaConfig.cmake to make find_package work in case insensitive manner
514 # even with case sensitive file systems. This gives more consistent behavior
515 # between operating systems.
517 # FIXME: SameMajorVersion is correct for stable releases but it is wrong
518 # for development releases where each release may have incompatible changes.
519 include(CMakePackageConfigHelpers)
520 write_basic_package_version_file(
521 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
522 VERSION "${liblzma_VERSION}"
523 COMPATIBILITY SameMajorVersion)
525 # Create liblzma-config.cmake.
526 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
527 "include(CMakeFindDependencyMacro)
528 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
529 find_dependency(Threads)
531 include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
533 # Be compatible with the spelling used by the FindLibLZMA module. This
534 # doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA
535 # to liblzma::liblzma instead of keeping the original spelling. Keeping
536 # the original spelling is important for good FindLibLZMA compatibility.
537 add_library(LibLZMA::LibLZMA INTERFACE IMPORTED)
538 set_target_properties(LibLZMA::LibLZMA PROPERTIES
539 INTERFACE_LINK_LIBRARIES liblzma::liblzma)
542 # Set CMAKE_INSTALL_LIBDIR and friends.
543 include(GNUInstallDirs)
545 # Install the library binary. The INCLUDES specifies the include path that
546 # is exported for other projects to use but it doesn't install any files.
547 install(TARGETS liblzma EXPORT liblzmaTargets
548 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
549 COMPONENT liblzma_Runtime
550 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
551 COMPONENT liblzma_Runtime
552 NAMELINK_COMPONENT liblzma_Development
553 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
554 COMPONENT liblzma_Development
555 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
557 # Install the liblzma API headers. These use a subdirectory so
558 # this has to be done as a separate step.
559 install(DIRECTORY src/liblzma/api/
560 COMPONENT liblzma_Development
561 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
562 FILES_MATCHING PATTERN "*.h")
564 # Install the CMake files that other packages can use to find liblzma.
565 set(liblzma_INSTALL_CMAKEDIR
566 "${CMAKE_INSTALL_LIBDIR}/cmake/liblzma"
567 CACHE STRING "Path to liblzma's .cmake files")
569 install(EXPORT liblzmaTargets
571 FILE liblzma-targets.cmake
572 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
573 COMPONENT liblzma_Development)
575 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
576 "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config-version.cmake"
577 DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
578 COMPONENT liblzma_Development)
581 #############################################################################
583 #############################################################################
585 # The command line tools needs this.
586 check_symbol_exists(getopt_long getopt.h HAVE_GETOPT_LONG)
589 #############################################################################
591 #############################################################################
596 src/common/tuklib_common.h
597 src/common/tuklib_config.h
598 src/common/tuklib_exit.c
599 src/common/tuklib_exit.h
600 src/common/tuklib_gettext.h
601 src/common/tuklib_progname.c
602 src/common/tuklib_progname.h
606 target_include_directories(xzdec PRIVATE
611 target_link_libraries(xzdec PRIVATE liblzma)
613 tuklib_progname(xzdec)
615 install(TARGETS xzdec
616 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
620 install(FILES src/xzdec/xzdec.1
621 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
627 #############################################################################
629 #############################################################################
631 if(NOT MSVC AND HAVE_GETOPT_LONG)
633 src/common/mythread.h
635 src/common/tuklib_common.h
636 src/common/tuklib_config.h
637 src/common/tuklib_exit.c
638 src/common/tuklib_exit.h
639 src/common/tuklib_gettext.h
640 src/common/tuklib_integer.h
641 src/common/tuklib_mbstr.h
642 src/common/tuklib_mbstr_fw.c
643 src/common/tuklib_mbstr_width.c
644 src/common/tuklib_open_stdxxx.c
645 src/common/tuklib_open_stdxxx.h
646 src/common/tuklib_progname.c
647 src/common/tuklib_progname.h
675 target_include_directories(xz PRIVATE
680 target_link_libraries(xz PRIVATE liblzma)
682 target_compile_definitions(xz PRIVATE ASSUME_RAM=128)
687 check_symbol_exists(optreset getopt.h HAVE_OPTRESET)
688 tuklib_add_definition_if(xz HAVE_OPTRESET)
690 check_symbol_exists(posix_fadvise fcntl.h HAVE_POSIX_FADVISE)
691 tuklib_add_definition_if(xz HAVE_POSIX_FADVISE)
693 # How to get file time:
694 check_struct_has_member("struct stat" st_atim.tv_nsec
695 "sys/types.h;sys/stat.h"
696 HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
697 if(HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
698 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC)
700 check_struct_has_member("struct stat" st_atimespec.tv_nsec
701 "sys/types.h;sys/stat.h"
702 HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
703 if(HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
704 tuklib_add_definitions(xz HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC)
706 check_struct_has_member("struct stat" st_atimensec
707 "sys/types.h;sys/stat.h"
708 HAVE_STRUCT_STAT_ST_ATIMENSEC)
709 tuklib_add_definition_if(xz HAVE_STRUCT_STAT_ST_ATIMENSEC)
713 # How to set file time:
714 check_symbol_exists(futimens "sys/types.h;sys/stat.h" HAVE_FUTIMENS)
716 tuklib_add_definitions(xz HAVE_FUTIMENS)
718 check_symbol_exists(futimes "sys/time.h" HAVE_FUTIMES)
720 tuklib_add_definitions(xz HAVE_FUTIMES)
722 check_symbol_exists(futimesat "sys/time.h" HAVE_FUTIMESAT)
724 tuklib_add_definitions(xz HAVE_FUTIMESAT)
726 check_symbol_exists(utimes "sys/time.h" HAVE_UTIMES)
728 tuklib_add_definitions(xz HAVE_UTIMES)
730 check_symbol_exists(_futime "sys/utime.h" HAVE__FUTIME)
732 tuklib_add_definitions(xz HAVE__FUTIME)
734 check_symbol_exists(utime "utime.h" HAVE_UTIME)
735 tuklib_add_definition_if(xz HAVE_UTIME)
743 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
747 install(FILES src/xz/xz.1
748 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
751 option(CREATE_XZ_SYMLINKS "Create unxz and xzcat symlinks" ON)
752 option(CREATE_LZMA_SYMLINKS "Create lzma, unlzma, and lzcat symlinks"
756 if(CREATE_XZ_SYMLINKS)
757 list(APPEND XZ_LINKS "unxz" "xzcat")
760 if(CREATE_LZMA_SYMLINKS)
761 list(APPEND XZ_LINKS "lzma" "unlzma" "lzcat")
764 # Create symlinks in the build directory and then install them.
766 # The symlinks do not likely need any special extension since
767 # even on Windows the symlink can still be executed without
768 # the .exe extension.
769 foreach(LINK IN LISTS XZ_LINKS)
770 add_custom_target("${LINK}" ALL
771 "${CMAKE_COMMAND}" -E create_symlink
772 "$<TARGET_FILE_NAME:xz>" "${LINK}"
775 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}"
776 DESTINATION "${CMAKE_INSTALL_BINDIR}"
778 add_custom_target("${LINK}.1" ALL
779 "${CMAKE_COMMAND}" -E create_symlink "xz.1" "${LINK}.1"
780 BYPRODUCTS "${LINK}.1"
782 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LINK}.1"
783 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
790 #############################################################################
792 #############################################################################
810 foreach(TEST IN LISTS LIBLZMA_TESTS)
811 add_executable("${TEST}" "tests/${TEST}.c")
813 target_include_directories("${TEST}" PRIVATE
820 target_link_libraries("${TEST}" PRIVATE liblzma)
822 # Put the test programs into their own subdirectory so they don't
823 # pollute the top-level dir which might contain xz and xzdec.
824 set_target_properties("${TEST}" PROPERTIES
825 RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests_bin"
828 add_test(NAME "${TEST}"
829 COMMAND "${CMAKE_CURRENT_BINARY_DIR}/tests_bin/${TEST}"
832 # Set srcdir environment variable so that the tests find their
833 # input files from the source tree.
835 # Set the return code for skipped tests to match Automake convention.
836 set_tests_properties("${TEST}" PROPERTIES
837 ENVIRONMENT "srcdir=${CMAKE_CURRENT_LIST_DIR}/tests"