• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 2.8.12)
2
3if(CMAKE_EXECUTABLE_SUFFIX)
4  set(CMAKE_EXECUTABLE_SUFFIX_TMP ${CMAKE_EXECUTABLE_SUFFIX})
5endif()
6
7project(libjpeg-turbo C)
8set(VERSION 2.0.2)
9string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
10list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
11list(GET VERSION_TRIPLET 1 VERSION_MINOR)
12list(GET VERSION_TRIPLET 2 VERSION_REVISION)
13function(pad_number NUMBER OUTPUT_LEN)
14  string(LENGTH "${${NUMBER}}" INPUT_LEN)
15  if(INPUT_LEN LESS OUTPUT_LEN)
16    math(EXPR ZEROES "${OUTPUT_LEN} - ${INPUT_LEN} - 1")
17    set(NUM ${${NUMBER}})
18    foreach(C RANGE ${ZEROES})
19      set(NUM "0${NUM}")
20    endforeach()
21    set(${NUMBER} ${NUM} PARENT_SCOPE)
22  endif()
23endfunction()
24pad_number(VERSION_MINOR 3)
25pad_number(VERSION_REVISION 3)
26set(LIBJPEG_TURBO_VERSION_NUMBER ${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION})
27
28string(TIMESTAMP DEFAULT_BUILD "%Y%m%d")
29set(BUILD ${DEFAULT_BUILD} CACHE STRING "Build string (default: ${DEFAULT_BUILD})")
30
31# NOTE: On Windows, this does nothing except when using MinGW or Cygwin.
32# CMAKE_BUILD_TYPE has no meaning in Visual Studio, and it always defaults to
33# Debug when using NMake.
34if(NOT CMAKE_BUILD_TYPE)
35  set(CMAKE_BUILD_TYPE Release)
36endif()
37message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
38
39message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
40
41# Detect CPU type and whether we're building 64-bit or 32-bit code
42math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8")
43string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} CMAKE_SYSTEM_PROCESSOR_LC)
44if(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86_64" OR
45  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "amd64" OR
46  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "i[0-9]86" OR
47  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "x86" OR
48  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "ia32")
49  if(BITS EQUAL 64)
50    set(CPU_TYPE x86_64)
51  else()
52    set(CPU_TYPE i386)
53  endif()
54  if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ${CPU_TYPE})
55    set(CMAKE_SYSTEM_PROCESSOR ${CPU_TYPE})
56  endif()
57elseif(CMAKE_SYSTEM_PROCESSOR_LC STREQUAL "aarch64" OR
58  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "arm*64*")
59  set(CPU_TYPE arm64)
60elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "arm*")
61  set(CPU_TYPE arm)
62elseif(CMAKE_SYSTEM_PROCESSOR_LC MATCHES "ppc*" OR
63  CMAKE_SYSTEM_PROCESSOR_LC MATCHES "powerpc*")
64  set(CPU_TYPE powerpc)
65else()
66  set(CPU_TYPE ${CMAKE_SYSTEM_PROCESSOR_LC})
67endif()
68message(STATUS "${BITS}-bit build (${CPU_TYPE})")
69
70
71###############################################################################
72# INSTALL DIRECTORIES
73###############################################################################
74
75if(WIN32)
76  if(MSVC)
77    set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}")
78  else()
79    set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}-gcc")
80  endif()
81  if(BITS EQUAL 64)
82    set(CMAKE_INSTALL_DEFAULT_PREFIX "${CMAKE_INSTALL_DEFAULT_PREFIX}64")
83  endif()
84else()
85  set(CMAKE_INSTALL_DEFAULT_PREFIX /opt/${CMAKE_PROJECT_NAME})
86endif()
87if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
88  set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_DEFAULT_PREFIX}" CACHE PATH
89    "Directory into which to install ${CMAKE_PROJECT_NAME} (default: ${CMAKE_INSTALL_DEFAULT_PREFIX})"
90    FORCE)
91endif()
92message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
93
94# When the prefix is /opt/${CMAKE_PROJECT_NAME}, we assume that an "official"
95# build is being created, and thus we install things into specific locations.
96
97if(CMAKE_INSTALL_PREFIX STREQUAL "${CMAKE_INSTALL_DEFAULT_PREFIX}")
98  set(CMAKE_INSTALL_DEFAULT_DATAROOTDIR "")
99  set(CMAKE_INSTALL_DEFAULT_DOCDIR "<CMAKE_INSTALL_DATAROOTDIR>/doc")
100  set(CMAKE_INSTALL_DEFAULT_JAVADIR "<CMAKE_INSTALL_DATAROOTDIR>/classes")
101  if(UNIX AND NOT APPLE)
102    if(BITS EQUAL 64)
103      set(CMAKE_INSTALL_DEFAULT_LIBDIR "lib64")
104    else()
105      set(CMAKE_INSTALL_DEFAULT_LIBDIR "lib32")
106    endif()
107  endif()
108endif()
109
110include(cmakescripts/GNUInstallDirs.cmake)
111
112macro(report_directory var)
113  if(CMAKE_INSTALL_${var} STREQUAL CMAKE_INSTALL_FULL_${var})
114    message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}}")
115  else()
116    message(STATUS "CMAKE_INSTALL_${var} = ${CMAKE_INSTALL_${var}} (${CMAKE_INSTALL_FULL_${var}})")
117  endif()
118  mark_as_advanced(CLEAR CMAKE_INSTALL_${var})
119endmacro()
120
121set(DIRLIST "BINDIR;DATAROOTDIR;DOCDIR;INCLUDEDIR;LIBDIR")
122if(UNIX)
123  list(APPEND DIRLIST "MANDIR")
124endif()
125foreach(dir ${DIRLIST})
126  report_directory(${dir})
127endforeach()
128
129
130###############################################################################
131# CONFIGURATION OPTIONS
132###############################################################################
133
134macro(boolean_number var)
135  if(${var})
136    set(${var} 1)
137  else()
138    set(${var} 0)
139  endif()
140endmacro()
141
142option(ENABLE_SHARED "Build shared libraries" TRUE)
143boolean_number(ENABLE_SHARED)
144option(ENABLE_STATIC "Build static libraries" TRUE)
145boolean_number(ENABLE_STATIC)
146option(REQUIRE_SIMD "Generate a fatal error if SIMD extensions are not available for this platform (default is to fall back to a non-SIMD build)" FALSE)
147boolean_number(REQUIRE_SIMD)
148option(WITH_12BIT "Encode/decode JPEG images with 12-bit samples (implies WITH_ARITH_DEC=0 WITH_ARITH_ENC=0 WITH_JAVA=0 WITH_SIMD=0 WITH_TURBOJPEG=0 )" FALSE)
149boolean_number(WITH_12BIT)
150option(WITH_ARITH_DEC "Include arithmetic decoding support when emulating the libjpeg v6b API/ABI" TRUE)
151boolean_number(WITH_ARITH_DEC)
152option(WITH_ARITH_ENC "Include arithmetic encoding support when emulating the libjpeg v6b API/ABI" TRUE)
153boolean_number(WITH_ARITH_ENC)
154option(WITH_JAVA "Build Java wrapper for the TurboJPEG API library (implies ENABLE_SHARED=1)" FALSE)
155boolean_number(WITH_JAVA)
156option(WITH_JPEG7 "Emulate libjpeg v7 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE)
157boolean_number(WITH_JPEG7)
158option(WITH_JPEG8 "Emulate libjpeg v8 API/ABI (this makes ${CMAKE_PROJECT_NAME} backward-incompatible with libjpeg v6b)" FALSE)
159boolean_number(WITH_JPEG8)
160option(WITH_MEM_SRCDST "Include in-memory source/destination manager functions when emulating the libjpeg v6b or v7 API/ABI" TRUE)
161boolean_number(WITH_MEM_SRCDST)
162option(WITH_SIMD "Include SIMD extensions, if available for this platform" TRUE)
163boolean_number(WITH_SIMD)
164option(WITH_TURBOJPEG "Include the TurboJPEG API library and associated test programs" TRUE)
165boolean_number(WITH_TURBOJPEG)
166
167macro(report_option var desc)
168  if(${var})
169    message(STATUS "${desc} enabled (${var} = ${${var}})")
170  else()
171    message(STATUS "${desc} disabled (${var} = ${${var}})")
172  endif()
173endmacro()
174
175if(WITH_JAVA)
176  set(ENABLE_SHARED 1)
177endif()
178
179# Explicitly setting CMAKE_POSITION_INDEPENDENT_CODE=FALSE disables PIC for all
180# targets, which will cause the shared library builds to fail.  Thus, if shared
181# libraries are enabled and CMAKE_POSITION_INDEPENDENT_CODE is explicitly set
182# to FALSE, we need to unset it, thus restoring the default behavior
183# (automatically using PIC for shared library targets.)
184if(DEFINED CMAKE_POSITION_INDEPENDENT_CODE AND
185  NOT CMAKE_POSITION_INDEPENDENT_CODE AND ENABLE_SHARED)
186  unset(CMAKE_POSITION_INDEPENDENT_CODE CACHE)
187endif()
188
189report_option(ENABLE_SHARED "Shared libraries")
190report_option(ENABLE_STATIC "Static libraries")
191
192if(ENABLE_SHARED)
193  set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
194endif()
195
196if(WITH_12BIT)
197  set(WITH_ARITH_DEC 0)
198  set(WITH_ARITH_ENC 0)
199  set(WITH_JAVA 0)
200  set(WITH_SIMD 0)
201  set(WITH_TURBOJPEG 0)
202  set(BITS_IN_JSAMPLE 12)
203else()
204  set(BITS_IN_JSAMPLE 8)
205endif()
206report_option(WITH_12BIT "12-bit JPEG support")
207
208if(WITH_JPEG8 OR WITH_JPEG7)
209  set(WITH_ARITH_ENC 1)
210  set(WITH_ARITH_DEC 1)
211endif()
212if(WITH_JPEG8)
213  set(WITH_MEM_SRCDST 0)
214endif()
215
216if(WITH_ARITH_DEC)
217  set(D_ARITH_CODING_SUPPORTED 1)
218endif()
219if(NOT WITH_12BIT)
220  report_option(WITH_ARITH_DEC "Arithmetic decoding support")
221endif()
222
223if(WITH_ARITH_ENC)
224  set(C_ARITH_CODING_SUPPORTED 1)
225endif()
226if(NOT WITH_12BIT)
227  report_option(WITH_ARITH_ENC "Arithmetic encoding support")
228endif()
229
230if(NOT WITH_12BIT)
231  report_option(WITH_TURBOJPEG "TurboJPEG API library")
232  report_option(WITH_JAVA "TurboJPEG Java wrapper")
233endif()
234
235if(WITH_MEM_SRCDST)
236  set(MEM_SRCDST_SUPPORTED 1)
237  set(MEM_SRCDST_FUNCTIONS "global:  jpeg_mem_dest;  jpeg_mem_src;")
238endif()
239if(NOT WITH_JPEG8)
240  report_option(WITH_MEM_SRCDST "In-memory source/destination managers")
241endif()
242
243set(SO_AGE 2)
244if(WITH_MEM_SRCDST)
245  set(SO_AGE 3)
246endif()
247
248if(WITH_JPEG8)
249  set(JPEG_LIB_VERSION 80)
250elseif(WITH_JPEG7)
251  set(JPEG_LIB_VERSION 70)
252else()
253  set(JPEG_LIB_VERSION 62)
254endif()
255
256math(EXPR JPEG_LIB_VERSION_DIV10 "${JPEG_LIB_VERSION} / 10")
257math(EXPR JPEG_LIB_VERSION_MOD10 "${JPEG_LIB_VERSION} % 10")
258if(JPEG_LIB_VERSION STREQUAL "62")
259  set(DEFAULT_SO_MAJOR_VERSION ${JPEG_LIB_VERSION})
260else()
261  set(DEFAULT_SO_MAJOR_VERSION ${JPEG_LIB_VERSION_DIV10})
262endif()
263if(JPEG_LIB_VERSION STREQUAL "80")
264  set(DEFAULT_SO_MINOR_VERSION 2)
265else()
266  set(DEFAULT_SO_MINOR_VERSION 0)
267endif()
268
269# This causes SO_MAJOR_VERSION/SO_MINOR_VERSION to reset to defaults if
270# WITH_JPEG7 or WITH_JPEG8 has changed.
271if((DEFINED WITH_JPEG7_INT AND NOT WITH_JPEG7 EQUAL WITH_JPEG7_INT) OR
272  (DEFINED WITH_JPEG8_INT AND NOT WITH_JPEG8 EQUAL WITH_JPEG8_INT))
273  set(FORCE_SO_VERSION "FORCE")
274endif()
275set(WITH_JPEG7_INT ${WITH_JPEG7} CACHE INTERNAL "")
276set(WITH_JPEG8_INT ${WITH_JPEG8} CACHE INTERNAL "")
277
278set(SO_MAJOR_VERSION ${DEFAULT_SO_MAJOR_VERSION} CACHE STRING
279  "Major version of the libjpeg API shared library (default: ${DEFAULT_SO_MAJOR_VERSION})"
280  ${FORCE_SO_VERSION})
281set(SO_MINOR_VERSION ${DEFAULT_SO_MINOR_VERSION} CACHE STRING
282  "Minor version of the libjpeg API shared library (default: ${DEFAULT_SO_MINOR_VERSION})"
283  ${FORCE_SO_VERSION})
284
285set(JPEG_LIB_VERSION_DECIMAL "${JPEG_LIB_VERSION_DIV10}.${JPEG_LIB_VERSION_MOD10}")
286message(STATUS "Emulating libjpeg API/ABI v${JPEG_LIB_VERSION_DECIMAL} (WITH_JPEG7 = ${WITH_JPEG7}, WITH_JPEG8 = ${WITH_JPEG8})")
287message(STATUS "libjpeg API shared library version = ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION}")
288
289# Because the TurboJPEG API library uses versioned symbols and changes the
290# names of functions whenever they are modified in a backward-incompatible
291# manner, it is always backward-ABI-compatible with itself, so the major and
292# minor SO versions don't change.  However, we increase the middle number (the
293# SO "age") whenever functions are added to the API.
294set(TURBOJPEG_SO_MAJOR_VERSION 0)
295set(TURBOJPEG_SO_VERSION 0.2.0)
296
297
298###############################################################################
299# COMPILER SETTINGS
300###############################################################################
301
302if(MSVC)
303  option(WITH_CRT_DLL
304    "Link all ${CMAKE_PROJECT_NAME} libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.)  The default is to use the C run-time DLL only with the libraries and executables that need it."
305    FALSE)
306  if(NOT WITH_CRT_DLL)
307    # Use the static C library for all build types
308    foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
309      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
310      if(${var} MATCHES "/MD")
311        string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
312      endif()
313    endforeach()
314  endif()
315  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /wd4996")
316endif()
317
318if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
319  # Use the maximum optimization level for release builds
320  foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
321    if(${var} MATCHES "-O2")
322      string(REGEX REPLACE "-O2" "-O3" ${var} "${${var}}")
323    endif()
324  endforeach()
325endif()
326
327if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
328  if(CMAKE_C_COMPILER_ID MATCHES "SunPro")
329    # Use the maximum optimization level for release builds
330    foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
331      if(${var} MATCHES "-xO3")
332        string(REGEX REPLACE "-xO3" "-xO5" ${var} "${${var}}")
333      endif()
334      if(${var} MATCHES "-xO2")
335        string(REGEX REPLACE "-xO2" "-xO5" ${var} "${${var}}")
336      endif()
337    endforeach()
338  endif()
339endif()
340
341string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
342
343set(EFFECTIVE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
344message(STATUS "Compiler flags = ${EFFECTIVE_C_FLAGS}")
345
346set(EFFECTIVE_LD_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UC}}")
347message(STATUS "Linker flags = ${EFFECTIVE_LD_FLAGS}")
348
349include(CheckCSourceCompiles)
350include(CheckIncludeFiles)
351include(CheckTypeSize)
352
353check_type_size("size_t" SIZE_T)
354check_type_size("unsigned long" UNSIGNED_LONG)
355
356if(SIZE_T EQUAL UNSIGNED_LONG)
357  check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc;  return __builtin_ctzl(a); }"
358    HAVE_BUILTIN_CTZL)
359endif()
360if(MSVC)
361  check_include_files("intrin.h" HAVE_INTRIN_H)
362endif()
363
364if(UNIX)
365  # Check for headers
366  check_include_files(locale.h HAVE_LOCALE_H)
367  check_include_files(stddef.h HAVE_STDDEF_H)
368  check_include_files(stdlib.h HAVE_STDLIB_H)
369  check_include_files(sys/types.h NEED_SYS_TYPES_H)
370
371  # Check for functions
372  include(CheckSymbolExists)
373  check_symbol_exists(memset string.h HAVE_MEMSET)
374  check_symbol_exists(memcpy string.h HAVE_MEMCPY)
375  if(NOT HAVE_MEMSET AND NOT HAVE_MEMCPY)
376    set(NEED_BSD_STRINGS 1)
377  endif()
378
379  # Check for types
380  check_type_size("unsigned char" UNSIGNED_CHAR)
381  check_type_size("unsigned short" UNSIGNED_SHORT)
382
383  # Check for compiler features
384  check_c_source_compiles("int main(void) { typedef struct undefined_structure *undef_struct_ptr;  undef_struct_ptr ptr = 0;  return ptr != 0; }"
385    INCOMPLETE_TYPES)
386  if(INCOMPLETE_TYPES)
387    message(STATUS "Compiler supports pointers to undefined structures.")
388  else()
389    set(INCOMPLETE_TYPES_BROKEN 1)
390    message(STATUS "Compiler does not support pointers to undefined structures.")
391  endif()
392
393  if(CMAKE_CROSSCOMPILING)
394    set(RIGHT_SHIFT_IS_UNSIGNED 0)
395  else()
396    include(CheckCSourceRuns)
397    check_c_source_runs("
398      #include <stdio.h>
399      #include <stdlib.h>
400      int is_shifting_signed (long arg) {
401        long res = arg >> 4;
402        if (res == -0x7F7E80CL)
403          return 1; /* right shift is signed */
404        /* see if unsigned-shift hack will fix it. */
405        /* we can't just test exact value since it depends on width of long... */
406        res |= (~0L) << (32-4);
407        if (res == -0x7F7E80CL)
408          return 0; /* right shift is unsigned */
409        printf(\"Right shift isn't acting as I expect it to.\\\\n\");
410        printf(\"I fear the JPEG software will not work at all.\\\\n\\\\n\");
411        return 0; /* try it with unsigned anyway */
412      }
413      int main (void) {
414        exit(is_shifting_signed(-0x7F7E80B1L));
415      }" RIGHT_SHIFT_IS_UNSIGNED)
416  endif()
417
418  if(CMAKE_CROSSCOMPILING)
419    set(__CHAR_UNSIGNED__ 0)
420  else()
421    check_c_source_runs("int main(void) { return ((char) -1 < 0); }"
422      __CHAR_UNSIGNED__)
423  endif()
424endif()
425
426if(MSVC)
427  set(INLINE_OPTIONS "__inline;inline")
428else()
429  set(INLINE_OPTIONS "__inline__;inline")
430endif()
431option(FORCE_INLINE "Force function inlining" TRUE)
432boolean_number(FORCE_INLINE)
433if(FORCE_INLINE)
434  if(MSVC)
435    list(INSERT INLINE_OPTIONS 0 "__forceinline")
436  else()
437    list(INSERT INLINE_OPTIONS 0 "inline __attribute__((always_inline))")
438    list(INSERT INLINE_OPTIONS 0 "__inline__ __attribute__((always_inline))")
439  endif()
440endif()
441foreach(inline ${INLINE_OPTIONS})
442  check_c_source_compiles("${inline} static int foo(void) { return 0; } int main(void) { return foo(); }"
443    INLINE_WORKS)
444  if(INLINE_WORKS)
445    set(INLINE ${inline})
446    break()
447  endif()
448endforeach()
449if(NOT INLINE_WORKS)
450  message(FATAL_ERROR "Could not determine how to inline functions.")
451endif()
452message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})")
453
454if(UNIX AND NOT APPLE)
455  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map "VERS_1 { global: *; };")
456  set(CMAKE_REQUIRED_FLAGS
457    "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/conftest.map")
458  check_c_source_compiles("int main(void) { return 0; }" HAVE_VERSION_SCRIPT)
459  set(CMAKE_REQUIRED_FLAGS)
460  file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map)
461  if(HAVE_VERSION_SCRIPT)
462    message(STATUS "Linker supports GNU-style version scripts")
463    set(MAPFLAG "-Wl,--version-script,")
464    set(TJMAPFLAG "-Wl,--version-script,")
465  else()
466    message(STATUS "Linker does not support GNU-style version scripts")
467    if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
468      # The Solaris linker doesn't like our version script for the libjpeg API
469      # library, but the version script for the TurboJPEG API library should
470      # still work.
471      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map
472        "VERS_1 { global: foo;  local: *; }; VERS_2 { global: foo2; } VERS_1;")
473      set(CMAKE_REQUIRED_FLAGS "-Wl,-M,${CMAKE_CURRENT_BINARY_DIR}/conftest.map -shared")
474      check_c_source_compiles("int foo() { return 0; } int foo2() { return 2; }"
475        HAVE_MAPFILE)
476      set(CMAKE_REQUIRED_FLAGS)
477      file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map)
478      if(HAVE_MAPFILE)
479        message(STATUS "Linker supports mapfiles")
480        set(TJMAPFLAG "-Wl,-M,")
481      else()
482        message(STATUS "Linker does not support mapfiles")
483      endif()
484    endif()
485  endif()
486endif()
487
488# Generate files
489if(WIN32)
490  configure_file(win/jconfig.h.in jconfig.h)
491else()
492  configure_file(jconfig.h.in jconfig.h)
493endif()
494configure_file(jconfigint.h.in jconfigint.h)
495if(UNIX)
496  configure_file(libjpeg.map.in libjpeg.map)
497endif()
498
499# Include directories and compiler definitions
500include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
501
502
503###############################################################################
504# TARGETS
505###############################################################################
506
507if(CMAKE_EXECUTABLE_SUFFIX_TMP)
508  set(CMAKE_EXECUTABLE_SUFFIX ${CMAKE_EXECUTABLE_SUFFIX_TMP})
509endif()
510message(STATUS "CMAKE_EXECUTABLE_SUFFIX = ${CMAKE_EXECUTABLE_SUFFIX}")
511
512set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
513  jcicc.c jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c
514  jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c
515  jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdicc.c jdinput.c
516  jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c
517  jdtrans.c jerror.c jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c
518  jidctint.c jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
519
520if(WITH_ARITH_ENC OR WITH_ARITH_DEC)
521  set(JPEG_SOURCES ${JPEG_SOURCES} jaricom.c)
522endif()
523
524if(WITH_ARITH_ENC)
525  set(JPEG_SOURCES ${JPEG_SOURCES} jcarith.c)
526endif()
527
528if(WITH_ARITH_DEC)
529  set(JPEG_SOURCES ${JPEG_SOURCES} jdarith.c)
530endif()
531
532if(WITH_SIMD)
533  add_subdirectory(simd)
534elseif(NOT WITH_12BIT)
535  message(STATUS "SIMD extensions: None (WITH_SIMD = ${WITH_SIMD})")
536endif()
537if(WITH_SIMD)
538  message(STATUS "SIMD extensions: ${CPU_TYPE} (WITH_SIMD = ${WITH_SIMD})")
539  if(MSVC_IDE)
540    set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
541  endif()
542else()
543  add_library(simd OBJECT jsimd_none.c)
544endif()
545
546if(WITH_JAVA)
547  add_subdirectory(java)
548endif()
549
550if(ENABLE_SHARED)
551  add_subdirectory(sharedlib)
552endif()
553
554if(ENABLE_STATIC)
555  add_library(jpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd>
556    ${SIMD_OBJS})
557  if(NOT MSVC)
558    set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
559  endif()
560endif()
561
562if(WITH_TURBOJPEG)
563  if(ENABLE_SHARED)
564    set(TURBOJPEG_SOURCES ${JPEG_SOURCES} $<TARGET_OBJECTS:simd> ${SIMD_OBJS}
565      turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c rdppm.c
566      wrbmp.c wrppm.c)
567    set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile)
568    if(WITH_JAVA)
569      set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES} turbojpeg-jni.c)
570      include_directories(${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
571      set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg-mapfile.jni)
572    endif()
573    add_library(turbojpeg SHARED ${TURBOJPEG_SOURCES})
574    set_property(TARGET turbojpeg PROPERTY COMPILE_FLAGS
575      "-DBMP_SUPPORTED -DPPM_SUPPORTED")
576    if(WIN32)
577      set_target_properties(turbojpeg PROPERTIES DEFINE_SYMBOL DLLDEFINE)
578    endif()
579    if(MINGW)
580      set_target_properties(turbojpeg PROPERTIES LINK_FLAGS -Wl,--kill-at)
581    endif()
582    if(APPLE AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET OR
583                  CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.4))
584      if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
585        set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
586      endif()
587      set_target_properties(turbojpeg PROPERTIES MACOSX_RPATH 1)
588    endif()
589    set_target_properties(turbojpeg PROPERTIES
590      SOVERSION ${TURBOJPEG_SO_MAJOR_VERSION} VERSION ${TURBOJPEG_SO_VERSION})
591    if(TJMAPFLAG)
592      set_target_properties(turbojpeg PROPERTIES
593        LINK_FLAGS "${TJMAPFLAG}${TJMAPFILE}")
594    endif()
595
596    add_executable(tjunittest tjunittest.c tjutil.c md5/md5.c md5/md5hl.c)
597    target_link_libraries(tjunittest turbojpeg)
598
599    add_executable(tjbench tjbench.c tjutil.c)
600    target_link_libraries(tjbench turbojpeg)
601    if(UNIX)
602      target_link_libraries(tjbench m)
603    endif()
604
605    add_executable(tjexample tjexample.c)
606    target_link_libraries(tjexample turbojpeg)
607  endif()
608
609  if(ENABLE_STATIC)
610    add_library(turbojpeg-static STATIC ${JPEG_SOURCES} $<TARGET_OBJECTS:simd>
611      ${SIMD_OBJS} turbojpeg.c transupp.c jdatadst-tj.c jdatasrc-tj.c rdbmp.c
612      rdppm.c wrbmp.c wrppm.c)
613    set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS
614      "-DBMP_SUPPORTED -DPPM_SUPPORTED")
615    if(NOT MSVC)
616      set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
617    endif()
618
619    add_executable(tjunittest-static tjunittest.c tjutil.c md5/md5.c
620      md5/md5hl.c)
621    target_link_libraries(tjunittest-static turbojpeg-static)
622
623    add_executable(tjbench-static tjbench.c tjutil.c)
624    target_link_libraries(tjbench-static turbojpeg-static)
625    if(UNIX)
626      target_link_libraries(tjbench-static m)
627    endif()
628  endif()
629endif()
630
631if(WIN32)
632  set(USE_SETMODE "-DUSE_SETMODE")
633endif()
634if(WITH_12BIT)
635  set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
636else()
637  set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
638  set(CJPEG_BMP_SOURCES rdbmp.c rdtarga.c)
639  set(DJPEG_BMP_SOURCES wrbmp.c wrtarga.c)
640endif()
641
642if(ENABLE_STATIC)
643  add_executable(cjpeg-static cjpeg.c cdjpeg.c rdgif.c rdppm.c rdswitch.c
644    ${CJPEG_BMP_SOURCES})
645  set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
646  target_link_libraries(cjpeg-static jpeg-static)
647
648  add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrgif.c
649    wrppm.c ${DJPEG_BMP_SOURCES})
650  set_property(TARGET djpeg-static PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
651  target_link_libraries(djpeg-static jpeg-static)
652
653  add_executable(jpegtran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
654  target_link_libraries(jpegtran-static jpeg-static)
655  set_property(TARGET jpegtran-static PROPERTY COMPILE_FLAGS "${USE_SETMODE}")
656endif()
657
658add_executable(rdjpgcom rdjpgcom.c)
659
660add_executable(wrjpgcom wrjpgcom.c)
661
662
663###############################################################################
664# TESTS
665###############################################################################
666
667add_subdirectory(md5)
668
669if(MSVC_IDE)
670  set(OBJDIR "\${CTEST_CONFIGURATION_TYPE}/")
671else()
672  set(OBJDIR "")
673endif()
674
675enable_testing()
676
677if(WITH_12BIT)
678  set(TESTORIG testorig12.jpg)
679  set(MD5_JPEG_RGB_ISLOW 9d7369207c520d37f2c1cbfcb82b2964)
680  set(MD5_JPEG_RGB_ISLOW2 a00bd20d8ae49684640ef7177d2e0b64)
681  set(MD5_PPM_RGB_ISLOW f3301d2219783b8b3d942b7239fa50c0)
682  set(MD5_JPEG_422_IFAST_OPT 7322e3bd2f127f7de4b40d4480ce60e4)
683  set(MD5_PPM_422_IFAST 79807fa552899e66a04708f533e16950)
684  set(MD5_PPM_422M_IFAST 07737bfe8a7c1c87aaa393a0098d16b0)
685  set(MD5_JPEG_420_IFAST_Q100_PROG a1da220b5604081863a504297ed59e55)
686  set(MD5_PPM_420_Q100_IFAST 1b3730122709f53d007255e8dfd3305e)
687  set(MD5_PPM_420M_Q100_IFAST 980a1a3c5bf9510022869d30b7d26566)
688  set(MD5_JPEG_GRAY_ISLOW 235c90707b16e2e069f37c888b2636d9)
689  set(MD5_PPM_GRAY_ISLOW 7213c10af507ad467da5578ca5ee1fca)
690  set(MD5_PPM_GRAY_ISLOW_RGB e96ee81c30a6ed422d466338bd3de65d)
691  set(MD5_JPEG_420S_IFAST_OPT 7af8e60be4d9c227ec63ac9b6630855e)
692
693  set(MD5_JPEG_3x2_FLOAT_PROG_SSE a8c17daf77b457725ec929e215b603f8)
694  set(MD5_PPM_3x2_FLOAT_SSE 42876ab9e5c2f76a87d08db5fbd57956)
695  set(MD5_JPEG_3x2_FLOAT_PROG_32BIT a8c17daf77b457725ec929e215b603f8)
696  set(MD5_PPM_3x2_FLOAT_32BIT ${MD5_PPM_3x2_FLOAT_SSE})
697  set(MD5_JPEG_3x2_FLOAT_PROG_64BIT ${MD5_JPEG_3x2_FLOAT_PROG_32BIT})
698  set(MD5_PPM_3x2_FLOAT_64BIT ${MD5_PPM_3x2_FLOAT_SSE})
699  set(MD5_JPEG_3x2_FLOAT_PROG_387 bc6dbbefac2872f6b9d6c4a0ae60c3c0)
700  set(MD5_PPM_3x2_FLOAT_387 bcc5723c61560463ac60f772e742d092)
701  set(MD5_JPEG_3x2_FLOAT_PROG_MSVC e27840755870fa849872e58aa0cd1400)
702  set(MD5_PPM_3x2_FLOAT_MSVC 6c2880b83bb1aa41dfe330e7a9768690)
703
704  set(MD5_JPEG_3x2_IFAST_PROG 1396cc2b7185cfe943d408c9d305339e)
705  set(MD5_PPM_3x2_IFAST 3975985ef6eeb0a2cdc58daa651ccc00)
706  set(MD5_PPM_420M_ISLOW_2_1 4ca6be2a6f326ff9eaab63e70a8259c0)
707  set(MD5_PPM_420M_ISLOW_15_8 12aa9f9534c1b3d7ba047322226365eb)
708  set(MD5_PPM_420M_ISLOW_13_8 f7e22817c7b25e1393e4ec101e9d4e96)
709  set(MD5_PPM_420M_ISLOW_11_8 800a16f9f4dc9b293197bfe11be10a82)
710  set(MD5_PPM_420M_ISLOW_9_8 06b7a92a9bc69f4dc36ec40f1937d55c)
711  set(MD5_PPM_420M_ISLOW_7_8 3ec444a14a4ab4eab88ffc49c48eca43)
712  set(MD5_PPM_420M_ISLOW_3_4 3e726b7ea872445b19437d1c1d4f0d93)
713  set(MD5_PPM_420M_ISLOW_5_8 a8a771abdc94301d20ffac119b2caccd)
714  set(MD5_PPM_420M_ISLOW_1_2 b419124dd5568b085787234866102866)
715  set(MD5_PPM_420M_ISLOW_3_8 343d19015531b7bbe746124127244fa8)
716  set(MD5_PPM_420M_ISLOW_1_4 35fd59d866e44659edfa3c18db2a3edb)
717  set(MD5_PPM_420M_ISLOW_1_8 ccaed48ac0aedefda5d4abe4013f4ad7)
718  set(MD5_PPM_420_ISLOW_SKIP15_31 86664cd9dc956536409e44e244d20a97)
719  set(MD5_PPM_420_ISLOW_PROG_CROP62x62_71_71 452a21656115a163029cfba5c04fa76a)
720  set(MD5_PPM_444_ISLOW_SKIP1_6 ef63901f71ef7a75cd78253fc0914f84)
721  set(MD5_PPM_444_ISLOW_PROG_CROP98x98_13_13 15b173fb5872d9575572fbcc1b05956f)
722  set(MD5_JPEG_CROP cdb35ff4b4519392690ea040c56ea99c)
723else()
724  set(TESTORIG testorig.jpg)
725  set(MD5_JPEG_RGB_ISLOW 1d44a406f61da743b5fd31c0a9abdca3)
726  set(MD5_JPEG_RGB_ISLOW2 31d121e57b6c2934c890a7fc7763bcd4)
727  set(MD5_PPM_RGB_ISLOW 00a257f5393fef8821f2b88ac7421291)
728  set(MD5_BMP_RGB_ISLOW_565 f07d2e75073e4bb10f6c6f4d36e2e3be)
729  set(MD5_BMP_RGB_ISLOW_565D 4cfa0928ef3e6bb626d7728c924cfda4)
730  set(MD5_JPEG_422_IFAST_OPT 2540287b79d913f91665e660303ab2c8)
731  set(MD5_PPM_422_IFAST 35bd6b3f833bad23de82acea847129fa)
732  set(MD5_PPM_422M_IFAST 8dbc65323d62cca7c91ba02dd1cfa81d)
733  set(MD5_BMP_422M_IFAST_565 3294bd4d9a1f2b3d08ea6020d0db7065)
734  set(MD5_BMP_422M_IFAST_565D da98c9c7b6039511be4a79a878a9abc1)
735  set(MD5_JPEG_420_IFAST_Q100_PROG 990cbe0329c882420a2094da7e5adade)
736  set(MD5_PPM_420_Q100_IFAST 5a732542015c278ff43635e473a8a294)
737  set(MD5_PPM_420M_Q100_IFAST ff692ee9323a3b424894862557c092f1)
738  set(MD5_JPEG_GRAY_ISLOW 72b51f894b8f4a10b3ee3066770aa38d)
739  set(MD5_PPM_GRAY_ISLOW 8d3596c56eace32f205deccc229aa5ed)
740  set(MD5_PPM_GRAY_ISLOW_RGB 116424ac07b79e5e801f00508eab48ec)
741  set(MD5_BMP_GRAY_ISLOW_565 12f78118e56a2f48b966f792fedf23cc)
742  set(MD5_BMP_GRAY_ISLOW_565D bdbbd616441a24354c98553df5dc82db)
743  set(MD5_JPEG_420S_IFAST_OPT 388708217ac46273ca33086b22827ed8)
744
745  set(MD5_JPEG_3x2_FLOAT_PROG_SSE 343e3f8caf8af5986ebaf0bdc13b5c71)
746  set(MD5_PPM_3x2_FLOAT_SSE 1a75f36e5904d6fc3a85a43da9ad89bb)
747  set(MD5_JPEG_3x2_FLOAT_PROG_32BIT 9bca803d2042bd1eb03819e2bf92b3e5)
748  set(MD5_PPM_3x2_FLOAT_32BIT f6bfab038438ed8f5522fbd33595dcdc)
749  set(MD5_JPEG_3x2_FLOAT_PROG_64BIT ${MD5_JPEG_3x2_FLOAT_PROG_32BIT})
750  set(MD5_PPM_3x2_FLOAT_64BIT 0e917a34193ef976b679a6b069b1be26)
751  set(MD5_JPEG_3x2_FLOAT_PROG_387 1657664a410e0822c924b54f6f65e6e9)
752  set(MD5_PPM_3x2_FLOAT_387 cb0a1f027f3d2917c902b5640214e025)
753  set(MD5_JPEG_3x2_FLOAT_PROG_MSVC 7999ce9cd0ee9b6c7043b7351ab7639d)
754  set(MD5_PPM_3x2_FLOAT_MSVC 28cdc448a6b75e97892f0e0f8d4b21f3)
755
756  set(MD5_JPEG_3x2_IFAST_PROG 1ee5d2c1a77f2da495f993c8c7cceca5)
757  set(MD5_PPM_3x2_IFAST fd283664b3b49127984af0a7f118fccd)
758  set(MD5_JPEG_420_ISLOW_ARI e986fb0a637a8d833d96e8a6d6d84ea1)
759  set(MD5_JPEG_444_ISLOW_PROGARI 0a8f1c8f66e113c3cf635df0a475a617)
760  set(MD5_PPM_420M_IFAST_ARI 72b59a99bcf1de24c5b27d151bde2437)
761  set(MD5_JPEG_420_ISLOW 9a68f56bc76e466aa7e52f415d0f4a5f)
762  set(MD5_PPM_420M_ISLOW_2_1 9f9de8c0612f8d06869b960b05abf9c9)
763  set(MD5_PPM_420M_ISLOW_15_8 b6875bc070720b899566cc06459b63b7)
764  set(MD5_PPM_420M_ISLOW_13_8 bc3452573c8152f6ae552939ee19f82f)
765  set(MD5_PPM_420M_ISLOW_11_8 d8cc73c0aaacd4556569b59437ba00a5)
766  set(MD5_PPM_420M_ISLOW_9_8 d25e61bc7eac0002f5b393aa223747b6)
767  set(MD5_PPM_420M_ISLOW_7_8 ddb564b7c74a09494016d6cd7502a946)
768  set(MD5_PPM_420M_ISLOW_3_4 8ed8e68808c3fbc4ea764fc9d2968646)
769  set(MD5_PPM_420M_ISLOW_5_8 a3363274999da2366a024efae6d16c9b)
770  set(MD5_PPM_420M_ISLOW_1_2 e692a315cea26b988c8e8b29a5dbcd81)
771  set(MD5_PPM_420M_ISLOW_3_8 79eca9175652ced755155c90e785a996)
772  set(MD5_PPM_420M_ISLOW_1_4 79cd778f8bf1a117690052cacdd54eca)
773  set(MD5_PPM_420M_ISLOW_1_8 391b3d4aca640c8567d6f8745eb2142f)
774  set(MD5_BMP_420_ISLOW_256 4980185e3776e89bd931736e1cddeee6)
775  set(MD5_BMP_420_ISLOW_565 bf9d13e16c4923b92e1faa604d7922cb)
776  set(MD5_BMP_420_ISLOW_565D 6bde71526acc44bcff76f696df8638d2)
777  set(MD5_BMP_420M_ISLOW_565 8dc0185245353cfa32ad97027342216f)
778  set(MD5_BMP_420M_ISLOW_565D ce034037d212bc403330df6f915c161b)
779  set(MD5_PPM_420_ISLOW_SKIP15_31 c4c65c1e43d7275cd50328a61e6534f0)
780  set(MD5_PPM_420_ISLOW_ARI_SKIP16_139 087c6b123db16ac00cb88c5b590bb74a)
781  set(MD5_PPM_420_ISLOW_PROG_CROP62x62_71_71 26eb36ccc7d1f0cb80cdabb0ac8b5d99)
782  set(MD5_PPM_420_ISLOW_ARI_CROP53x53_4_4 886c6775af22370257122f8b16207e6d)
783  set(MD5_PPM_444_ISLOW_SKIP1_6 5606f86874cf26b8fcee1117a0a436a6)
784  set(MD5_PPM_444_ISLOW_PROG_CROP98x98_13_13 db87dc7ce26bcdc7a6b56239ce2b9d6c)
785  set(MD5_PPM_444_ISLOW_ARI_CROP37x37_0_0 cb57b32bd6d03e35432362f7bf184b6d)
786  set(MD5_JPEG_CROP b4197f377e621c4e9b1d20471432610d)
787endif()
788
789if(WITH_JAVA)
790  add_test(TJUnitTest
791    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
792      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
793      TJUnitTest)
794  add_test(TJUnitTest-yuv
795    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
796      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
797      TJUnitTest -yuv)
798  add_test(TJUnitTest-yuv-nopad
799    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
800      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
801      TJUnitTest -yuv -noyuvpad)
802  add_test(TJUnitTest-bi
803    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
804      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
805      TJUnitTest -bi)
806  add_test(TJUnitTest-bi-yuv
807    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
808      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
809      TJUnitTest -bi -yuv)
810  add_test(TJUnitTest-bi-yuv-nopad
811    ${Java_JAVA_EXECUTABLE} ${JAVAARGS} -cp java/turbojpeg.jar
812      -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR}
813      TJUnitTest -bi -yuv -noyuvpad)
814endif()
815
816set(TEST_LIBTYPES "")
817if(ENABLE_SHARED)
818  set(TEST_LIBTYPES ${TEST_LIBTYPES} shared)
819endif()
820if(ENABLE_STATIC)
821  set(TEST_LIBTYPES ${TEST_LIBTYPES} static)
822endif()
823
824set(TESTIMAGES ${CMAKE_CURRENT_SOURCE_DIR}/testimages)
825set(MD5CMP ${CMAKE_CURRENT_BINARY_DIR}/md5/md5cmp)
826if(CMAKE_CROSSCOMPILING)
827  file(RELATIVE_PATH TESTIMAGES ${CMAKE_CURRENT_BINARY_DIR} ${TESTIMAGES})
828  file(RELATIVE_PATH MD5CMP ${CMAKE_CURRENT_BINARY_DIR} ${MD5CMP})
829endif()
830
831# The output of the floating point DCT/IDCT algorithms differs depending on the
832# type of floating point math used, so the FLOATTEST CMake variable must be
833# set in order to tell the testing system which floating point results it
834# should expect:
835#
836# sse = validate against the expected results from the libjpeg-turbo SSE SIMD
837#       extensions
838# 32bit = validate against the expected results from the C code when running on
839#         a 32-bit FPU (or when SSE is being used for floating point math,
840#         which is generally the default with x86-64 compilers)
841# 64bit = validate against the expected results from the C code when running
842#         on a 64-bit FPU
843# 387 = validate against the expected results from the C code when the 387 FPU
844#       is being used for floating point math (which is generally the default
845#       with x86 compilers)
846# msvc = validate against the expected results from the C code when compiled
847#        with a 32-bit version of Visual C++
848
849if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
850  if(WITH_SIMD)
851    set(DEFAULT_FLOATTEST sse)
852  elseif(CPU_TYPE STREQUAL "x86_64")
853    set(DEFAULT_FLOATTEST 32bit)
854  elseif(CPU_TYPE STREQUAL "i386" AND MSVC)
855    set(DEFAULT_FLOATTEST msvc)
856  endif()
857else()
858  if(BITS EQUAL 64)
859    set(DEFAULT_FLOATTEST 64bit)
860  elseif(BITS EQUAL 32)
861    set(DEFAULT_FLOATTEST 32bit)
862  endif()
863endif()
864
865# This causes FLOATTEST to reset to the default value if WITH_SIMD has
866# changed.
867if(DEFINED WITH_SIMD_INT AND NOT WITH_SIMD EQUAL WITH_SIMD_INT)
868  set(FORCE_FLOATTEST "FORCE")
869endif()
870set(WITH_SIMD_INT ${WITH_SIMD} CACHE INTERNAL "")
871set(FLOATTEST ${DEFAULT_FLOATTEST} CACHE STRING
872  "The type of floating point math used by the floating point DCT/IDCT algorithms.  This tells the testing system which numerical results it should expect from those tests.  [sse = libjpeg-turbo x86/x86-64 SIMD extensions, 32bit = generic 32-bit FPU or SSE, 64bit = generic 64-bit FPU, 387 = 387 FPU, msvc = 32-bit Visual Studio] (default = ${DEFAULT_FLOATTEST})"
873  ${FORCE_FLOATTEST})
874message(STATUS "FLOATTEST = ${FLOATTEST}")
875
876if(FLOATTEST)
877  string(TOUPPER ${FLOATTEST} FLOATTEST_UC)
878  string(TOLOWER ${FLOATTEST} FLOATTEST)
879  if(NOT FLOATTEST STREQUAL "sse" AND NOT FLOATTEST STREQUAL "32bit" AND
880    NOT FLOATTEST STREQUAL "64bit" AND NOT FLOATTEST STREQUAL "387" AND
881    NOT FLOATTEST STREQUAL "msvc")
882    message(FATAL_ERROR "\"${FLOATTEST}\" is not a valid value for FLOATTEST.")
883  endif()
884endif()
885
886foreach(libtype ${TEST_LIBTYPES})
887  if(libtype STREQUAL "static")
888    set(suffix -static)
889  endif()
890  if(WITH_TURBOJPEG)
891    add_test(tjunittest-${libtype} tjunittest${suffix})
892    add_test(tjunittest-${libtype}-alloc tjunittest${suffix} -alloc)
893    add_test(tjunittest-${libtype}-yuv tjunittest${suffix} -yuv)
894    add_test(tjunittest-${libtype}-yuv-alloc tjunittest${suffix} -yuv -alloc)
895    add_test(tjunittest-${libtype}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)
896    add_test(tjunittest-${libtype}-bmp tjunittest${suffix} -bmp)
897
898    set(MD5_PPM_GRAY_TILE 89d3ca21213d9d864b50b4e4e7de4ca6)
899    set(MD5_PPM_420_8x8_TILE 847fceab15c5b7b911cb986cf0f71de3)
900    set(MD5_PPM_420_16x16_TILE ca45552a93687e078f7137cc4126a7b0)
901    set(MD5_PPM_420_32x32_TILE d8676f1d6b68df358353bba9844f4a00)
902    set(MD5_PPM_420_64x64_TILE 4e4c1a3d7ea4bace4f868bcbe83b7050)
903    set(MD5_PPM_420_128x128_TILE f24c3429c52265832beab9df72a0ceae)
904    set(MD5_PPM_420M_8x8_TILE bc25320e1f4c31ce2e610e43e9fd173c)
905    set(MD5_PPM_420M_TILE 75ffdf14602258c5c189522af57fa605)
906    set(MD5_PPM_422_8x8_TILE d83dacd9fc73b0a6f10c09acad64eb1e)
907    set(MD5_PPM_422_16x16_TILE 35077fb610d72dd743b1eb0cbcfe10fb)
908    set(MD5_PPM_422_32x32_TILE e6902ed8a449ecc0f0d6f2bf945f65f7)
909    set(MD5_PPM_422_64x64_TILE 2b4502a8f316cedbde1da7bce3d2231e)
910    set(MD5_PPM_422_128x128_TILE f0b5617d578f5e13c8eee215d64d4877)
911    set(MD5_PPM_422M_8x8_TILE 828941d7f41cd6283abd6beffb7fd51d)
912    set(MD5_PPM_422M_TILE e877ae1324c4a280b95376f7f018172f)
913    set(MD5_PPM_444_TILE 7964e41e67cfb8d0a587c0aa4798f9c3)
914
915    # Test compressing from/decompressing to an arbitrary subregion of a larger
916    # image buffer
917    add_test(tjbench-${libtype}-tile-cp
918      ${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
919        testout_tile.ppm)
920    add_test(tjbench-${libtype}-tile
921      tjbench${suffix} testout_tile.ppm 95 -rgb -quiet -tile -benchtime 0.01
922        -warmup 0)
923    set_tests_properties(tjbench-${libtype}-tile
924      PROPERTIES DEPENDS tjbench-${libtype}-tile-cp)
925
926    foreach(tile 8 16 32 64 128)
927      add_test(tjbench-${libtype}-tile-gray-${tile}x${tile}-cmp
928        ${MD5CMP} ${MD5_PPM_GRAY_TILE}
929          testout_tile_GRAY_Q95_${tile}x${tile}.ppm)
930      foreach(subsamp 420 422)
931        add_test(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
932          ${MD5CMP} ${MD5_PPM_${subsamp}_${tile}x${tile}_TILE}
933            testout_tile_${subsamp}_Q95_${tile}x${tile}.ppm)
934      endforeach()
935      add_test(tjbench-${libtype}-tile-444-${tile}x${tile}-cmp
936        ${MD5CMP} ${MD5_PPM_444_TILE}
937          testout_tile_444_Q95_${tile}x${tile}.ppm)
938      foreach(subsamp gray 420 422 444)
939        set_tests_properties(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
940          PROPERTIES DEPENDS tjbench-${libtype}-tile)
941      endforeach()
942    endforeach()
943
944    add_test(tjbench-${libtype}-tilem-cp
945      ${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
946        testout_tilem.ppm)
947    add_test(tjbench-${libtype}-tilem
948      tjbench${suffix} testout_tilem.ppm 95 -rgb -fastupsample -quiet -tile
949        -benchtime 0.01 -warmup 0)
950    set_tests_properties(tjbench-${libtype}-tilem
951      PROPERTIES DEPENDS tjbench-${libtype}-tilem-cp)
952
953    add_test(tjbench-${libtype}-tile-420m-8x8-cmp
954      ${MD5CMP} ${MD5_PPM_420M_8x8_TILE} testout_tilem_420_Q95_8x8.ppm)
955    add_test(tjbench-${libtype}-tile-422m-8x8-cmp
956      ${MD5CMP} ${MD5_PPM_422M_8x8_TILE} testout_tilem_422_Q95_8x8.ppm)
957    foreach(tile 16 32 64 128)
958      foreach(subsamp 420 422)
959        add_test(tjbench-${libtype}-tile-${subsamp}m-${tile}x${tile}-cmp
960          ${MD5CMP} ${MD5_PPM_${subsamp}M_TILE}
961            testout_tilem_${subsamp}_Q95_${tile}x${tile}.ppm)
962      endforeach()
963    endforeach()
964    foreach(tile 8 16 32 64 128)
965      foreach(subsamp 420 422)
966        set_tests_properties(tjbench-${libtype}-tile-${subsamp}m-${tile}x${tile}-cmp
967          PROPERTIES DEPENDS tjbench-${libtype}-tilem)
968      endforeach()
969    endforeach()
970  endif()
971
972  # These tests are carefully crafted to provide full coverage of as many of
973  # the underlying algorithms as possible (including all of the
974  # SIMD-accelerated ones.)
975
976  macro(add_bittest PROG NAME ARGS OUTFILE INFILE MD5SUM)
977    add_test(${PROG}-${libtype}-${NAME}
978      ${PROG}${suffix} ${ARGS} -outfile ${OUTFILE} ${INFILE})
979    add_test(${PROG}-${libtype}-${NAME}-cmp
980      ${MD5CMP} ${MD5SUM} ${OUTFILE})
981    set_tests_properties(${PROG}-${libtype}-${NAME}-cmp PROPERTIES
982      DEPENDS ${PROG}-${libtype}-${NAME})
983    if(${ARGC} GREATER 6)
984      set(DEPENDS ${ARGN})
985      set_tests_properties(${PROG}-${libtype}-${NAME} PROPERTIES
986        DEPENDS ${DEPENDS})
987    endif()
988  endmacro()
989
990  # CC: null  SAMP: fullsize  FDCT: islow  ENT: huff
991  add_bittest(cjpeg rgb-islow "-rgb;-dct;int;-icc;${TESTIMAGES}/test1.icc"
992    testout_rgb_islow.jpg ${TESTIMAGES}/testorig.ppm
993    ${MD5_JPEG_RGB_ISLOW})
994
995  # CC: null  SAMP: fullsize  IDCT: islow  ENT: huff
996  add_bittest(djpeg rgb-islow "-dct;int;-ppm;-icc;testout_rgb_islow.icc"
997    testout_rgb_islow.ppm testout_rgb_islow.jpg
998    ${MD5_PPM_RGB_ISLOW} cjpeg-${libtype}-rgb-islow)
999
1000  add_test(djpeg-${libtype}-rgb-islow-icc-cmp
1001    ${MD5CMP} b06a39d730129122e85c1363ed1bbc9e testout_rgb_islow.icc)
1002  set_tests_properties(djpeg-${libtype}-rgb-islow-icc-cmp PROPERTIES
1003    DEPENDS djpeg-${libtype}-rgb-islow)
1004
1005  add_bittest(jpegtran icc "-copy;all;-icc;${TESTIMAGES}/test2.icc"
1006    testout_rgb_islow2.jpg testout_rgb_islow.jpg ${MD5_JPEG_RGB_ISLOW2})
1007
1008  if(NOT WITH_12BIT)
1009    # CC: RGB->RGB565  SAMP: fullsize  IDCT: islow  ENT: huff
1010    add_bittest(djpeg rgb-islow-565 "-dct;int;-rgb565;-dither;none;-bmp"
1011      testout_rgb_islow_565.bmp testout_rgb_islow.jpg
1012      ${MD5_BMP_RGB_ISLOW_565} cjpeg-${libtype}-rgb-islow)
1013
1014    # CC: RGB->RGB565 (dithered)  SAMP: fullsize  IDCT: islow  ENT: huff
1015    add_bittest(djpeg rgb-islow-565D "-dct;int;-rgb565;-bmp"
1016      testout_rgb_islow_565D.bmp testout_rgb_islow.jpg
1017      ${MD5_BMP_RGB_ISLOW_565D} cjpeg-${libtype}-rgb-islow)
1018  endif()
1019
1020  # CC: RGB->YCC  SAMP: fullsize/h2v1  FDCT: ifast  ENT: 2-pass huff
1021  add_bittest(cjpeg 422-ifast-opt "-sample;2x1;-dct;fast;-opt"
1022    testout_422_ifast_opt.jpg ${TESTIMAGES}/testorig.ppm
1023    ${MD5_JPEG_422_IFAST_OPT})
1024
1025  # CC: YCC->RGB  SAMP: fullsize/h2v1 fancy  IDCT: ifast  ENT: huff
1026  add_bittest(djpeg 422-ifast "-dct;fast"
1027    testout_422_ifast.ppm testout_422_ifast_opt.jpg
1028    ${MD5_PPM_422_IFAST} cjpeg-${libtype}-422-ifast-opt)
1029
1030  # CC: YCC->RGB  SAMP: h2v1 merged  IDCT: ifast  ENT: huff
1031  add_bittest(djpeg 422m-ifast "-dct;fast;-nosmooth"
1032    testout_422m_ifast.ppm testout_422_ifast_opt.jpg
1033    ${MD5_PPM_422M_IFAST} cjpeg-${libtype}-422-ifast-opt)
1034
1035  if(NOT WITH_12BIT)
1036    # CC: YCC->RGB565  SAMP: h2v1 merged  IDCT: ifast  ENT: huff
1037    add_bittest(djpeg 422m-ifast-565
1038      "-dct;int;-nosmooth;-rgb565;-dither;none;-bmp"
1039      testout_422m_ifast_565.bmp testout_422_ifast_opt.jpg
1040      ${MD5_BMP_422M_IFAST_565} cjpeg-${libtype}-422-ifast-opt)
1041
1042    # CC: YCC->RGB565 (dithered)  SAMP: h2v1 merged  IDCT: ifast  ENT: huff
1043    add_bittest(djpeg 422m-ifast-565D "-dct;int;-nosmooth;-rgb565;-bmp"
1044      testout_422m_ifast_565D.bmp testout_422_ifast_opt.jpg
1045      ${MD5_BMP_422M_IFAST_565D} cjpeg-${libtype}-422-ifast-opt)
1046  endif()
1047
1048  # CC: RGB->YCC  SAMP: fullsize/h2v2  FDCT: ifast  ENT: prog huff
1049  add_bittest(cjpeg 420-q100-ifast-prog
1050    "-sample;2x2;-quality;100;-dct;fast;-prog"
1051    testout_420_q100_ifast_prog.jpg ${TESTIMAGES}/testorig.ppm
1052    ${MD5_JPEG_420_IFAST_Q100_PROG})
1053
1054  # CC: YCC->RGB  SAMP: fullsize/h2v2 fancy  IDCT: ifast  ENT: prog huff
1055  add_bittest(djpeg 420-q100-ifast-prog "-dct;fast"
1056    testout_420_q100_ifast.ppm testout_420_q100_ifast_prog.jpg
1057    ${MD5_PPM_420_Q100_IFAST} cjpeg-${libtype}-420-q100-ifast-prog)
1058
1059  # CC: YCC->RGB  SAMP: h2v2 merged  IDCT: ifast  ENT: prog huff
1060  add_bittest(djpeg 420m-q100-ifast-prog "-dct;fast;-nosmooth"
1061    testout_420m_q100_ifast.ppm testout_420_q100_ifast_prog.jpg
1062    ${MD5_PPM_420M_Q100_IFAST} cjpeg-${libtype}-420-q100-ifast-prog)
1063
1064  # CC: RGB->Gray  SAMP: fullsize  FDCT: islow  ENT: huff
1065  add_bittest(cjpeg gray-islow "-gray;-dct;int"
1066    testout_gray_islow.jpg ${TESTIMAGES}/testorig.ppm
1067    ${MD5_JPEG_GRAY_ISLOW})
1068
1069  # CC: Gray->Gray  SAMP: fullsize  IDCT: islow  ENT: huff
1070  add_bittest(djpeg gray-islow "-dct;int"
1071    testout_gray_islow.ppm testout_gray_islow.jpg
1072    ${MD5_PPM_GRAY_ISLOW} cjpeg-${libtype}-gray-islow)
1073
1074  # CC: Gray->RGB  SAMP: fullsize  IDCT: islow  ENT: huff
1075  add_bittest(djpeg gray-islow-rgb "-dct;int;-rgb"
1076    testout_gray_islow_rgb.ppm testout_gray_islow.jpg
1077    ${MD5_PPM_GRAY_ISLOW_RGB} cjpeg-${libtype}-gray-islow)
1078
1079  if(NOT WITH_12BIT)
1080    # CC: Gray->RGB565  SAMP: fullsize  IDCT: islow  ENT: huff
1081    add_bittest(djpeg gray-islow-565 "-dct;int;-rgb565;-dither;none;-bmp"
1082      testout_gray_islow_565.bmp testout_gray_islow.jpg
1083      ${MD5_BMP_GRAY_ISLOW_565} cjpeg-${libtype}-gray-islow)
1084
1085    # CC: Gray->RGB565 (dithered)  SAMP: fullsize  IDCT: islow  ENT: huff
1086    add_bittest(djpeg gray-islow-565D "-dct;int;-rgb565;-bmp"
1087      testout_gray_islow_565D.bmp testout_gray_islow.jpg
1088      ${MD5_BMP_GRAY_ISLOW_565D} cjpeg-${libtype}-gray-islow)
1089  endif()
1090
1091  # CC: RGB->YCC  SAMP: fullsize smooth/h2v2 smooth  FDCT: islow
1092  # ENT: 2-pass huff
1093  add_bittest(cjpeg 420s-ifast-opt "-sample;2x2;-smooth;1;-dct;int;-opt"
1094    testout_420s_ifast_opt.jpg ${TESTIMAGES}/testorig.ppm
1095    ${MD5_JPEG_420S_IFAST_OPT})
1096
1097  if(FLOATTEST)
1098    # CC: RGB->YCC  SAMP: fullsize/int  FDCT: float  ENT: prog huff
1099    add_bittest(cjpeg 3x2-float-prog "-sample;3x2;-dct;float;-prog"
1100      testout_3x2_float_prog.jpg ${TESTIMAGES}/testorig.ppm
1101      ${MD5_JPEG_3x2_FLOAT_PROG_${FLOATTEST_UC}})
1102
1103    # CC: YCC->RGB  SAMP: fullsize/int  IDCT: float  ENT: prog huff
1104    add_bittest(djpeg 3x2-float-prog "-dct;float"
1105      testout_3x2_float.ppm testout_3x2_float_prog.jpg
1106      ${MD5_PPM_3x2_FLOAT_${FLOATTEST_UC}} cjpeg-${libtype}-3x2-float-prog)
1107  endif()
1108
1109    # CC: RGB->YCC  SAMP: fullsize/int  FDCT: ifast  ENT: prog huff
1110  add_bittest(cjpeg 3x2-ifast-prog "-sample;3x2;-dct;fast;-prog"
1111    testout_3x2_ifast_prog.jpg ${TESTIMAGES}/testorig.ppm
1112    ${MD5_JPEG_3x2_IFAST_PROG})
1113
1114  # CC: YCC->RGB  SAMP: fullsize/int  IDCT: ifast  ENT: prog huff
1115  add_bittest(djpeg 3x2-ifast-prog "-dct;fast"
1116    testout_3x2_ifast.ppm testout_3x2_ifast_prog.jpg
1117    ${MD5_PPM_3x2_IFAST} cjpeg-${libtype}-3x2-ifast-prog)
1118
1119  if(WITH_ARITH_ENC)
1120    # CC: YCC->RGB  SAMP: fullsize/h2v2  FDCT: islow  ENT: arith
1121    add_bittest(cjpeg 420-islow-ari "-dct;int;-arithmetic"
1122      testout_420_islow_ari.jpg ${TESTIMAGES}/testorig.ppm
1123      ${MD5_JPEG_420_ISLOW_ARI})
1124
1125    add_bittest(jpegtran 420-islow-ari "-arithmetic"
1126      testout_420_islow_ari2.jpg ${TESTIMAGES}/testimgint.jpg
1127      ${MD5_JPEG_420_ISLOW_ARI})
1128
1129    # CC: YCC->RGB  SAMP: fullsize  FDCT: islow  ENT: prog arith
1130    add_bittest(cjpeg 444-islow-progari
1131      "-sample;1x1;-dct;int;-prog;-arithmetic"
1132      testout_444_islow_progari.jpg ${TESTIMAGES}/testorig.ppm
1133      ${MD5_JPEG_444_ISLOW_PROGARI})
1134  endif()
1135
1136  if(WITH_ARITH_DEC)
1137    # CC: RGB->YCC  SAMP: h2v2 merged  IDCT: ifast  ENT: arith
1138    add_bittest(djpeg 420m-ifast-ari "-fast;-ppm"
1139      testout_420m_ifast_ari.ppm ${TESTIMAGES}/testimgari.jpg
1140      ${MD5_PPM_420M_IFAST_ARI})
1141
1142    add_bittest(jpegtran 420-islow ""
1143      testout_420_islow.jpg ${TESTIMAGES}/testimgari.jpg
1144      ${MD5_JPEG_420_ISLOW})
1145  endif()
1146
1147  # 2/1--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 16x16 islow  ENT: huff
1148  # 15/8--  CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 15x15 islow  ENT: huff
1149  # 13/8--  CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 13x13 islow  ENT: huff
1150  # 11/8--  CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 11x11 islow  ENT: huff
1151  # 9/8--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 9x9 islow  ENT: huff
1152  # 7/8--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 7x7 islow/14x14 islow
1153  #         ENT: huff
1154  # 3/4--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 6x6 islow/12x12 islow
1155  #         ENT: huff
1156  # 5/8--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 5x5 islow/10x10 islow
1157  #         ENT: huff
1158  # 1/2--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 4x4 islow/8x8 islow
1159  #         ENT: huff
1160  # 3/8--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 3x3 islow/6x6 islow
1161  #         ENT: huff
1162  # 1/4--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 2x2 islow/4x4 islow
1163  #         ENT: huff
1164  # 1/8--   CC: YCC->RGB  SAMP: h2v2 merged  IDCT: 1x1 islow/2x2 islow
1165  #         ENT: huff
1166  foreach(scale 2_1 15_8 13_8 11_8 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8)
1167    string(REGEX REPLACE "_" "/" scalearg ${scale})
1168    add_bittest(djpeg 420m-islow-${scale}
1169      "-dct;int;-scale;${scalearg};-nosmooth;-ppm"
1170      testout_420m_islow_${scale}.ppm ${TESTIMAGES}/${TESTORIG}
1171      ${MD5_PPM_420M_ISLOW_${scale}})
1172  endforeach()
1173
1174  if(NOT WITH_12BIT)
1175    # CC: YCC->RGB (dithered)  SAMP: h2v2 fancy  IDCT: islow  ENT: huff
1176    add_bittest(djpeg 420-islow-256 "-dct;int;-colors;256;-bmp"
1177      testout_420_islow_256.bmp ${TESTIMAGES}/${TESTORIG}
1178      ${MD5_BMP_420_ISLOW_256})
1179
1180    # CC: YCC->RGB565  SAMP: h2v2 fancy  IDCT: islow  ENT: huff
1181    add_bittest(djpeg 420-islow-565 "-dct;int;-rgb565;-dither;none;-bmp"
1182      testout_420_islow_565.bmp ${TESTIMAGES}/${TESTORIG}
1183      ${MD5_BMP_420_ISLOW_565})
1184
1185    # CC: YCC->RGB565 (dithered)  SAMP: h2v2 fancy  IDCT: islow  ENT: huff
1186    add_bittest(djpeg 420-islow-565D "-dct;int;-rgb565;-bmp"
1187      testout_420_islow_565D.bmp ${TESTIMAGES}/${TESTORIG}
1188      ${MD5_BMP_420_ISLOW_565D})
1189
1190    # CC: YCC->RGB565  SAMP: h2v2 merged  IDCT: islow  ENT: huff
1191    add_bittest(djpeg 420m-islow-565
1192      "-dct;int;-nosmooth;-rgb565;-dither;none;-bmp"
1193      testout_420m_islow_565.bmp ${TESTIMAGES}/${TESTORIG}
1194      ${MD5_BMP_420M_ISLOW_565})
1195
1196    # CC: YCC->RGB565 (dithered)  SAMP: h2v2 merged  IDCT: islow  ENT: huff
1197    add_bittest(djpeg 420m-islow-565D "-dct;int;-nosmooth;-rgb565;-bmp"
1198      testout_420m_islow_565D.bmp ${TESTIMAGES}/${TESTORIG}
1199      ${MD5_BMP_420M_ISLOW_565D})
1200  endif()
1201
1202  # Partial decode tests.  These tests are designed to cover all of the
1203  # possible code paths in jpeg_skip_scanlines().
1204
1205  # Context rows: Yes  Intra-iMCU row: Yes  iMCU row prefetch: No   ENT: huff
1206  add_bittest(djpeg 420-islow-skip15_31 "-dct;int;-skip;15,31;-ppm"
1207    testout_420_islow_skip15,31.ppm ${TESTIMAGES}/${TESTORIG}
1208    ${MD5_PPM_420_ISLOW_SKIP15_31})
1209
1210  # Context rows: Yes  Intra-iMCU row: No   iMCU row prefetch: Yes  ENT: arith
1211  if(WITH_ARITH_DEC)
1212    add_bittest(djpeg 420-islow-ari-skip16_139 "-dct;int;-skip;16,139;-ppm"
1213      testout_420_islow_ari_skip16,139.ppm ${TESTIMAGES}/testimgari.jpg
1214      ${MD5_PPM_420_ISLOW_ARI_SKIP16_139})
1215  endif()
1216
1217  # Context rows: Yes  Intra-iMCU row: No   iMCU row prefetch: No   ENT: prog huff
1218  add_test(cjpeg-${libtype}-420-islow-prog
1219    cjpeg${suffix} -dct int -prog
1220      -outfile testout_420_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
1221  add_bittest(djpeg 420-islow-prog-crop62x62_71_71
1222    "-dct;int;-crop;62x62+71+71;-ppm"
1223    testout_420_islow_prog_crop62x62,71,71.ppm testout_420_islow_prog.jpg
1224    ${MD5_PPM_420_ISLOW_PROG_CROP62x62_71_71} cjpeg-${libtype}-420-islow-prog)
1225
1226  # Context rows: Yes  Intra-iMCU row: No   iMCU row prefetch: No   ENT: arith
1227  if(WITH_ARITH_DEC)
1228    add_bittest(djpeg 420-islow-ari-crop53x53_4_4
1229      "-dct;int;-crop;53x53+4+4;-ppm"
1230      testout_420_islow_ari_crop53x53,4,4.ppm ${TESTIMAGES}/testimgari.jpg
1231      ${MD5_PPM_420_ISLOW_ARI_CROP53x53_4_4})
1232  endif()
1233
1234  # Context rows: No   Intra-iMCU row: Yes  ENT: huff
1235  add_test(cjpeg-${libtype}-444-islow
1236    cjpeg${suffix} -dct int -sample 1x1
1237      -outfile testout_444_islow.jpg ${TESTIMAGES}/testorig.ppm)
1238  add_bittest(djpeg 444-islow-skip1_6 "-dct;int;-skip;1,6;-ppm"
1239    testout_444_islow_skip1,6.ppm testout_444_islow.jpg
1240    ${MD5_PPM_444_ISLOW_SKIP1_6} cjpeg-${libtype}-444-islow)
1241
1242  # Context rows: No   Intra-iMCU row: No   ENT: prog huff
1243  add_test(cjpeg-${libtype}-444-islow-prog
1244    cjpeg${suffix} -dct int -prog -sample 1x1
1245      -outfile testout_444_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
1246  add_bittest(djpeg 444-islow-prog-crop98x98_13_13
1247    "-dct;int;-crop;98x98+13+13;-ppm"
1248    testout_444_islow_prog_crop98x98,13,13.ppm testout_444_islow_prog.jpg
1249    ${MD5_PPM_444_ISLOW_PROG_CROP98x98_13_13} cjpeg-${libtype}-444-islow-prog)
1250
1251  # Context rows: No   Intra-iMCU row: No   ENT: arith
1252  if(WITH_ARITH_ENC)
1253    add_test(cjpeg-${libtype}-444-islow-ari
1254      cjpeg${suffix} -dct int -arithmetic -sample 1x1
1255        -outfile testout_444_islow_ari.jpg ${TESTIMAGES}/testorig.ppm)
1256    if(WITH_ARITH_DEC)
1257      add_bittest(djpeg 444-islow-ari-crop37x37_0_0
1258        "-dct;int;-crop;37x37+0+0;-ppm"
1259        testout_444_islow_ari_crop37x37,0,0.ppm testout_444_islow_ari.jpg
1260        ${MD5_PPM_444_ISLOW_ARI_CROP37x37_0_0} cjpeg-${libtype}-444-islow-ari)
1261    endif()
1262  endif()
1263
1264  add_bittest(jpegtran crop "-crop;120x90+20+50;-transpose;-perfect"
1265    testout_crop.jpg ${TESTIMAGES}/${TESTORIG}
1266    ${MD5_JPEG_CROP})
1267
1268endforeach()
1269
1270add_custom_target(testclean COMMAND ${CMAKE_COMMAND} -P
1271  ${CMAKE_CURRENT_SOURCE_DIR}/cmakescripts/testclean.cmake)
1272
1273if(WITH_TURBOJPEG)
1274  configure_file(tjbenchtest.in tjbenchtest @ONLY)
1275  configure_file(tjexampletest.in tjexampletest @ONLY)
1276  if(WIN32)
1277    set(BASH bash)
1278  endif()
1279  if(WITH_JAVA)
1280    configure_file(tjbenchtest.java.in tjbenchtest.java @ONLY)
1281    configure_file(tjexampletest.java.in tjexampletest.java @ONLY)
1282    add_custom_target(tjtest
1283      COMMAND echo tjbenchtest
1284      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest
1285      COMMAND echo tjbenchtest -alloc
1286      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -alloc
1287      COMMAND echo tjbenchtest -yuv
1288      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -yuv
1289      COMMAND echo tjbenchtest -yuv -alloc
1290      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -yuv -alloc
1291      COMMAND echo tjbenchtest -progressive
1292      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -progressive
1293      COMMAND echo tjexampletest
1294      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjexampletest
1295      COMMAND echo tjbenchtest.java
1296      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest.java
1297      COMMAND echo tjbenchtest.java -yuv
1298      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest.java -yuv
1299      COMMAND echo tjbenchtest.java -progressive
1300      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest.java -progressive
1301      COMMAND echo tjexampletest.java
1302      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjexampletest.java
1303      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest
1304        ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest.java
1305        ${CMAKE_CURRENT_BINARY_DIR}/tjexampletest)
1306  else()
1307    add_custom_target(tjtest
1308      COMMAND echo tjbenchtest
1309      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest
1310      COMMAND echo tjbenchtest -alloc
1311      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -alloc
1312      COMMAND echo tjbenchtest -yuv
1313      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -yuv
1314      COMMAND echo tjbenchtest -yuv -alloc
1315      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest -yuv -alloc
1316      COMMAND echo tjexampletest
1317      COMMAND ${BASH} ${CMAKE_CURRENT_BINARY_DIR}/tjexampletest
1318      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tjbenchtest)
1319  endif()
1320endif()
1321
1322
1323###############################################################################
1324# INSTALLATION
1325###############################################################################
1326
1327set(EXE ${CMAKE_EXECUTABLE_SUFFIX})
1328
1329if(WITH_TURBOJPEG)
1330  if(ENABLE_SHARED)
1331    install(TARGETS turbojpeg tjbench
1332      ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1333      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1334      RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1335    if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
1336      CMAKE_C_LINKER_SUPPORTS_PDB)
1337      install(FILES "$<TARGET_PDB_FILE:turbojpeg>"
1338        DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
1339    endif()
1340  endif()
1341  if(ENABLE_STATIC)
1342    install(TARGETS turbojpeg-static ARCHIVE
1343      DESTINATION ${CMAKE_INSTALL_LIBDIR})
1344    if(NOT ENABLE_SHARED)
1345      if(MSVC_IDE)
1346        set(DIR "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}")
1347      else()
1348        set(DIR ${CMAKE_CURRENT_BINARY_DIR})
1349      endif()
1350      install(PROGRAMS ${DIR}/tjbench-static${EXE}
1351        DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME tjbench${EXE})
1352    endif()
1353  endif()
1354  install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/turbojpeg.h
1355    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1356endif()
1357
1358if(ENABLE_STATIC)
1359  install(TARGETS jpeg-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1360  if(NOT ENABLE_SHARED)
1361    if(MSVC_IDE)
1362      set(DIR "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}")
1363    else()
1364      set(DIR ${CMAKE_CURRENT_BINARY_DIR})
1365    endif()
1366    install(PROGRAMS ${DIR}/cjpeg-static${EXE}
1367      DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME cjpeg${EXE})
1368    install(PROGRAMS ${DIR}/djpeg-static${EXE}
1369      DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME djpeg${EXE})
1370    install(PROGRAMS ${DIR}/jpegtran-static${EXE}
1371      DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME jpegtran${EXE})
1372  endif()
1373endif()
1374
1375install(TARGETS rdjpgcom wrjpgcom RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1376
1377install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.ijg
1378  ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/example.txt
1379  ${CMAKE_CURRENT_SOURCE_DIR}/tjexample.c
1380  ${CMAKE_CURRENT_SOURCE_DIR}/libjpeg.txt
1381  ${CMAKE_CURRENT_SOURCE_DIR}/structure.txt
1382  ${CMAKE_CURRENT_SOURCE_DIR}/usage.txt ${CMAKE_CURRENT_SOURCE_DIR}/wizard.txt
1383  ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
1384if(WITH_JAVA)
1385  install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/java/TJExample.java
1386    DESTINATION ${CMAKE_INSTALL_DOCDIR})
1387endif()
1388
1389if(UNIX OR MINGW)
1390  install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cjpeg.1
1391    ${CMAKE_CURRENT_SOURCE_DIR}/djpeg.1 ${CMAKE_CURRENT_SOURCE_DIR}/jpegtran.1
1392    ${CMAKE_CURRENT_SOURCE_DIR}/rdjpgcom.1
1393    ${CMAKE_CURRENT_SOURCE_DIR}/wrjpgcom.1
1394    DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
1395endif()
1396install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libjpeg.pc
1397  ${CMAKE_CURRENT_BINARY_DIR}/pkgscripts/libturbojpeg.pc
1398  DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
1399
1400install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jconfig.h
1401  ${CMAKE_CURRENT_SOURCE_DIR}/jerror.h ${CMAKE_CURRENT_SOURCE_DIR}/jmorecfg.h
1402  ${CMAKE_CURRENT_SOURCE_DIR}/jpeglib.h
1403  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1404
1405include(cmakescripts/BuildPackages.cmake)
1406
1407configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmakescripts/cmake_uninstall.cmake.in"
1408  "cmake_uninstall.cmake" IMMEDIATE @ONLY)
1409
1410add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)
1411