Skip to content

Commit

Permalink
Remove ZLIB_ENABLE_LFS
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-park committed Nov 2, 2023
1 parent d6fb381 commit cf5e894
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 39 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ env:

jobs:
build:
name: ${{ matrix.preset }}-${{ matrix.config }}-${{ matrix.lfs }}-${{ matrix.sanitize }}
name: ${{ matrix.preset }}-${{ matrix.config }}-${{ matrix.sanitize }}
strategy:
fail-fast: false
matrix:
preset: [linux-clang, linux-gcc, macos, windows]
config: [Debug, Release]
lfs: [OFF, ON]
sanitize: [address, thread, undefined, leak, memory]
exclude:
- { preset: linux-gcc, sanitize: memory }
Expand Down Expand Up @@ -49,7 +48,6 @@ jobs:
cmake --preset ${{ matrix.preset }}
-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED=NO
-DCPM_SOURCE_CACHE="${{ env.cpm-path }}"
-DZLIB_ENABLE_LFS=${{ matrix.lfs }}
-DZLIB_SANITIZE=${{ matrix.sanitize }}
- name: Build
Expand All @@ -62,13 +60,12 @@ jobs:
run: cmake --build --preset ${{ matrix.preset }} --config ${{ matrix.config }} -t install

build-mobile:
name: ${{ matrix.preset }}-${{ matrix.config }}-${{ matrix.lfs }}
name: ${{ matrix.preset }}-${{ matrix.config }}
strategy:
fail-fast: false
matrix:
preset: [android, ios]
config: [Debug, Release]
lfs: [OFF, ON]
include:
- { preset: android, os: ubuntu-latest }
- { preset: ios, os: macos-latest }
Expand All @@ -91,7 +88,6 @@ jobs:
run: >
cmake --preset ${{ matrix.preset }}
-DCPM_SOURCE_CACHE=${{ env.cpm-path }}
-DZLIB_ENABLE_LFS=${{ matrix.lfs }}
- name: Build
run: cmake --build --preset ${{ matrix.preset }} --config ${{ matrix.config }}
Expand All @@ -100,14 +96,13 @@ jobs:
run: cmake --build --preset ${{ matrix.preset }} --config ${{ matrix.config }} -t install

build-bsd:
name: ${{ matrix.preset }}-${{ matrix.arch }}-${{ matrix.config }}-${{ matrix.lfs }}
name: ${{ matrix.preset }}-${{ matrix.arch }}-${{ matrix.config }}
strategy:
fail-fast: false
matrix:
preset: [freebsd, netbsd, openbsd]
arch: [arm64, x86_64]
config: [Debug, Release]
lfs: [OFF, ON]
exclude:
- { preset: netbsd, arch: arm64 }
include:
Expand All @@ -133,7 +128,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.config }} \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install \
-DCPM_SOURCE_CACHE=${{ env.cpm-path }} \
-DZLIB_ENABLE_LFS=${{ matrix.lfs }} \
-DZLIB_INSTALL=ON \
-DZLIB_TEST=ON
cmake --build build
Expand All @@ -143,13 +137,12 @@ jobs:
cmake --install build
build-msys2:
name: msys2-${{ matrix.preset }}-${{ matrix.config }}-${{ matrix.lfs }}
name: msys2-${{ matrix.preset }}-${{ matrix.config }}
strategy:
fail-fast: false
matrix:
preset: [mingw64, mingw32, ucrt64, clang64]
config: [Debug, Release]
lfs: [OFF, ON]
include:
- { preset: mingw64, env: x86_64 }
- { preset: mingw32, env: i686 }
Expand Down Expand Up @@ -181,7 +174,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.config }}
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/install
-DCPM_SOURCE_CACHE=${{ env.cpm-path }}
-DZLIB_ENABLE_LFS=${{ matrix.lfs }}
-DZLIB_INSTALL=ON
-DZLIB_TEST=ON
Expand Down
99 changes: 77 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.25)

project(
zlib-cmake
Expand All @@ -8,13 +8,13 @@ project(
LANGUAGES C
)

include(CheckIncludeFile)
include(CheckTypeSize)
include(CheckFunctionExists)
include(FetchContent)
include(cmake/GetCPM.cmake)
include(cmake/UseSanitizer.cmake)

# Custom options
option(ZLIB_ENABLE_LFS "Enable Large-File Support (LFS) on 32-bit system" OFF)
option(ZLIB_INSTALL "Install zlib and CMake targets" OFF)
option(ZLIB_TEST "Enable testing and build tests" OFF)

Expand All @@ -35,7 +35,6 @@ CPMAddPackage(
)

# Modify zlib source
check_include_file(unistd.h Z_HAVE_UNISTD_H)
file(REMOVE
${zlib-source_SOURCE_DIR}/CMakeLists.txt
${zlib-source_SOURCE_DIR}/zconf.h
Expand Down Expand Up @@ -130,11 +129,21 @@ if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(ZLIB PUBLIC ZLIB_DLL)
endif()

if(ZLIB_ENABLE_LFS)
target_compile_definitions(ZLIB PUBLIC
_LARGEFILE64_SOURCE
_FILE_OFFSET_BITS=64
)
block()

set(CMAKE_REQUIRED_DEFINITIONS _LARGEFILE64_SOURCE)
check_type_size(off64_t OFF64_T)

if(HAVE_OFF64_T)
target_compile_definitions(ZLIB PUBLIC _LARGEFILE64_SOURCE)
endif()

endblock()

check_function_exists(fseeko HAVE_FSEEKO)

if(NOT HAVE_FSEEKO)
target_compile_definitions(ZLIB PUBLIC NO_FSEEKO)
endif()

# Install zlib
Expand Down Expand Up @@ -182,19 +191,34 @@ endif()
if(ZLIB_TEST AND NOT CMAKE_CROSSCOMPILING)
include(CTest)

add_executable(example ${zlib_SOURCE_DIR}/test/example.c)
target_link_libraries(example PRIVATE ZLIB::ZLIB)
add_test(
NAME test_example
COMMAND example
)
function(add_test_files)
foreach(test_file IN LISTS ARGN)
message(STATUS "add ${test_file}")

add_executable(infcover ${zlib_SOURCE_DIR}/test/infcover.c)
target_link_libraries(infcover PRIVATE ZLIB::ZLIB)
add_test(
NAME test_infcover
COMMAND infcover
)
add_executable(${test_file} ${zlib_SOURCE_DIR}/test/${test_file}.c)
target_link_libraries(${test_file} PRIVATE ZLIB::ZLIB)
add_test(
NAME test_${test_file}
COMMAND ${test_file}
)
list(APPEND ZLIB_TEST_LIST "test_${test_file}")

if(HAVE_OFF64_T)
add_executable(${test_file}64 ${zlib_SOURCE_DIR}/test/${test_file}.c)
target_link_libraries(${test_file}64 PRIVATE ZLIB::ZLIB)
target_compile_definitions(${test_file}64 PRIVATE _FILE_OFFSET_BITS=64)
add_test(
NAME test_${test_file}64
COMMAND ${test_file}64
)
list(APPEND ZLIB_TEST_LIST "test_${test_file}64")
endif()
endforeach()

return(PROPAGATE ZLIB_TEST_LIST)
endfunction()

add_test_files(example infcover)

add_executable(minigzip ${zlib_SOURCE_DIR}/test/minigzip.c)
target_link_libraries(minigzip PRIVATE ZLIB::ZLIB)
Expand All @@ -213,18 +237,49 @@ if(ZLIB_TEST AND NOT CMAKE_CROSSCOMPILING)
COMMAND cmake -P ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/test_minigzip.cmake
COMMAND_EXPAND_LISTS
)
list(APPEND ZLIB_TEST_LIST test_minigzip)

if(HAVE_OFF64_T)
add_executable(minigzip64 ${zlib_SOURCE_DIR}/test/minigzip.c)
target_link_libraries(minigzip64 PRIVATE ZLIB::ZLIB)
target_compile_definitions(minigzip64 PRIVATE _FILE_OFFSET_BITS=64)
file(
GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/test_minigzip64.cmake
CONTENT
"execute_process(
COMMAND cmake -E echo hello world
COMMAND $<TARGET_FILE:minigzip64>
COMMAND $<TARGET_FILE:minigzip64> -d
COMMAND_ERROR_IS_FATAL ANY
)"
)
add_test(
NAME test_minigzip64
COMMAND cmake -P ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/test_minigzip64.cmake
COMMAND_EXPAND_LISTS
)
list(APPEND ZLIB_TEST_LIST test_minigzip64)
endif()

if(WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(
TARGET minigzip POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:minigzip> $<TARGET_FILE_DIR:minigzip>
COMMAND_EXPAND_LISTS
)

if(HAVE_OFF64_T)
add_custom_command(
TARGET minigzip64 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:minigzip64> $<TARGET_FILE_DIR:minigzip64>
COMMAND_EXPAND_LISTS
)
endif()
endif()

if(MSVC)
cmake_path(GET CMAKE_C_COMPILER PARENT_PATH VS_PATH)
set_tests_properties(test_example test_infcover test_minigzip
set_tests_properties(${ZLIB_TEST_LIST}
PROPERTIES ENVIRONMENT PATH=${VS_PATH}
)
endif()
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ Build [zlib](https://github.com/madler/zlib) using modern CMake and override the

## CMake Options

| Option | Default | Description |
| ----------------- | ------- | ------------------------------------------------ |
| `ZLIB_ENABLE_LFS` | `OFF` | Enable Large-File Support (LFS) on 32-bit system |
| `ZLIB_INSTALL` | `OFF` | Install zlib and CMake targets |
| `ZLIB_TEST` | `OFF` | Enable testing and build tests |
| Option | Default | Description |
| -------------- | ------- | ------------------------------ |
| `ZLIB_INSTALL` | `OFF` | Install zlib and CMake targets |
| `ZLIB_TEST` | `OFF` | Enable testing and build tests |

- `CPM_SOURCE_CACHE`
- Set to `/path/to/cache` to reuse downloaded source code
Expand Down

0 comments on commit cf5e894

Please sign in to comment.