diff options
| author | Vollstrecker <werner@vollstreckernet.de> | 2025-12-30 17:42:52 +0100 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-12 10:55:15 -0800 |
| commit | 5ba29aea46bc135dcde7bcf88314b816d77a1cf6 (patch) | |
| tree | f3e7e548e88a90d9836ceadc343c76596cdde134 | |
| parent | b74a346cbf6b9fac87ec2746a8c678bd0a65b7c8 (diff) | |
| download | zlib-5ba29aea46bc135dcde7bcf88314b816d77a1cf6.tar.gz zlib-5ba29aea46bc135dcde7bcf88314b816d77a1cf6.tar.bz2 zlib-5ba29aea46bc135dcde7bcf88314b816d77a1cf6.zip | |
CMake: Added contrib/blast.
| -rw-r--r-- | contrib/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | contrib/blast/CMakeLists.txt | 81 | ||||
| -rw-r--r-- | contrib/blast/Makefile | 16 | ||||
| -rw-r--r-- | contrib/blast/blast-test.c | 42 | ||||
| -rw-r--r-- | contrib/blast/blast.c | 44 | ||||
| -rw-r--r-- | contrib/blast/blast.h | 1 | ||||
| -rw-r--r-- | contrib/blast/tester.cmake | 28 |
7 files changed, 171 insertions, 49 deletions
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index cc4b3310..63a838dc 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | option(ZLIB_BUILD_ADA "Enable building of Ada bindings" OFF) | 1 | option(ZLIB_BUILD_ADA "Enable building of Ada bindings" OFF) |
| 2 | option(ZLIB_BUILD_BLAST "Enable building of blast binary" OFF) | ||
| 2 | option(ZLIB_BUILD_MINIZIP "Enable building libminizip contrib library" OFF) | 3 | option(ZLIB_BUILD_MINIZIP "Enable building libminizip contrib library" OFF) |
| 3 | 4 | ||
| 4 | if(ZLIB_BUILD_ADA) | 5 | if(ZLIB_BUILD_ADA) |
| @@ -8,6 +9,13 @@ if(ZLIB_BUILD_ADA) | |||
| 8 | add_subdirectory(ada/) | 9 | add_subdirectory(ada/) |
| 9 | endif(ZLIB_BUILD_ADA) | 10 | endif(ZLIB_BUILD_ADA) |
| 10 | 11 | ||
| 12 | if(ZLIB_BUILD_BLAST) | ||
| 13 | set(ZLIBBLAST_BUILD_SHARED ${ZLIB_BUILD_SHARED}) | ||
| 14 | set(ZLIBBLAST_BUILD_STATIC ${ZLIB_BUILD_STATIC}) | ||
| 15 | set(ZLIBBLAST_BUILD_TESTING ${ZLIB_BUILD_TESTING}) | ||
| 16 | add_subdirectory(blast/) | ||
| 17 | endif(ZLIB_BUILD_BLAST) | ||
| 18 | |||
| 11 | if(ZLIB_BUILD_MINIZIP) | 19 | if(ZLIB_BUILD_MINIZIP) |
| 12 | set(MINIZIP_BUILD_SHARED ${ZLIB_BUILD_SHARED}) | 20 | set(MINIZIP_BUILD_SHARED ${ZLIB_BUILD_SHARED}) |
| 13 | set(MINIZIP_BUILD_STATIC ${ZLIB_BUILD_STATIC}) | 21 | set(MINIZIP_BUILD_STATIC ${ZLIB_BUILD_STATIC}) |
diff --git a/contrib/blast/CMakeLists.txt b/contrib/blast/CMakeLists.txt new file mode 100644 index 00000000..6357fcbb --- /dev/null +++ b/contrib/blast/CMakeLists.txt | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.12...3.31) | ||
| 2 | |||
| 3 | set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") | ||
| 4 | |||
| 5 | project( | ||
| 6 | blast | ||
| 7 | VERSION 1.3.0 | ||
| 8 | LANGUAGES C | ||
| 9 | DESCRIPTION "A library for creating zipfiles based in zlib" | ||
| 10 | HOMEPAGE_URL "https://www.zlib.net") | ||
| 11 | |||
| 12 | if(WIN32 OR CYGWIN) | ||
| 13 | set(zlibAda_static_suffix "s") | ||
| 14 | set(CMAKE_DEBUG_POSTFIX "d") | ||
| 15 | endif(WIN32 OR CYGWIN) | ||
| 16 | |||
| 17 | function(blast_findTestEnv testName) | ||
| 18 | set(testEnv "PATH=") | ||
| 19 | |||
| 20 | if(MSVC OR MINGW) | ||
| 21 | set(separator "\\\;") | ||
| 22 | else() | ||
| 23 | set(separator ":") | ||
| 24 | endif() | ||
| 25 | |||
| 26 | string(APPEND testEnv "$<TARGET_FILE_DIR:ZLIB::ZLIB>${separator}") | ||
| 27 | string(APPEND testEnv "$ENV{PATH}") | ||
| 28 | |||
| 29 | set_tests_properties(${testName} PROPERTIES ENVIRONMENT "${testEnv}") | ||
| 30 | endfunction(blast_findTestEnv testName) | ||
| 31 | |||
| 32 | if(ZLIBBLAST_BUILD_SHARED) | ||
| 33 | add_library(blast SHARED | ||
| 34 | blast.c | ||
| 35 | blast.h) | ||
| 36 | |||
| 37 | if(ZLIBBLAST_BUILD_TESTING) | ||
| 38 | enable_testing() | ||
| 39 | add_executable(blast-test blast-test.c) | ||
| 40 | target_link_libraries(blast-test blast) | ||
| 41 | |||
| 42 | add_test(NAME blast_blast-test | ||
| 43 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/tester.cmake | ||
| 44 | "$<TARGET_FILE:blast-test>" | ||
| 45 | "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| 46 | "${CMAKE_CURRENT_BINARY_DIR}") | ||
| 47 | |||
| 48 | if(MSVC | ||
| 49 | OR MSYS | ||
| 50 | OR MINGW | ||
| 51 | OR CYGWIN) | ||
| 52 | blast_findtestenv(blast-test) | ||
| 53 | endif( | ||
| 54 | MSVC | ||
| 55 | OR MSYS | ||
| 56 | OR MINGW | ||
| 57 | OR CYGWIN) | ||
| 58 | endif(ZLIBBLAST_BUILD_TESTING) | ||
| 59 | endif(ZLIBBLAST_BUILD_SHARED) | ||
| 60 | |||
| 61 | if(ZLIBBLAST_BUILD_STATIC) | ||
| 62 | add_library(blastStatic STATIC | ||
| 63 | blast.c | ||
| 64 | blast.h) | ||
| 65 | |||
| 66 | set_target_properties(blastStatic | ||
| 67 | PROPERTIES | ||
| 68 | OUTPUT_NAME blast${minizip_static_suffix}) | ||
| 69 | |||
| 70 | if(ZLIBBLAST_BUILD_TESTING) | ||
| 71 | enable_testing() | ||
| 72 | add_executable(blast-testStatic blast-test.c) | ||
| 73 | target_link_libraries(blast-testStatic blastStatic) | ||
| 74 | |||
| 75 | add_test(NAME blast_testStatic | ||
| 76 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/tester.cmake | ||
| 77 | "$<TARGET_FILE:blast-testStatic>" | ||
| 78 | "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| 79 | "${CMAKE_CURRENT_BINARY_DIR}") | ||
| 80 | endif(ZLIBBLAST_BUILD_TESTING) | ||
| 81 | endif(ZLIBBLAST_BUILD_STATIC) | ||
diff --git a/contrib/blast/Makefile b/contrib/blast/Makefile index 9be80baf..f64848b3 100644 --- a/contrib/blast/Makefile +++ b/contrib/blast/Makefile | |||
| @@ -1,8 +1,14 @@ | |||
| 1 | blast: blast.c blast.h | 1 | all: test |
| 2 | cc -DTEST -o blast blast.c | ||
| 3 | 2 | ||
| 4 | test: blast | 3 | libblast.so: blast.c blast.h |
| 5 | blast < test.pk | cmp - test.txt | 4 | cc -o libblast.so -shared blast.c |
| 5 | |||
| 6 | blast-test: libblast.so | ||
| 7 | cc -o blast-test.o -c blast-test.c | ||
| 8 | cc -o blast-test blast-test.o libblast.so | ||
| 9 | |||
| 10 | test: blast-test | ||
| 11 | LD_LIBRARY_PATH=./ ./blast-test < test.pk | cmp - test.txt | ||
| 6 | 12 | ||
| 7 | clean: | 13 | clean: |
| 8 | rm -f blast blast.o | 14 | rm -f libblast.so blast-test blast-test.o |
diff --git a/contrib/blast/blast-test.c b/contrib/blast/blast-test.c new file mode 100644 index 00000000..471dfd6d --- /dev/null +++ b/contrib/blast/blast-test.c | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #include "blast.h" /* prototype for blast() */ | ||
| 2 | |||
| 3 | /* Example of how to use blast() */ | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | #define CHUNK 16384 | ||
| 8 | |||
| 9 | local unsigned inf(void *how, unsigned char **buf) | ||
| 10 | { | ||
| 11 | static unsigned char hold[CHUNK]; | ||
| 12 | |||
| 13 | *buf = hold; | ||
| 14 | return fread(hold, 1, CHUNK, (FILE *)how); | ||
| 15 | } | ||
| 16 | |||
| 17 | local int outf(void *how, unsigned char *buf, unsigned len) | ||
| 18 | { | ||
| 19 | return fwrite(buf, 1, len, (FILE *)how) != len; | ||
| 20 | } | ||
| 21 | |||
| 22 | /* Decompress a PKWare Compression Library stream from stdin to stdout */ | ||
| 23 | int main(void) | ||
| 24 | { | ||
| 25 | int ret; | ||
| 26 | unsigned left; | ||
| 27 | |||
| 28 | /* decompress to stdout */ | ||
| 29 | left = 0; | ||
| 30 | ret = blast(inf, stdin, outf, stdout, &left, NULL); | ||
| 31 | if (ret != 0) | ||
| 32 | fprintf(stderr, "blast error: %d\n", ret); | ||
| 33 | |||
| 34 | /* count any leftover bytes */ | ||
| 35 | while (getchar() != EOF) | ||
| 36 | left++; | ||
| 37 | if (left) | ||
| 38 | fprintf(stderr, "blast warning: %u unused bytes of input\n", left); | ||
| 39 | |||
| 40 | /* return blast() error code */ | ||
| 41 | return ret; | ||
| 42 | } | ||
diff --git a/contrib/blast/blast.c b/contrib/blast/blast.c index e6e65907..3f6963f8 100644 --- a/contrib/blast/blast.c +++ b/contrib/blast/blast.c | |||
| @@ -33,7 +33,6 @@ | |||
| 33 | #include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ | 33 | #include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ |
| 34 | #include "blast.h" /* prototype for blast() */ | 34 | #include "blast.h" /* prototype for blast() */ |
| 35 | 35 | ||
| 36 | #define local static /* for local function definitions */ | ||
| 37 | #define MAXBITS 13 /* maximum code length */ | 36 | #define MAXBITS 13 /* maximum code length */ |
| 38 | #define MAXWIN 4096 /* maximum window size */ | 37 | #define MAXWIN 4096 /* maximum window size */ |
| 39 | 38 | ||
| @@ -421,46 +420,3 @@ int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow, | |||
| 421 | err = 1; | 420 | err = 1; |
| 422 | return err; | 421 | return err; |
| 423 | } | 422 | } |
| 424 | |||
| 425 | #ifdef TEST | ||
| 426 | /* Example of how to use blast() */ | ||
| 427 | #include <stdio.h> | ||
| 428 | #include <stdlib.h> | ||
| 429 | |||
| 430 | #define CHUNK 16384 | ||
| 431 | |||
| 432 | local unsigned inf(void *how, unsigned char **buf) | ||
| 433 | { | ||
| 434 | static unsigned char hold[CHUNK]; | ||
| 435 | |||
| 436 | *buf = hold; | ||
| 437 | return fread(hold, 1, CHUNK, (FILE *)how); | ||
| 438 | } | ||
| 439 | |||
| 440 | local int outf(void *how, unsigned char *buf, unsigned len) | ||
| 441 | { | ||
| 442 | return fwrite(buf, 1, len, (FILE *)how) != len; | ||
| 443 | } | ||
| 444 | |||
| 445 | /* Decompress a PKWare Compression Library stream from stdin to stdout */ | ||
| 446 | int main(void) | ||
| 447 | { | ||
| 448 | int ret; | ||
| 449 | unsigned left; | ||
| 450 | |||
| 451 | /* decompress to stdout */ | ||
| 452 | left = 0; | ||
| 453 | ret = blast(inf, stdin, outf, stdout, &left, NULL); | ||
| 454 | if (ret != 0) | ||
| 455 | fprintf(stderr, "blast error: %d\n", ret); | ||
| 456 | |||
| 457 | /* count any leftover bytes */ | ||
| 458 | while (getchar() != EOF) | ||
| 459 | left++; | ||
| 460 | if (left) | ||
| 461 | fprintf(stderr, "blast warning: %u unused bytes of input\n", left); | ||
| 462 | |||
| 463 | /* return blast() error code */ | ||
| 464 | return ret; | ||
| 465 | } | ||
| 466 | #endif | ||
diff --git a/contrib/blast/blast.h b/contrib/blast/blast.h index ef8544c5..c5ef7ab5 100644 --- a/contrib/blast/blast.h +++ b/contrib/blast/blast.h | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | Mark Adler madler@alumni.caltech.edu | 21 | Mark Adler madler@alumni.caltech.edu |
| 22 | */ | 22 | */ |
| 23 | 23 | ||
| 24 | #define local static /* for local function definitions */ | ||
| 24 | 25 | ||
| 25 | /* | 26 | /* |
| 26 | * blast() decompresses the PKWare Data Compression Library (DCL) compressed | 27 | * blast() decompresses the PKWare Data Compression Library (DCL) compressed |
diff --git a/contrib/blast/tester.cmake b/contrib/blast/tester.cmake new file mode 100644 index 00000000..14e69fca --- /dev/null +++ b/contrib/blast/tester.cmake | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.12...3.31) | ||
| 2 | |||
| 3 | #CMAKE_ARGV0 = ${CMAKE_COMMAND} | ||
| 4 | #CMAKE_ARGV1 = -P | ||
| 5 | #CMAKE_ARGV2 = ${CMAKE_CURRENT_SOURCE_DIR}/tester.cmake | ||
| 6 | #CMAKE_ARGV3 = "$<TARGET_FILE:blast-test>" | ||
| 7 | #CMAKE_ARGV4 = "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| 8 | #CMAKE_ARGV5 = "${CMAKE_CURRENT_BINARY_DIR}") | ||
| 9 | |||
| 10 | execute_process(COMMAND ${CMAKE_ARGV3} | ||
| 11 | INPUT_FILE "${CMAKE_ARGV4}/test.pk" | ||
| 12 | OUTPUT_FILE "${CMAKE_ARGV5}/output.txt" | ||
| 13 | RESULT_VARIABLE RESULT) | ||
| 14 | |||
| 15 | if(RESULT) | ||
| 16 | message(FATAL_ERROR "Command exitited with: ${RESULT}") | ||
| 17 | endif(RESULT) | ||
| 18 | |||
| 19 | execute_process(COMMAND ${CMAKE_ARGV0} -E compare_files | ||
| 20 | "${CMAKE_ARGV4}/test.txt" | ||
| 21 | "${CMAKE_ARGV5}/output.txt" | ||
| 22 | RESULT_VARIABLE RESULT) | ||
| 23 | |||
| 24 | file(REMOVE "${CMAKE_ARGV5}/output.txt") | ||
| 25 | |||
| 26 | if(RESULT) | ||
| 27 | message(FATAL_ERROR "Files differ") | ||
| 28 | endif(RESULT) | ||
