diff --git a/.cmake-format.yaml b/.cmake-format.yaml new file mode 100644 index 000000000..9c554da15 --- /dev/null +++ b/.cmake-format.yaml @@ -0,0 +1,245 @@ +_help_parse: Options affecting listfile parsing +parse: + _help_additional_commands: + - Specify structure for custom cmake functions + additional_commands: + foo: + flags: + - BAR + - BAZ + kwargs: + HEADERS: '*' + SOURCES: '*' + DEPENDS: '*' + _help_override_spec: + - Override configurations per-command where available + override_spec: {} + _help_vartags: + - Specify variable tags. + vartags: [] + _help_proptags: + - Specify property tags. + proptags: [] +_help_format: Options affecting formatting. +format: + _help_disable: + - Disable formatting entirely, making cmake-format a no-op + disable: false + _help_line_width: + - How wide to allow formatted cmake files + line_width: 80 + _help_tab_size: + - How many spaces to tab for indent + tab_size: 4 + _help_use_tabchars: + - If true, lines are indented using tab characters (utf-8 + - 0x09) instead of space characters (utf-8 0x20). + - In cases where the layout would require a fractional tab + - character, the behavior of the fractional indentation is + - governed by + use_tabchars: false + _help_fractional_tab_policy: + - If is True, then the value of this variable + - indicates how fractional indentions are handled during + - whitespace replacement. If set to 'use-space', fractional + - indentation is left as spaces (utf-8 0x20). If set to + - '`round-up` fractional indentation is replaced with a single' + - tab character (utf-8 0x09) effectively shifting the column + - to the next tabstop + fractional_tab_policy: use-space + _help_max_subgroups_hwrap: + - If an argument group contains more than this many sub-groups + - (parg or kwarg groups) then force it to a vertical layout. + max_subgroups_hwrap: 2 + _help_max_pargs_hwrap: + - If a positional argument group contains more than this many + - arguments, then force it to a vertical layout. + max_pargs_hwrap: 6 + _help_max_rows_cmdline: + - If a cmdline positional group consumes more than this many + - lines without nesting, then invalidate the layout (and nest) + max_rows_cmdline: 2 + _help_separate_ctrl_name_with_space: + - If true, separate flow control names from their parentheses + - with a space + separate_ctrl_name_with_space: false + _help_separate_fn_name_with_space: + - If true, separate function names from parentheses with a + - space + separate_fn_name_with_space: false + _help_dangle_parens: + - If a statement is wrapped to more than one line, than dangle + - the closing parenthesis on its own line. + dangle_parens: false + _help_dangle_align: + - If the trailing parenthesis must be 'dangled' on its on + - 'line, then align it to this reference: `prefix`: the start' + - 'of the statement, `prefix-indent`: the start of the' + - 'statement, plus one indentation level, `child`: align to' + - the column of the arguments + dangle_align: prefix + _help_min_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is smaller than this amount, then force reject + - nested layouts. + min_prefix_chars: 4 + _help_max_prefix_chars: + - If the statement spelling length (including space and + - parenthesis) is larger than the tab width by more than this + - amount, then force reject un-nested layouts. + max_prefix_chars: 10 + _help_max_lines_hwrap: + - If a candidate layout is wrapped horizontally but it exceeds + - this many lines, then reject the layout. + max_lines_hwrap: 2 + _help_line_ending: + - What style line endings to use in the output. + line_ending: unix + _help_command_case: + - Format command names consistently as 'lower' or 'upper' case + command_case: canonical + _help_keyword_case: + - Format keywords consistently as 'lower' or 'upper' case + keyword_case: unchanged + _help_always_wrap: + - A list of command names which should always be wrapped + always_wrap: [] + _help_enable_sort: + - If true, the argument lists which are known to be sortable + - will be sorted lexicographicall + enable_sort: true + _help_autosort: + - If true, the parsers may infer whether or not an argument + - list is sortable (without annotation). + autosort: false + _help_require_valid_layout: + - By default, if cmake-format cannot successfully fit + - everything into the desired linewidth it will apply the + - last, most aggressive attempt that it made. If this flag is + - True, however, cmake-format will print error, exit with non- + - zero status code, and write-out nothing + require_valid_layout: false + _help_layout_passes: + - A dictionary mapping layout nodes to a list of wrap + - decisions. See the documentation for more information. + layout_passes: {} +_help_markup: Options affecting comment reflow and formatting. +markup: + _help_bullet_char: + - What character to use for bulleted lists + bullet_char: '*' + _help_enum_char: + - What character to use as punctuation after numerals in an + - enumerated list + enum_char: . + _help_first_comment_is_literal: + - If comment markup is enabled, don't reflow the first comment + - block in each listfile. Use this to preserve formatting of + - your copyright/license statements. + first_comment_is_literal: false + _help_literal_comment_pattern: + - If comment markup is enabled, don't reflow any comment block + - which matches this (regex) pattern. Default is `None` + - (disabled). + literal_comment_pattern: null + _help_fence_pattern: + - Regular expression to match preformat fences in comments + - default= ``r'^\s*([`~]{3}[`~]*)(.*)$'`` + fence_pattern: ^\s*([`~]{3}[`~]*)(.*)$ + _help_ruler_pattern: + - Regular expression to match rulers in comments default= + - '``r''^\s*[^\w\s]{3}.*[^\w\s]{3}$''``' + ruler_pattern: ^\s*[^\w\s]{3}.*[^\w\s]{3}$ + _help_explicit_trailing_pattern: + - If a comment line matches starts with this pattern then it + - is explicitly a trailing comment for the preceding argument. + - Default is '#<' + explicit_trailing_pattern: '#<' + _help_hashruler_min_length: + - If a comment line starts with at least this many consecutive + - hash characters, then don't lstrip() them off. This allows + - for lazy hash rulers where the first hash char is not + - separated by space + hashruler_min_length: 10 + _help_canonicalize_hashrulers: + - If true, then insert a space between the first hash char and + - remaining hash chars in a hash ruler, and normalize its + - length to fill the column + canonicalize_hashrulers: true + _help_enable_markup: + - enable comment markup parsing and reflow + enable_markup: true +_help_lint: Options affecting the linter +lint: + _help_disabled_codes: + - a list of lint codes to disable + disabled_codes: [] + _help_function_pattern: + - regular expression pattern describing valid function names + function_pattern: '[0-9a-z_]+' + _help_macro_pattern: + - regular expression pattern describing valid macro names + macro_pattern: '[0-9A-Z_]+' + _help_global_var_pattern: + - regular expression pattern describing valid names for + - variables with global (cache) scope + global_var_pattern: '[A-Z][0-9A-Z_]+' + _help_internal_var_pattern: + - regular expression pattern describing valid names for + - variables with global scope (but internal semantic) + internal_var_pattern: _[A-Z][0-9A-Z_]+ + _help_local_var_pattern: + - regular expression pattern describing valid names for + - variables with local scope + local_var_pattern: '[a-z][a-z0-9_]+' + _help_private_var_pattern: + - regular expression pattern describing valid names for + - privatedirectory variables + private_var_pattern: _[0-9a-z_]+ + _help_public_var_pattern: + - regular expression pattern describing valid names for public + - directory variables + public_var_pattern: '[A-Z][0-9A-Z_]+' + _help_argument_var_pattern: + - regular expression pattern describing valid names for + - function/macro arguments and loop variables. + argument_var_pattern: '[a-z][a-z0-9_]+' + _help_keyword_pattern: + - regular expression pattern describing valid names for + - keywords used in functions or macros + keyword_pattern: '[A-Z][0-9A-Z_]+' + _help_max_conditionals_custom_parser: + - In the heuristic for C0201, how many conditionals to match + - within a loop in before considering the loop a parser. + max_conditionals_custom_parser: 2 + _help_min_statement_spacing: + - Require at least this many newlines between statements + min_statement_spacing: 1 + _help_max_statement_spacing: + - Require no more than this many newlines between statements + max_statement_spacing: 2 + max_returns: 6 + max_branches: 12 + max_arguments: 5 + max_localvars: 15 + max_statements: 50 +_help_encode: Options affecting file encoding +encode: + _help_emit_byteorder_mark: + - If true, emit the unicode byte-order mark (BOM) at the start + - of the file + emit_byteorder_mark: false + _help_input_encoding: + - Specify the encoding of the input file. Defaults to utf-8 + input_encoding: utf-8 + _help_output_encoding: + - Specify the encoding of the output file. Defaults to utf-8. + - Note that cmake only claims to support utf-8 so be careful + - when using anything else + output_encoding: utf-8 +_help_misc: Miscellaneous configurations options. +misc: + _help_per_command: + - A dictionary containing any per-command configuration + - overrides. Currently only `command_case` is supported. + per_command: {} diff --git a/.github/workflows/c-std.yml b/.github/workflows/c-std.yml index 44417bfad..a99cdb569 100644 --- a/.github/workflows/c-std.yml +++ b/.github/workflows/c-std.yml @@ -133,18 +133,30 @@ jobs: - name: Generate project files (cmake) if: matrix.builder == 'cmake' run: | - cmake -S . -B . -D CMAKE_BUILD_TYPE=Release -D ZLIB_BUILD_EXAMPLES=OFF ${{ matrix.os.cmake-opt }} + cmake -S . -B ./build1 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_TESTING=OFF env: CC: ${{ matrix.compiler }} CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Werror -Wall -Wextra + - name: Generate project files with tests (cmake) + if: matrix.builder == 'cmake' + run: | + cmake -S . -B ./build2 -D CMAKE_BUILD_TYPE=Release ${{ matrix.os.cmake-opt }} -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: -std=${{ matrix.std.value }} ${{ matrix.arch.compiler-opt }} -Wall -Wextra + - name: Compile source code (cmake) if: matrix.builder == 'cmake' - run: cmake --build . --config Release + run: cmake --build ./build1 --config Release + + - name: Compile source code with tests (cmake) + if: matrix.builder == 'cmake' + run: cmake --build ./build2 --config Release - name: Run test cases (cmake) if: matrix.builder == 'cmake' - run: ctest -C Release --output-on-failure --max-width 120 + run: ctest ./build2 -C Release --output-on-failure --max-width 120 msvc: @@ -196,13 +208,23 @@ jobs: - name: Generate project files (cmake) run: | - cmake -S . -B . ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release + cmake -S . -B ./build1 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_TESTING=OFF env: CC: ${{ matrix.compiler }} CFLAGS: /WX ${{ matrix.std.value }} + - name: Generate project files with tests (cmake) + run: | + cmake -S . -B ./build2 ${{ matrix.arch.value }} -D CMAKE_BUILD_TYPE=Release -DZLIB_BUILD_MINIZIP=ON -DMINIZIP_ENABLE_BZIP2=OFF + env: + CC: ${{ matrix.compiler }} + CFLAGS: ${{ matrix.std.value }} + - name: Compile source code (cmake) - run: cmake --build . --config Release -v + run: cmake --build ./build1 --config Release -v + + - name: Compile source code with tests(cmake) + run: cmake --build ./build2 --config Release -v - name: Run test cases (cmake) - run: ctest -C Release --output-on-failure --max-width 120 \ No newline at end of file + run: ctest ./build2 -C Release --output-on-failure --max-width 120 diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 36fb2493d..25a3b8124 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -11,59 +11,66 @@ jobs: - name: Ubuntu GCC os: ubuntu-latest compiler: gcc - cflags: -Werror -Wall -Wextra - - # Test out of source builds - - name: Ubuntu GCC OSB - os: ubuntu-latest - compiler: gcc - cflags: -Werror -Wall -Wextra - build-dir: ../build - src-dir: ../zlib + cflags: -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON - name: Ubuntu GCC -O3 os: ubuntu-latest compiler: gcc - cflags: -O3 -Werror -Wall -Wextra + cflags: -O3 -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON - name: Ubuntu Clang os: ubuntu-latest compiler: clang - cflags: -Werror -Wall -Wextra + cflags: -Wall -Wextra + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON - name: Ubuntu Clang Debug os: ubuntu-latest compiler: clang - cflags: -Werror -Wall -Wextra + cflags: -Wall -Wextra build-config: Debug + pkgtgt: package package_source + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON - name: Windows MSVC Win32 os: windows-latest compiler: cl - cflags: /WX /W3 + cflags: /W3 cmake-args: -A Win32 + pkgtgt: PACKAGE - name: Windows MSVC Win64 os: windows-latest compiler: cl - cflags: /WX /W3 - cmake-args: -A x64 + cflags: /W3 + cmake-args: -A x64 -DMINIZIP_ENABLE_BZIP2=OFF + pkgtgt: PACKAGE - name: Windows GCC os: windows-latest compiler: gcc - cflags: -Werror -Wall -Wextra - cmake-args: -G Ninja + cflags: -Wall -Wextra + cmake-args: -G Ninja -DMINIZIP_ENABLE_BZIP2=OFF + pkgtgt: package - name: macOS Clang os: macos-latest compiler: clang - cflags: -Werror -Wall -Wextra + cflags: -Wall -Wextra + pkgtgt: package + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON - name: macOS GCC os: macos-latest compiler: gcc-12 - cflags: -Werror -Wall -Wextra + cflags: -Wall -Wextra + pkgtgt: package + cmake-args: -DMINIZIP_ENABLE_BZIP2=ON steps: - name: Checkout repository @@ -72,20 +79,27 @@ jobs: - name: Install packages (Windows) if: runner.os == 'Windows' run: | - choco install --no-progress ninja ${{ matrix.packages }} + choco install --no-progress ninja + - name: Install packages (Linux) + if: runner.os == 'Linux' + run: | + sudo apt install libbz2-dev - name: Generate project files - run: cmake -S ${{ matrix.src-dir || '.' }} -B ${{ matrix.build-dir || '.' }} ${{ matrix.cmake-args }} -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }} + run: cmake -S . -B ../build ${{ matrix.cmake-args }} -D CMAKE_BUILD_TYPE=${{ matrix.build-config || 'Release' }} -DZLIB_BUILD_MINIZIP=ON env: CC: ${{ matrix.compiler }} CFLAGS: ${{ matrix.cflags }} - name: Compile source code - run: cmake --build ${{ matrix.build-dir || '.' }} --config ${{ matrix.build-config || 'Release' }} + run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }} - name: Run test cases run: ctest -C Release --output-on-failure --max-width 120 - working-directory: ${{ matrix.build-dir || '.' }} + working-directory: ../build + + - name: create packages + run: cmake --build ../build --config ${{ matrix.build-config || 'Release' }} -t ${{ matrix.pkgtgt }} - name: Upload build errors uses: actions/upload-artifact@v4 @@ -93,6 +107,6 @@ jobs: with: name: ${{ matrix.name }} (cmake) path: | - **/CMakeFiles/CMakeOutput.log - **/CMakeFiles/CMakeError.log + ../build/CMakeFiles/CMakeOutput.log + ../build/CMakeFiles/CMakeError.log retention-days: 7 diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml index 7789095e2..f19272c72 100644 --- a/.github/workflows/configure.yml +++ b/.github/workflows/configure.yml @@ -26,7 +26,7 @@ jobs: compiler: arm-linux-gnueabi-gcc configure-args: --warn chost: arm-linux-gnueabi - packages: qemu qemu-user gcc-arm-linux-gnueabi libc-dev-armel-cross + packages: qemu-system qemu-user gcc-arm-linux-gnueabi libc-dev-armel-cross qemu-run: qemu-arm -L /usr/arm-linux-gnueabi - name: Ubuntu GCC ARM HF @@ -34,7 +34,7 @@ jobs: compiler: arm-linux-gnueabihf-gcc configure-args: --warn chost: arm-linux-gnueabihf - packages: qemu qemu-user gcc-arm-linux-gnueabihf libc-dev-armhf-cross + packages: qemu-system qemu-user gcc-arm-linux-gnueabihf libc-dev-armhf-cross qemu-run: qemu-arm -L /usr/arm-linux-gnueabihf - name: Ubuntu GCC AARCH64 @@ -42,7 +42,7 @@ jobs: compiler: aarch64-linux-gnu-gcc configure-args: --warn chost: aarch64-linux-gnu - packages: qemu qemu-user gcc-aarch64-linux-gnu libc-dev-arm64-cross + packages: qemu-system qemu-user gcc-aarch64-linux-gnu libc-dev-arm64-cross qemu-run: qemu-aarch64 -L /usr/aarch64-linux-gnu - name: Ubuntu GCC PPC @@ -50,7 +50,7 @@ jobs: compiler: powerpc-linux-gnu-gcc configure-args: --warn --static chost: powerpc-linux-gnu - packages: qemu qemu-user gcc-powerpc-linux-gnu libc-dev-powerpc-cross + packages: qemu-system qemu-user gcc-powerpc-linux-gnu libc-dev-powerpc-cross qemu-run: qemu-ppc -L /usr/powerpc-linux-gnu cflags: -static ldflags: -static @@ -60,7 +60,7 @@ jobs: compiler: powerpc64-linux-gnu-gcc configure-args: --warn --static chost: powerpc-linux-gnu - packages: qemu qemu-user gcc-powerpc64-linux-gnu libc-dev-ppc64-cross + packages: qemu-system qemu-user gcc-powerpc64-linux-gnu libc-dev-ppc64-cross qemu-run: qemu-ppc64 -L /usr/powerpc64-linux-gnu cflags: -static ldflags: -static @@ -70,7 +70,7 @@ jobs: compiler: powerpc64le-linux-gnu-gcc configure-args: --warn chost: powerpc64le-linux-gnu - packages: qemu qemu-user gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross + packages: qemu-system qemu-user gcc-powerpc64le-linux-gnu libc-dev-ppc64el-cross qemu-run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu - name: Ubuntu GCC S390X @@ -78,7 +78,7 @@ jobs: compiler: s390x-linux-gnu-gcc configure-args: --warn --static chost: s390x-linux-gnu - packages: qemu qemu-user gcc-s390x-linux-gnu libc-dev-s390x-cross + packages: qemu-system qemu-user gcc-s390x-linux-gnu libc-dev-s390x-cross qemu-run: qemu-s390x -L /usr/s390x-linux-gnu cflags: -static ldflags: -static @@ -110,7 +110,7 @@ jobs: ${{ matrix.src-dir || '.' }}/configure ${{ matrix.configure-args }} env: CC: ${{ matrix.compiler }} - CFLAGS: ${{ matrix.cflags }} -Werror + CFLAGS: ${{ matrix.cflags }} LDFLAGS: ${{ matrix.ldflags }} CHOST: ${{ matrix.chost }} diff --git a/.github/workflows/msys-cygwin.yml b/.github/workflows/msys-cygwin.yml new file mode 100644 index 000000000..e76be9f0d --- /dev/null +++ b/.github/workflows/msys-cygwin.yml @@ -0,0 +1,77 @@ +name: mingw/cygwin + +on: [push, pull_request] + +jobs: + MSys: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + sys: [mingw32, mingw64, ucrt64, clang64] + name: MSys - ${{ matrix.sys }} + defaults: + run: + shell: msys2 {0} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2 + with: + msystem: ${{ matrix.sys }} + update: true + install: >- + make + pacboy: >- + toolchain:p + cmake:p + - name: Configure + run: | + cmake -G"Unix Makefiles" \ + -S . \ + -B build \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DMINIZIP_ENABLE_BZIP2=ON + - name: Build + run: cmake --build build --config Release + - name: Run tests + run: ctest --output-on-failure --test-dir build -C Release + + cygwin: + strategy: + fail-fast: false + runs-on: windows-latest + defaults: + run: + shell: C:\cygwin\bin\bash.exe --login -o igncr '{0}' + name: Cygwin + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Setup cygwin + uses: cygwin/cygwin-install-action@master + with: + packages: >- + cmake + cygwin-devel + gcc-core + gcc-g++ + ninja + - name: Configure + run: | + cmake /cygdrive/d/a/zlib/zlib \ + -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DZLIB_BUILD_MINIZIP=ON \ + -DMINIZIP_ENABLE_BZIP2=OFF \ + -G Ninja + - name: Build + run: cmake --build build --config Release -v -j1 + - name: Run tests + run: ctest --output-on-failure --test-dir build -C Release diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d9b58df8..d963e7c04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,99 +1,132 @@ -cmake_minimum_required(VERSION 2.4.4...3.15.0) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) +cmake_minimum_required(VERSION 3.12...3.31) -project(zlib C) +project( + zlib + LANGUAGES C + VERSION 1.4.1.1 + HOMEPAGE_URL "https://zlib.net/" + DESCRIPTION "a general-purpose lossless data-compression library") -set(VERSION "1.3.1.1") +# ============================================================================ +# CPack +# ============================================================================ +set(CPACK_PACKAGE_VENDOR "zlib-Project") +set(CPACK_PACKAGE_DESCRIPTION_FILE ${zlib_SOURCE_DIR}/README) +set(CPACK_RESOURCE_FILE_LICENSE ${zlib_SOURCE_DIR}/LICENSE) +set(CPACK_RESOURCE_FILE_README ${zlib_SOURCE_DIR}/README) -option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) +# ============================================================================ +# configuration +# ============================================================================ -set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") -set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") -set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") -set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") -set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") +option(ZLIB_BUILD_TESTING "Enable Zlib Examples as tests" ON) +option(ZLIB_BUILD_SHARED "Enable building zlib shared library" ON) +option(ZLIB_BUILD_STATIC "Enable building zlib static library" ON) +option(ZLIB_BUILD_MINIZIP "Enable building libminizip contrib library" OFF) +option(ZLIB_INSTALL "Enable installation of zlib" ON) +option(ZLIB_PREFIX "prefix for all types and library functions, see zconf.h.in" + OFF) +mark_as_advanced(ZLIB_PREFIX) -include(CheckTypeSize) +if(WIN32) + option(ZLIB_INSTALL_COMPAT_DLL "Install a copy as zlib1.dll" ON) +endif(WIN32) + +get_property(IS_MULTI GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + +if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI) + message(STATUS "No CMAKE_BUILD_TYPE set -- using Release") + set(CMAKE_BUILD_TYPE Release) +endif(NOT DEFINED CMAKE_BUILD_TYPE AND NOT IS_MULTI) + +include(CheckCSourceCompiles) include(CheckFunctionExists) include(CheckIncludeFile) -include(CheckCSourceCompiles) -enable_testing() +include(CMakePackageConfigHelpers) +include(CheckTypeSize) +include(CPack) +include(GNUInstallDirs) + +set(CPACK_INCLUDED TRUE) + +if(NOT ZLIB_CONF_WRITTEN) + set(Z_PREFIX ${ZLIB_PREFIX}) + set(CONF_OUT_FILE ${zlib_BINARY_DIR}/zconf.h.cmakein) + file(READ ${zlib_SOURCE_DIR}/zconf.h.in ZCONF_CONTENT LIMIT 245) + file(WRITE ${CONF_OUT_FILE} ${ZCONF_CONTENT}) + file(APPEND ${CONF_OUT_FILE} "#cmakedefine Z_PREFIX 1\n") + file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_STDARG_H 1\n") + file(APPEND ${CONF_OUT_FILE} "#cmakedefine HAVE_UNISTD_H 1\n") + file(READ ${zlib_SOURCE_DIR}/zconf.h.in ZCONF_CONTENT OFFSET 244) + set(FIRST_ITEM TRUE) + + foreach(item IN LISTS ZCONF_CONTENT) + if(FIRST_ITEM) + string(APPEND OUT_CONTENT ${item}) + set(FIRST_ITEM FALSE) + else(FIRST_ITEM) + string(APPEND OUT_CONTENT "\;" ${item}) + endif(FIRST_ITEM) + endforeach(item IN LISTS ${ZCONF_CONTENT}) -check_include_file(sys/types.h HAVE_SYS_TYPES_H) -check_include_file(stdint.h HAVE_STDINT_H) -check_include_file(stddef.h HAVE_STDDEF_H) + file(APPEND ${CONF_OUT_FILE} ${OUT_CONTENT}) + set(ZLIB_CONF_WRITTEN + TRUE + CACHE BOOL "zconf.h.cmakein was created") + mark_as_advanced(ZLIB_CONF_WRITTEN) +endif(NOT ZLIB_CONF_WRITTEN) # # Check to see if we have large file support # set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) -# We add these other definitions here because CheckTypeSize.cmake -# in CMake 2.4.x does not automatically do so and we want -# compatibility with CMake 2.4.x. -if(HAVE_SYS_TYPES_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) -endif() -if(HAVE_STDINT_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) -endif() -if(HAVE_STDDEF_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) -endif() check_type_size(off64_t OFF64_T) -if(HAVE_OFF64_T) - add_definitions(-D_LARGEFILE64_SOURCE=1) -endif() -set(CMAKE_REQUIRED_DEFINITIONS) # clear variable +unset(CMAKE_REQUIRED_DEFINITIONS) # clear variable # # Check for fseeko # check_function_exists(fseeko HAVE_FSEEKO) -if(NOT HAVE_FSEEKO) - add_definitions(-DNO_FSEEKO) -endif() + +# +# Check for stdarg.h +# +check_include_file(stdarg.h HAVE_STDARG_H) # # Check for unistd.h # -check_include_file(unistd.h Z_HAVE_UNISTD_H) +check_include_file(unistd.h HAVE_UNISTD_H) +# +# Check visibility attribute is supported +# if(MSVC) - set(CMAKE_DEBUG_POSTFIX "d") - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -endif() - -option(RENAME_ZCONF "Rename the zconf when building out of source" ON) -if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND RENAME_ZCONF) - # If we're doing an out of source build and the user has a zconf.h - # in their source tree... - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) - message(STATUS "Renaming") - message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") - message(STATUS "to 'zconf.h.included' because this file is included with zlib") - message(STATUS "but CMake generates it automatically in the build directory.") - file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) - endif() -endif() - -set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) - - -#============================================================================ + set(CMAKE_REQUIRED_FLAGS "-WX") +else(MSVC) + set(CMAKE_REQUIRED_FLAGS "-WError") +endif(MSVC) + +check_c_source_compiles( + " + #include + static void f(void) __attribute__ ((visibility(\"hidden\"))); + int main(void) {return 0;} + " + HAVE___ATTR__VIS_HIDDEN) + +unset(CMAKE_COMPILE_FLAGS) +set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc) +configure_file(${zlib_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY) +configure_file(${zlib_BINARY_DIR}/zconf.h.cmakein ${zlib_BINARY_DIR}/zconf.h) +include_directories(${zlib_BINARY_DIR} ${zlib_SOURCE_DIR}) + +# ============================================================================ # zlib -#============================================================================ +# ============================================================================ + +set(ZLIB_PUBLIC_HDRS ${zlib_BINARY_DIR}/zconf.h zlib.h) -set(ZLIB_PUBLIC_HDRS - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h - zlib.h -) set(ZLIB_PRIVATE_HDRS crc32.h deflate.h @@ -103,8 +136,8 @@ set(ZLIB_PRIVATE_HDRS inflate.h inftrees.h trees.h - zutil.h -) + zutil.h) + set(ZLIB_SRCS adler32.c compress.c @@ -120,104 +153,182 @@ set(ZLIB_SRCS inffast.c trees.c uncompr.c - zutil.c -) - -if(NOT MINGW) - set(ZLIB_DLL_SRCS - win32/zlib1.rc # If present will override custom build rule below. - ) -endif() - -# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) -string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" - "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) - -if(MINGW) - # This gets us DLL resource information when compiling on MinGW. - if(NOT CMAKE_RC_COMPILER) - set(CMAKE_RC_COMPILER windres.exe) - endif() - - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - COMMAND ${CMAKE_RC_COMPILER} - -D GCC_WINDRES - -I ${CMAKE_CURRENT_SOURCE_DIR} - -I ${CMAKE_CURRENT_BINARY_DIR} - -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) - set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) -endif(MINGW) - -add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -target_include_directories(zlib PUBLIC - $ - $) -add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -target_include_directories(zlibstatic PUBLIC - $ - $) -set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) -set_target_properties(zlib PROPERTIES SOVERSION 1) - -if(NOT CYGWIN) - # This property causes shared libraries on Linux to have the full version - # encoded into their final filename. We disable this on Cygwin because - # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll - # seems to be the default. - # - # This has no effect with MSVC, on that platform the version info for - # the DLL comes from the resource file win32/zlib1.rc - set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) -endif() - -if(UNIX) - # On unix-like platforms the library is almost always called libz - set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) - if(NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) - set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") - endif() -elseif(BUILD_SHARED_LIBS AND WIN32) - # Creates zlib1.dll when building shared library version - set_target_properties(zlib PROPERTIES SUFFIX "1.dll") -endif() - -if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - install(TARGETS zlib zlibstatic - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" - LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) -endif() -if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") -endif() - -#============================================================================ -# Example binaries -#============================================================================ -if(ZLIB_BUILD_EXAMPLES) - add_executable(example test/example.c) - target_link_libraries(example zlib) - add_test(example example) - - add_executable(minigzip test/minigzip.c) - target_link_libraries(minigzip zlib) - - if(HAVE_OFF64_T) - add_executable(example64 test/example.c) - target_link_libraries(example64 zlib) - set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - add_test(example64 example64) - - add_executable(minigzip64 test/minigzip.c) - target_link_libraries(minigzip64 zlib) - set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - endif() -endif() + zutil.c) + +set_source_files_properties( + win32/zlib1.rc + PROPERTIES COMPILE_FLAGS + $<$:-DGCC_WINDRES>) + +if(WIN32) + set(zlib_static_suffix "s") + set(CMAKE_DEBUG_POSTFIX "d") +endif(WIN32) + +if(ZLIB_BUILD_SHARED) + add_library( + zlib SHARED ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS} + $<$,$>:win32/zlib1.rc>) + add_library(ZLIB::ZLIB ALIAS zlib) + target_include_directories( + zlib + PUBLIC $ + $ + $) + target_compile_definitions( + zlib + PRIVATE $<$:NO_FSEEKO> + $<$:HAVE_HIDDEN> + $<$:_CRT_SECURE_NO_DEPRECATE> + $<$:_CRT_NONSTDC_NO_DEPRECATE> + PUBLIC $<$:_LARGEFILE64_SOURCE=1>) + set(INSTALL_VERSION ${zlib_VERSION}) + + if(NOT CYGWIN) + set_target_properties(zlib PROPERTIES SOVERSION ${zlib_VERSION_MAJOR} + VERSION ${INSTALL_VERSION}) + endif(NOT CYGWIN) + + set_target_properties( + zlib + PROPERTIES DEFINE_SYMBOL ZLIB_DLL + EXPORT_NAME ZLIB + OUTPUT_NAME z) + if(UNIX + AND NOT APPLE + AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX)) + # On unix-like platforms the library is almost always called libz + set_target_properties( + zlib + PROPERTIES LINK_FLAGS + "-Wl,--version-script,\"${zlib_SOURCE_DIR}/zlib.map\"") + endif( + UNIX + AND NOT APPLE + AND NOT (CMAKE_SYSTEM_NAME STREQUAL AIX)) +endif(ZLIB_BUILD_SHARED) + +if(ZLIB_BUILD_STATIC) + add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} + ${ZLIB_PRIVATE_HDRS}) + add_library(ZLIB::ZLIBSTATIC ALIAS zlibstatic) + target_include_directories( + zlibstatic + PUBLIC $ + $ + $) + target_compile_definitions( + zlibstatic + PRIVATE $<$:NO_FSEEKO> + $<$:HAVE_HIDDEN> + $<$:_CRT_SECURE_NO_DEPRECATE> + $<$:_CRT_NONSTDC_NO_DEPRECATE> + PUBLIC $<$:_LARGEFILE64_SOURCE=1>) + set_target_properties( + zlibstatic PROPERTIES EXPORT_NAME ZLIBSTATIC OUTPUT_NAME + z${zlib_static_suffix}) +endif(ZLIB_BUILD_STATIC) + +if(ZLIB_INSTALL) + if(ZLIB_BUILD_SHARED) + install( + TARGETS zlib + COMPONENT Runtime + EXPORT zlibSharedExport + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install( + EXPORT zlibSharedExport + FILE ZLIB-shared.cmake + NAMESPACE ZLIB:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + if(ZLIB_INSTALL_COMPAT_DLL) + install( + FILES $ + COMPONENT Runtime + RENAME zlib1.dll + DESTINATION "${CMAKE_INSTALL_BINDIR}") + endif(ZLIB_INSTALL_COMPAT_DLL) + + if(MSVC) + install( + FILES $ + COMPONENT Runtime + DESTINATION ${CMAKE_INSTALL_BINDIR} + CONFIGURATIONS Debug OR RelWithDebInfo + OPTIONAL) + endif(MSVC) + endif(ZLIB_BUILD_SHARED) + + if(ZLIB_BUILD_STATIC) + install( + TARGETS zlibstatic + COMPONENT Development + EXPORT zlibStaticExport + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + install( + EXPORT zlibStaticExport + FILE ZLIB-static.cmake + NAMESPACE ZLIB:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + + if(ZLIB_INSTALL_COMPAT_DLL AND MINGW) + install( + FILES $ + COMPONENT Development + RENAME libz.dll.a + DESTINATION "${CMAKE_INSTALL_LIBDIR}") + endif(ZLIB_INSTALL_COMPAT_DLL AND MINGW) + endif(ZLIB_BUILD_STATIC) + + configure_package_config_file( + ${zlib_SOURCE_DIR}/zlibConfig.cmake.in + ${zlib_BINARY_DIR}/ZLIBConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + + write_basic_package_version_file( + "${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake" + VERSION "${zlib_VERSION}" + COMPATIBILITY AnyNewerVersion) + + install(FILES ${zlib_BINARY_DIR}/ZLIBConfig.cmake + ${zlib_BINARY_DIR}/ZLIBConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/zlib) + install( + FILES ${ZLIB_PUBLIC_HDRS} + COMPONENT Development + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + install( + FILES zlib.3 + COMPONENT Docs + DESTINATION "${CMAKE_INSTALL_MANDIR}/man3") + install( + FILES LICENSE + doc/algorithm.txt + doc/crc-doc.1.0.pdf + doc/rfc1950.txt + doc/rfc1951.txt + doc/rfc1952.txt + doc/txtvsbin.txt + COMPONENT Docs + DESTINATION "${CMAKE_INSTALL_DOCDIR}/zlib") + install( + FILES ${ZLIB_PC} + COMPONENT Development + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +endif(ZLIB_INSTALL) + +# ============================================================================ +# Tests +# ============================================================================ +if(ZLIB_BUILD_TESTING) + enable_testing() + add_subdirectory(test) +endif(ZLIB_BUILD_TESTING) + +if(ZLIB_BUILD_MINIZIP) + add_subdirectory(contrib/minizip/) +endif(ZLIB_BUILD_MINIZIP) diff --git a/Makefile.in b/Makefile.in index c00625bb0..5da4ace7a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -13,6 +13,8 @@ # make install prefix=$HOME CC=cc +GCOV=GCOV +LLVM_GCOV_FLAG=LLMV_GCOV_FLAG CFLAGS=-O #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 @@ -113,15 +115,19 @@ test64: all64 @rm -f tmp64_$$ infcover.o: $(SRCDIR)test/infcover.c $(SRCDIR)zlib.h zconf.h - $(CC) $(CFLAGS) $(ZINCOUT) -c -o $@ $(SRCDIR)test/infcover.c + $(CC) $(CFLAGS) $(ZINCOUT) -c -coverage -o $@ $(SRCDIR)test/infcover.c infcover: infcover.o libz.a - $(CC) $(CFLAGS) -o $@ infcover.o libz.a + $(CC) $(CFLAGS) -coverage -o $@ infcover.o libz.a cover: infcover +ifdef $(GCOV) rm -f *.gcda ${QEMU_RUN} ./infcover - gcov inf*.c + ${GCOV} ${LLVM_GCOV_FLAG} inf*.c -o ./infcover.gcda +else + @echo 'cover disabled as no suitable gcov was found' +endif libz.a: $(OBJS) $(AR) $(ARFLAGS) $@ $(OBJS) diff --git a/README-cmake.md b/README-cmake.md new file mode 100644 index 000000000..7258f9cad --- /dev/null +++ b/README-cmake.md @@ -0,0 +1,83 @@ +# For building with cmake at least version 3.12 (minizip 3.12) is needed + +In most cases the usual + + cmake -S . -B build -D CMAKE_BUILD_TYPE=Release + +will create everything you need, however if you want something off default you can adjust several options fit your needs. +Every option is list below (excluding the cmake-standard options), they can be set via cmake-gui or on cmdline with + + -D