|
| 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(libbz2) |
| 31 | + |
| 32 | +function(require_var var) |
| 33 | + if (NOT DEFINED ${var}) |
| 34 | + message(FATAL_ERROR "${var} needs to be set; was '${var}'") |
| 35 | + endif() |
| 36 | +endfunction() |
| 37 | + |
| 38 | +require_var(BZIP2_ROOT) |
| 39 | +require_var(BZIP2_VERSION_MAJOR) |
| 40 | +require_var(BZIP2_VERSION_MINOR) |
| 41 | +require_var(BZIP2_VERSION_PATCH) |
| 42 | + |
| 43 | +set(BZIP2_VERSION "${BZIP2_VERSION_MAJOR}.${BZIP2_VERSION_MINOR}.${BZIP2_VERSION_PATCH}") |
| 44 | + |
| 45 | +message(VERBOSE "Building libbz2 version: ${BZIP2_VERSION}") |
| 46 | + |
| 47 | +set(PACKAGE_NAME "bzip2") |
| 48 | +set(TARGET_LIBBZ2 "bz2") |
| 49 | +set(BZIP2_SRC "${BZIP2_ROOT}/${PACKAGE_NAME}-${BZIP2_VERSION}") |
| 50 | + |
| 51 | +add_library(${TARGET_LIBBZ2} STATIC) |
| 52 | + |
| 53 | +# we want '-fPIC' even for the static lib |
| 54 | +set_target_properties(${TARGET_LIBBZ2} PROPERTIES POSITION_INDEPENDENT_CODE TRUE) |
| 55 | + |
| 56 | +# preprocessor defines for all platforms |
| 57 | +target_compile_definitions(${TARGET_LIBBZ2} PRIVATE _FILE_OFFSET_BITS=64) |
| 58 | + |
| 59 | +if(WIN32) |
| 60 | + target_compile_options(${TARGET_LIBBZ2} PRIVATE /Z7 /O2 /Wall) |
| 61 | +else() |
| 62 | + target_compile_options(${TARGET_LIBBZ2} PRIVATE -Wall -Winline -O2 -g) |
| 63 | +endif() |
| 64 | + |
| 65 | +# don't install into the system but into the MX project's output dir |
| 66 | +set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) |
| 67 | + |
| 68 | +# using glob patterns is not recommended: https://cmake.org/cmake/help/latest/command/file.html#glob |
| 69 | +target_sources(${TARGET_LIBBZ2} PRIVATE |
| 70 | + "${BZIP2_SRC}/bzlib.h" |
| 71 | + "${BZIP2_SRC}/blocksort.c" |
| 72 | + "${BZIP2_SRC}/huffman.c" |
| 73 | + "${BZIP2_SRC}/crctable.c" |
| 74 | + "${BZIP2_SRC}/randtable.c" |
| 75 | + "${BZIP2_SRC}/compress.c" |
| 76 | + "${BZIP2_SRC}/decompress.c" |
| 77 | + "${BZIP2_SRC}/bzlib.c" |
| 78 | +) |
0 commit comments