Skip to content

Commit

Permalink
Add flags for jconfig.h customization, and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
csparker247 committed Jun 24, 2019
1 parent 2681693 commit e4cda6e
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -29,6 +31,7 @@ djpeg
jpegtran
rdjpgcom
wrjpgcom
testout*

## Autoconf ##
# http://www.gnu.org/software/automake
Expand Down
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
45 changes: 37 additions & 8 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ project(libjpeg VERSION ${version} LANGUAGES C)
set(C_STANDARD 99)

### Include extra packages ###
include(CheckIncludeFile)
include(CMakeDependentOption)
include(GNUInstallDirs)

### Options ###
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
Expand All @@ -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
Expand Down Expand Up @@ -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()
135 changes: 135 additions & 0 deletions resources/ConfigureJConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CheckTypeSize)

## Define this if your system has an ANSI-conforming <stddef.h> file.
check_include_file(stddef.h HAVE_STDDEF_H)

## Define this if your system has an ANSI-conforming <stdlib.h> 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 <string.h>,
## but does have a BSD-style <strings.h>.
set(NEED_BSD_STRINGS false CACHE BOOL "Use BSD <strings.h>. Use only if system lacks ANSI/SysV <strings.h>")

## 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
## <sys/types.h> instead.
set(NEED_SYS_TYPES_H false CACHE BOOL "size_t defined in <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.
## 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)
Loading

0 comments on commit e4cda6e

Please sign in to comment.