|
| 1 | +# |
| 2 | +# Copyright (c) 2023, Oracle and/or its affiliates. |
| 3 | +# |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without modification, are |
| 7 | +# permitted provided that the following conditions are met: |
| 8 | +# |
| 9 | +# 1. Redistributions of source code must retain the above copyright notice, this list of |
| 10 | +# conditions and the following disclaimer. |
| 11 | +# |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this list of |
| 13 | +# conditions and the following disclaimer in the documentation and/or other materials provided |
| 14 | +# with the distribution. |
| 15 | +# 3. Neither the name of the copyright holder nor the names of its contributors may be used to |
| 16 | +# endorse or promote products derived from this software without specific prior written |
| 17 | +# permission. |
| 18 | +# |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
| 20 | +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 22 | +# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 24 | +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 25 | +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 | +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 27 | +# OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +# |
| 29 | +cmake_minimum_required(VERSION 3.22) |
| 30 | +project(python-liblzma) |
| 31 | + |
| 32 | +function(require_var var) |
| 33 | + if (NOT ${var}) |
| 34 | + message(FATAL_ERROR "${var} needs to be set") |
| 35 | + endif() |
| 36 | +endfunction() |
| 37 | + |
| 38 | +require_var(XZ_SRC) |
| 39 | + |
| 40 | +set(XZ_VERSION "${XZ_VERSION_MAJOR}.${XZ_VERSION_MINOR}.${XZ_VERSION_PATCH}") |
| 41 | + |
| 42 | +message(VERBOSE "Building liblzma version: ${XZ_VERSION}") |
| 43 | + |
| 44 | +set(PACKAGE_NAME "xz") |
| 45 | +set(TARGET_LZMA "lzma") |
| 46 | +set(TARGET_LZMASUPPORT "lzmasupport") |
| 47 | +set(XZ_ROOT "${XZ_SRC}/${PACKAGE_NAME}-${XZ_VERSION}") |
| 48 | +set(SRC_DIR "${XZ_ROOT}/src") |
| 49 | +set(API_DIR "${XZ_ROOT}/src/liblzma/api") |
| 50 | + |
| 51 | +set(XZ_HEADERS |
| 52 | + "${API_DIR}/lzma.h" |
| 53 | + "${API_DIR}/lzma/version.h" |
| 54 | + "${API_DIR}/lzma/base.h" |
| 55 | + "${API_DIR}/lzma/vli.h" |
| 56 | + "${API_DIR}/lzma/check.h" |
| 57 | + "${API_DIR}/lzma/filter.h" |
| 58 | + "${API_DIR}/lzma/bcj.h" |
| 59 | + "${API_DIR}/lzma/delta.h" |
| 60 | + "${API_DIR}/lzma/lzma12.h" |
| 61 | + "${API_DIR}/lzma/container.h" |
| 62 | + "${API_DIR}/lzma/stream_flags.h" |
| 63 | + "${API_DIR}/lzma/block.h" |
| 64 | + "${API_DIR}/lzma/index.h" |
| 65 | + "${API_DIR}/lzma/index_hash.h" |
| 66 | + "${API_DIR}/lzma/hardware.h" |
| 67 | +) |
| 68 | + |
| 69 | +add_library(${TARGET_LZMA} STATIC) |
| 70 | +add_library(${TARGET_LZMASUPPORT} SHARED) |
| 71 | + |
| 72 | +# we want '-fPIC' even for the static lib |
| 73 | +set_target_properties(${TARGET_LZMA} PROPERTIES POSITION_INDEPENDENT_CODE TRUE) |
| 74 | + |
| 75 | +# preprocessor defines for all platforms |
| 76 | +target_compile_definitions(${TARGET_LZMA} PRIVATE HAVE_CONFIG_H) |
| 77 | +target_compile_definitions(${TARGET_LZMASUPPORT} PRIVATE NDEBUG) |
| 78 | + |
| 79 | +if(WIN32) |
| 80 | + target_compile_options(${TARGET_LZMA} PRIVATE /Z7 /O2) |
| 81 | + target_compile_options(${TARGET_LZMASUPPORT} PRIVATE /Z7 /O2 /WX) |
| 82 | +else() |
| 83 | + target_compile_options(${TARGET_LZMA} PRIVATE -fPIC -DPIC -g -O2) |
| 84 | + target_compile_definitions(${TARGET_LZMA} PRIVATE PIC) |
| 85 | + |
| 86 | + target_compile_options(${TARGET_LZMASUPPORT} PRIVATE -g -O3) |
| 87 | +endif() |
| 88 | + |
| 89 | +# don't install into the system but into the MX project's output dir |
| 90 | +set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) |
| 91 | + |
| 92 | +# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob |
| 93 | +target_sources(${TARGET_LZMA} PRIVATE ${XZ_HEADERS}) |
| 94 | + |
| 95 | +target_sources(${TARGET_LZMA} PRIVATE |
| 96 | + "${API_DIR}/lzma.h" |
| 97 | + "${SRC_DIR}/common/tuklib_physmem.c" |
| 98 | + "${SRC_DIR}/liblzma/common/vli_size.c" |
| 99 | + "${SRC_DIR}/liblzma/common/hardware_physmem.c" |
| 100 | + "${SRC_DIR}/liblzma/common/filter_encoder.c" |
| 101 | + "${SRC_DIR}/liblzma/common/block_buffer_decoder.c" |
| 102 | + "${SRC_DIR}/liblzma/common/index.c" |
| 103 | + "${SRC_DIR}/liblzma/common/stream_encoder.c" |
| 104 | + "${SRC_DIR}/liblzma/common/block_encoder.c" |
| 105 | + "${SRC_DIR}/liblzma/common/easy_encoder.c" |
| 106 | + "${SRC_DIR}/liblzma/common/easy_buffer_encoder.c" |
| 107 | + "${SRC_DIR}/liblzma/common/block_util.c" |
| 108 | + "${SRC_DIR}/liblzma/common/filter_buffer_decoder.c" |
| 109 | + "${SRC_DIR}/liblzma/common/stream_flags_encoder.c" |
| 110 | + "${SRC_DIR}/liblzma/common/easy_preset.c" |
| 111 | + "${SRC_DIR}/liblzma/common/index_encoder.c" |
| 112 | + "${SRC_DIR}/liblzma/common/common.c" |
| 113 | + "${SRC_DIR}/liblzma/common/block_header_encoder.c" |
| 114 | + "${SRC_DIR}/liblzma/common/vli_encoder.c" |
| 115 | + "${SRC_DIR}/liblzma/common/block_header_decoder.c" |
| 116 | + "${SRC_DIR}/liblzma/common/stream_buffer_encoder.c" |
| 117 | + "${SRC_DIR}/liblzma/common/block_buffer_encoder.c" |
| 118 | + "${SRC_DIR}/liblzma/common/alone_decoder.c" |
| 119 | + "${SRC_DIR}/liblzma/common/auto_decoder.c" |
| 120 | + "${SRC_DIR}/liblzma/common/stream_flags_common.c" |
| 121 | + "${SRC_DIR}/liblzma/common/easy_decoder_memusage.c" |
| 122 | + "${SRC_DIR}/liblzma/common/easy_encoder_memusage.c" |
| 123 | + "${SRC_DIR}/liblzma/common/filter_buffer_encoder.c" |
| 124 | + "${SRC_DIR}/liblzma/common/filter_decoder.c" |
| 125 | + "${SRC_DIR}/liblzma/common/filter_flags_encoder.c" |
| 126 | + "${SRC_DIR}/liblzma/common/filter_common.c" |
| 127 | + "${SRC_DIR}/liblzma/common/alone_encoder.c" |
| 128 | + "${SRC_DIR}/liblzma/common/block_decoder.c" |
| 129 | + "${SRC_DIR}/liblzma/common/filter_flags_decoder.c" |
| 130 | + "${SRC_DIR}/liblzma/common/index_decoder.c" |
| 131 | + "${SRC_DIR}/liblzma/common/stream_buffer_decoder.c" |
| 132 | + "${SRC_DIR}/liblzma/common/stream_flags_decoder.c" |
| 133 | + "${SRC_DIR}/liblzma/common/index_hash.c" |
| 134 | + "${SRC_DIR}/liblzma/common/stream_decoder.c" |
| 135 | + "${SRC_DIR}/liblzma/common/vli_decoder.c" |
| 136 | + "${SRC_DIR}/liblzma/check/crc64_table.c" |
| 137 | + "${SRC_DIR}/liblzma/check/crc32_table.c" |
| 138 | + "${SRC_DIR}/liblzma/check/crc64_fast.c" |
| 139 | + "${SRC_DIR}/liblzma/check/crc32_fast.c" |
| 140 | + "${SRC_DIR}/liblzma/check/check.c" |
| 141 | + "${SRC_DIR}/liblzma/check/sha256.c" |
| 142 | + "${SRC_DIR}/liblzma/lz/lz_encoder.c" |
| 143 | + "${SRC_DIR}/liblzma/lz/lz_encoder_mf.c" |
| 144 | + "${SRC_DIR}/liblzma/lz/lz_decoder.c" |
| 145 | + "${SRC_DIR}/liblzma/lzma/lzma_encoder_presets.c" |
| 146 | + "${SRC_DIR}/liblzma/lzma/lzma_encoder.c" |
| 147 | + "${SRC_DIR}/liblzma/lzma/lzma_encoder_optimum_fast.c" |
| 148 | + "${SRC_DIR}/liblzma/lzma/lzma_encoder_optimum_normal.c" |
| 149 | + "${SRC_DIR}/liblzma/lzma/lzma2_encoder.c" |
| 150 | + "${SRC_DIR}/liblzma/lzma/lzma2_decoder.c" |
| 151 | + "${SRC_DIR}/liblzma/lzma/lzma_decoder.c" |
| 152 | + "${SRC_DIR}/liblzma/lzma/fastpos_table.c" |
| 153 | + "${SRC_DIR}/liblzma/rangecoder/price_table.c" |
| 154 | + "${SRC_DIR}/liblzma/delta/delta_common.c" |
| 155 | + "${SRC_DIR}/liblzma/delta/delta_encoder.c" |
| 156 | + "${SRC_DIR}/liblzma/delta/delta_decoder.c" |
| 157 | + "${SRC_DIR}/liblzma/simple/simple_coder.c" |
| 158 | + "${SRC_DIR}/liblzma/simple/simple_encoder.c" |
| 159 | + "${SRC_DIR}/liblzma/simple/simple_decoder.c" |
| 160 | + "${SRC_DIR}/liblzma/simple/powerpc.c" |
| 161 | + "${SRC_DIR}/liblzma/simple/x86.c" |
| 162 | + "${SRC_DIR}/liblzma/simple/arm.c" |
| 163 | + "${SRC_DIR}/liblzma/simple/ia64.c" |
| 164 | + "${SRC_DIR}/liblzma/simple/sparc.c" |
| 165 | + "${SRC_DIR}/liblzma/simple/armthumb.c" |
| 166 | +) |
| 167 | + |
| 168 | + |
| 169 | +target_include_directories(${TARGET_LZMA} PRIVATE |
| 170 | + "." |
| 171 | + "${SRC_DIR}/liblzma" |
| 172 | + "${SRC_DIR}/liblzma/api" |
| 173 | + "${SRC_DIR}/liblzma/common" |
| 174 | + "${SRC_DIR}/liblzma/check" |
| 175 | + "${SRC_DIR}/liblzma/lz" |
| 176 | + "${SRC_DIR}/liblzma/rangecoder" |
| 177 | + "${SRC_DIR}/liblzma/lzma" |
| 178 | + "${SRC_DIR}/liblzma/delta" |
| 179 | + "${SRC_DIR}/liblzma/simple" |
| 180 | + "${SRC_DIR}/common" |
| 181 | +) |
| 182 | + |
| 183 | +target_include_directories(${TARGET_LZMASUPPORT} PRIVATE ${API_DIR}) |
| 184 | +target_sources(${TARGET_LZMASUPPORT} PRIVATE "src/lzma.c") |
| 185 | +target_link_libraries(${TARGET_LZMASUPPORT} PRIVATE ${TARGET_LZMA}) |
| 186 | + |
| 187 | +install(TARGETS ${TARGET_LZMASUPPORT} DESTINATION bin) |
0 commit comments