From e4cda6e34fc23afd5b3abe5218e0188c0ad08f01 Mon Sep 17 00:00:00 2001 From: Seth Parker Date: Mon, 24 Jun 2019 14:02:14 -0400 Subject: [PATCH] Add flags for jconfig.h customization, and add tests --- .gitignore | 3 + CMakeLists.txt | 13 +++ README.md | 26 +++++- resources/CMakeLists.txt | 45 +++++++++-- resources/ConfigureJConfig.cmake | 135 +++++++++++++++++++++++++++++++ resources/jconfig.h.in | 58 ++++++------- resources/test-libjpeg.sh | 26 ++++++ 7 files changed, 262 insertions(+), 44 deletions(-) create mode 100644 resources/ConfigureJConfig.cmake create mode 100644 resources/test-libjpeg.sh diff --git a/.gitignore b/.gitignore index cb2e977..5e1f39a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,12 +14,14 @@ _deps ## jpeg-cmake ## libjpeg/CMakeLists.txt +libjpeg/ConfigureJConfig.cmake libjpeg/jconfig.h.in libjpeg/jconfig.h libjpeg/libjpeg.pc.cmakein libjpeg/libjpeg.pc libjpeg/libjpeg.la.in libjpeg/libjpeg.la +libjpeg/test-libjpeg.sh ## libjpeg ## .deps/ @@ -29,6 +31,7 @@ djpeg jpegtran rdjpgcom wrjpgcom +testout* ## Autoconf ## # http://www.gnu.org/software/automake diff --git a/CMakeLists.txt b/CMakeLists.txt index 09273d6..0427698 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,11 @@ configure_file( ${PROJECT_SOURCE_DIR}/libjpeg/CMakeLists.txt COPYONLY ) +configure_file( + resources/ConfigureJConfig.cmake + ${PROJECT_SOURCE_DIR}/libjpeg/ConfigureJConfig.cmake + COPYONLY +) configure_file( resources/jconfig.h.in ${PROJECT_SOURCE_DIR}/libjpeg/jconfig.h.in @@ -23,6 +28,14 @@ configure_file( ${PROJECT_SOURCE_DIR}/libjpeg/libjpeg.la.in COPYONLY ) +configure_file( + resources/test-libjpeg.sh + ${PROJECT_SOURCE_DIR}/libjpeg/test-libjpeg.sh + COPYONLY +) + +# Enable testing here AND in libjpeg CMakelists.txt +enable_testing() # Build libjpeg add_subdirectory(libjpeg) diff --git a/README.md b/README.md index 10e7d63..8cddc3c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ cmake . make ``` -## Advanced Options +## Advanced Configuration ### Shared and Static Libraries `jpeg-cmake` emulates the behavior of `libjpeg` and compiles both static and shared libraries by default. Selective compilation of shared and static @@ -62,9 +62,27 @@ by using the `LINK_STATIC` flag: cmake -DLINK_STATIC=ON .. ``` -### Tests (Coming Soon) -The `libjpeg` tests are built by default. To disable, set the -`BUILD_TESTS` flag: +### Tests +The `libjpeg` test targets are generated by default whenever +`BUILD_EXECUTABLES` is enabled. They can be run using the `test` target: +```Shell +cmake .. +make +make test +``` + +To disable test generation, set the `BUILD_TESTS` flag: ```Shell cmake -DBUILD_TESTS=OFF .. ``` + +### Customize `jconfig.h` +`libjpeg` provides extensive build customization through modification of `jconfig.h`. To ease this process, `jpeg-cmake` provides many of these +customization options as CMake flags. For example: + +```Shell +cmake -DGIF_SUPPORTED=OFF -DPROGRESS_REPORT=ON .. +``` + +See [`resources/ConfigureJConfig.cmake`](resources/ConfigureJConfig.cmake) for +a complete list of flags and their descriptions. diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index a857c4c..541cfa6 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -13,7 +13,6 @@ project(libjpeg VERSION ${version} LANGUAGES C) set(C_STANDARD 99) ### Include extra packages ### -include(CheckIncludeFile) include(CMakeDependentOption) include(GNUInstallDirs) @@ -21,7 +20,7 @@ include(GNUInstallDirs) option(BUILD_SHARED_LIBS "Build shared libraries" ON) option(BUILD_STATIC_LIBS "Build static libraries" ON) cmake_dependent_option(BUILD_EXECUTABLES "Build JPEG utilities" ON "BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS" OFF) -# cmake_dependent_option(BUILD_TESTS "Build test executables" ON "BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS" OFF) +cmake_dependent_option(BUILD_TESTS "Build test executables" ON "BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS;BUILD_EXECUTABLES" OFF) cmake_dependent_option(LINK_STATIC "Link all executables statically" OFF "BUILD_STATIC_LIBS;BUILD_EXECUTABLES" OFF) # Make sure we build at least one library @@ -30,12 +29,7 @@ if(NOT(BUILD_SHARED_LIBS OR BUILD_STATIC_LIBS)) endif() ### Configure jconfig.h ### -check_include_file(stddef.h HAVE_STDDEF_H) -check_include_file(stdlib.h HAVE_STDLIB_H) -if(WIN32 AND NOT CYGWIN) - set(TWO_FILE_COMMANDLINE ON) -endif() -configure_file(jconfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/jconfig.h) +include(ConfigureJConfig.cmake) ### Build the object library ### set(PUBLIC_HDRS @@ -143,3 +137,38 @@ if(BUILD_EXECUTABLES) DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 ) endif() + +### Add tests +if(BUILD_TESTS) + enable_testing() + # Copy test files + file( + COPY testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg testimgp.jpg + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + ) + ## Add tests + add_test( + NAME jpeg2ppm + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh jpeg2ppm + ) + add_test( + NAME jpeg2bmp + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh jpeg2bmp + ) + add_test( + NAME ppm2jpg + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh ppm2jpg + ) + add_test( + NAME progressive2ppm + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh progressive2ppm + ) + add_test( + NAME ppm2progressive + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh ppm2progressive + ) + add_test( + NAME progressive2baseline + COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test-libjpeg.sh progressive2baseline + ) +endif() diff --git a/resources/ConfigureJConfig.cmake b/resources/ConfigureJConfig.cmake new file mode 100644 index 0000000..87f9e9b --- /dev/null +++ b/resources/ConfigureJConfig.cmake @@ -0,0 +1,135 @@ +include(CheckIncludeFile) +include(CheckSymbolExists) +include(CheckTypeSize) + +## Define this if your system has an ANSI-conforming file. +check_include_file(stddef.h HAVE_STDDEF_H) + +## Define this if your system has an ANSI-conforming file. +check_include_file(stdlib.h HAVE_STDLIB_H) + +## Does your compiler support function prototypes? +## (If not, you also need to use ansi2knr, see install.txt) +set(HAVE_PROTOTYPES true CACHE BOOL "Does your compiler support function prototypes?") + +## Does your compiler support the declaration "unsigned char" ? +## How about "unsigned short" ? +check_type_size("unsigned char" UNSIGNED_CHAR LANGUAGE C) +check_type_size("unsigned short" UNSIGNED_SHORT LANGUAGE C) + +## Define "void" as "char" if your compiler doesn't know about type void. +## NOTE: be sure to define void such that "void *" represents the most general +## pointer type, e.g., that returned by malloc(). +# NOT IMPLEMENTED: Modify in jconfig.h.in # + +## Define "const" as empty if your compiler doesn't know the "const" keyword. +# NOT IMPLEMENTED: Modify in jconfig.h.in # + +## Define this if an ordinary "char" type is unsigned. +## If you're not sure, leaving it undefined will work at some cost in speed. +## If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. +set(CHAR_IS_UNSIGNED false CACHE BOOL "char type is unsigned") + +## Define this if your system does not have an ANSI/SysV , +## but does have a BSD-style . +set(NEED_BSD_STRINGS false CACHE BOOL "Use BSD . Use only if system lacks ANSI/SysV ") + +## Define this if your system does not provide typedef size_t in any of the +## ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in +## instead. +set(NEED_SYS_TYPES_H false CACHE BOOL "size_t defined in ") + +## For 80x86 machines, you need to define NEED_FAR_POINTERS, +## unless you are using a large-data memory model or 80386 flat-memory mode. +## On less brain-damaged CPUs this symbol must not be defined. +## (Defining this symbol causes large data structures to be referenced through +## "far" pointers and to be allocated with a special version of malloc.) +set(NEED_FAR_POINTERS false CACHE BOOL "Reference large data structures through 'far' pointers allocated with a special version of malloc") + +## Define this if your linker needs global names to be unique in less +## than the first 15 characters. +set(NEED_SHORT_EXTERNAL_NAMES false CACHE BOOL "Global names must be unique in less than the first 15 characters") + +## Although a real ANSI C compiler can deal perfectly well with pointers to +## unspecified structures (see "incomplete types" in the spec), a few pre-ANSI +## and pseudo-ANSI compilers get confused. To keep one of these bozos happy, +## define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you +## actually get "missing structure definition" warnings or errors while +## compiling the JPEG code. +set(INCOMPLETE_TYPES_BROKEN false CACHE BOOL "Disable pointers to unspecified structures") + +## Define "boolean" as unsigned char, not enum, on Windows systems. +# NOT IMPLEMENTED: Modify in jconfig.h.in # + +## The following options affect code selection within the JPEG library, +## but they don't need to be visible to applications using the library. +## To minimize application namespace pollution, the symbols won't be +## defined unless JPEG_INTERNALS has been defined. +## + +## Define this if your compiler implements ">>" on signed values as a logical +## (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift, +## which is the normal and rational definition. +set(RIGHT_SHIFT_IS_UNSIGNED false CACHE BOOL "Compiler implements >> on signed values as a logical (unsigned) shift") + +## The remaining options do not affect the JPEG library proper, +## but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c). +## Other applications can ignore these. +## + +## These defines indicate which image (non-JPEG) file formats are allowed.## +set(BMP_SUPPORTED true CACHE BOOL "Enable BMP image file format support") +set(GIF_SUPPORTED true CACHE BOOL "Enable GIF image file format support") +set(PPM_SUPPORTED true CACHE BOOL "Enable PBMPLUS PPM/PGM image file format support") +set(RLE_SUPPORTED false CACHE BOOL "Enable Utah RLE image file format support") +set(TARGA_SUPPORTED true CACHE BOOL "Enable Targa image file format support") + +## Define this if you want to name both input and output files on the command +## line, rather than using stdout and optionally stdin. You MUST do this if +## your system can't cope with binary I/O to stdin/stdout. See comments at +## head of cjpeg.c or djpeg.c. +if(WIN32 AND NOT CYGWIN) + set(TWO_FILE_COMMANDLINE ON CACHE BOOL "Enable both named inputs and outputs for CLI utilities") +else() + set(TWO_FILE_COMMANDLINE OFF CACHE BOOL "Enable both named inputs and outputs for CLI utilities") +endif() + +## Define this if your system needs explicit cleanup of temporary files. +## This is crucial under MS-DOS, where the temporary "files" may be areas +## of extended memory; on most other systems it's not as important. +set(NEED_SIGNAL_CATCHER false CACHE BOOL "System requires explicity cleanup of temporary files") + +## By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). +## This is necessary on systems that distinguish text files from binary files, +## and is harmless on most systems that don't. If you have one of the rare +## systems that complains about the "b" spec, define this symbol. +set(DONT_USE_B_MODE false CACHE BOOL "Disable B-mode with fopen") + +## Define this if you want percent-done progress reports from cjpeg/djpeg. +set(PROGRESS_REPORT false CACHE BOOL "Enable percent-done progress reports from cjpeg/djpeg") + +mark_as_advanced(FORCE + HAVE_PROTOTYPES + HAVE_UNSIGNED_CHAR + HAVE_UNSIGNED_SHORT + CHAR_IS_UNSIGNED + HAVE_STDDEF_H + HAVE_STDLIB_H + NEED_BSD_STRINGS + NEED_SYS_TYPES_H + NEED_FAR_POINTERS + NEED_SHORT_EXTERNAL_NAMES + INCOMPLETE_TYPES_BROKEN + RIGHT_SHIFT_IS_UNSIGNED + BMP_SUPPORTED + GIF_SUPPORTED + PPM_SUPPORTED + RLE_SUPPORTED + TARGA_SUPPORTED + TWO_FILE_COMMANDLINE + NEED_SIGNAL_CATCHER + DONT_USE_B_MODE + PROGRESS_REPORT +) + +configure_file(jconfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/jconfig.h) diff --git a/resources/jconfig.h.in b/resources/jconfig.h.in index d1710ae..72fd90d 100644 --- a/resources/jconfig.h.in +++ b/resources/jconfig.h.in @@ -1,21 +1,15 @@ /* - * jconfig.txt + * jconfig.h.in * * Copyright (C) 1991-1994, Thomas G. Lane. * Modified 2009-2013 by Guido Vollbeding. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * - * This file documents the configuration options that are required to - * customize the JPEG software for a particular system. - * - * The actual configuration options for a particular installation are stored - * in jconfig.h. On many machines, jconfig.h can be generated automatically - * or copied from one of the "canned" jconfig files that we supply. But if - * you need to generate a jconfig.h file by hand, this file tells you how. - * - * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING. - * EDIT A COPY NAMED JCONFIG.H. + * This file is a modification of jconfig.txt from libjpeg. In addition to + * documenting the configuration options that are required to customize the + * JPEG software for a particular system, it is used by jpeg-cmake to configure + * jconfig.h */ @@ -27,13 +21,13 @@ /* Does your compiler support function prototypes? * (If not, you also need to use ansi2knr, see install.txt) */ -#define HAVE_PROTOTYPES +#cmakedefine HAVE_PROTOTYPES /* Does your compiler support the declaration "unsigned char" ? * How about "unsigned short" ? */ -#define HAVE_UNSIGNED_CHAR -#define HAVE_UNSIGNED_SHORT +#cmakedefine HAVE_UNSIGNED_CHAR +#cmakedefine HAVE_UNSIGNED_SHORT /* Define "void" as "char" if your compiler doesn't know about type void. * NOTE: be sure to define void such that "void *" represents the most general @@ -49,26 +43,26 @@ * If you're not sure, leaving it undefined will work at some cost in speed. * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. */ -#undef CHAR_IS_UNSIGNED +#cmakedefine CHAR_IS_UNSIGNED /* Define this if your system has an ANSI-conforming file. */ -#define HAVE_STDDEF_H +#cmakedefine HAVE_STDDEF_H /* Define this if your system has an ANSI-conforming file. */ -#define HAVE_STDLIB_H +#cmakedefine HAVE_STDLIB_H /* Define this if your system does not have an ANSI/SysV , * but does have a BSD-style . */ -#undef NEED_BSD_STRINGS +#cmakedefine NEED_BSD_STRINGS /* Define this if your system does not provide typedef size_t in any of the * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in * instead. */ -#undef NEED_SYS_TYPES_H +#cmakedefine NEED_SYS_TYPES_H /* For 80x86 machines, you need to define NEED_FAR_POINTERS, * unless you are using a large-data memory model or 80386 flat-memory mode. @@ -76,12 +70,12 @@ * (Defining this symbol causes large data structures to be referenced through * "far" pointers and to be allocated with a special version of malloc.) */ -#undef NEED_FAR_POINTERS +#cmakedefine NEED_FAR_POINTERS /* Define this if your linker needs global names to be unique in less * than the first 15 characters. */ -#undef NEED_SHORT_EXTERNAL_NAMES +#cmakedefine NEED_SHORT_EXTERNAL_NAMES /* Although a real ANSI C compiler can deal perfectly well with pointers to * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI @@ -90,7 +84,7 @@ * actually get "missing structure definition" warnings or errors while * compiling the JPEG code. */ -#undef INCOMPLETE_TYPES_BROKEN +#cmakedefine INCOMPLETE_TYPES_BROKEN /* Define "boolean" as unsigned char, not enum, on Windows systems. */ @@ -121,7 +115,7 @@ typedef unsigned char boolean; * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift, * which is the normal and rational definition. */ -#undef RIGHT_SHIFT_IS_UNSIGNED +#cmakedefine RIGHT_SHIFT_IS_UNSIGNED #endif /* JPEG_INTERNALS */ @@ -137,35 +131,35 @@ typedef unsigned char boolean; /* These defines indicate which image (non-JPEG) file formats are allowed. */ -#define BMP_SUPPORTED /* BMP image file format */ -#define GIF_SUPPORTED /* GIF image file format */ -#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ -#undef RLE_SUPPORTED /* Utah RLE image file format */ -#define TARGA_SUPPORTED /* Targa image file format */ +#cmakedefine BMP_SUPPORTED /* BMP image file format */ +#cmakedefine GIF_SUPPORTED /* GIF image file format */ +#cmakedefine PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ +#cmakedefine RLE_SUPPORTED /* Utah RLE image file format */ +#cmakedefine TARGA_SUPPORTED /* Targa image file format */ /* Define this if you want to name both input and output files on the command * line, rather than using stdout and optionally stdin. You MUST do this if * your system can't cope with binary I/O to stdin/stdout. See comments at * head of cjpeg.c or djpeg.c. */ -#undef TWO_FILE_COMMANDLINE +#cmakedefine TWO_FILE_COMMANDLINE /* Define this if your system needs explicit cleanup of temporary files. * This is crucial under MS-DOS, where the temporary "files" may be areas * of extended memory; on most other systems it's not as important. */ -#undef NEED_SIGNAL_CATCHER +#cmakedefine NEED_SIGNAL_CATCHER /* By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). * This is necessary on systems that distinguish text files from binary files, * and is harmless on most systems that don't. If you have one of the rare * systems that complains about the "b" spec, define this symbol. */ -#undef DONT_USE_B_MODE +#cmakedefine DONT_USE_B_MODE /* Define this if you want percent-done progress reports from cjpeg/djpeg. */ -#undef PROGRESS_REPORT +#cmakedefine PROGRESS_REPORT #endif /* JPEG_CJPEG_DJPEG */ diff --git a/resources/test-libjpeg.sh b/resources/test-libjpeg.sh new file mode 100644 index 0000000..8098329 --- /dev/null +++ b/resources/test-libjpeg.sh @@ -0,0 +1,26 @@ +#/bin/bash + +# jpeg2ppm +if [[ $1 == "jpeg2ppm" ]]; then +./djpeg -dct int -ppm -outfile testout.ppm testorig.jpg && cmp testimg.ppm testout.ppm + +# jpeg2bmp +elif [[ $1 == "jpeg2bmp" ]]; then +./djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg && cmp testimg.bmp testout.bmp + +#ppm2jpg +elif [[ $1 == "ppm2jpg" ]]; then +./cjpeg -dct int -outfile testout.jpg testimg.ppm && cmp testimg.jpg testout.jpg + +#progressive2ppm +elif [[ $1 == "progressive2ppm" ]]; then +./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg && cmp testimg.ppm testoutp.ppm + +#ppm2progressive +elif [[ $1 == "ppm2progressive" ]]; then +./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm && cmp testimgp.jpg testoutp.jpg + +#progressive2baseline +elif [[ $1 == "progressive2baseline" ]]; then +./jpegtran -outfile testoutt.jpg testprog.jpg && cmp testorig.jpg testoutt.jpg +fi