blob: e5b240d0ef603835ead57e724f16cda51714e07c [file] [log] [blame]
DRC84697032010-10-15 03:43:24 +00001#
2# Setup
3#
4
5cmake_minimum_required(VERSION 2.6)
6
7project(libjpeg-turbo)
8set(VERSION 1.0.80)
9
10if(UNIX OR MINGW OR CYGWIN)
11 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
12 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
13elseif(WIN32)
14 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
15 OUTPUT_VARIABLE BUILD)
16 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
17else()
18 message(FATAL_ERROR "date not implemented")
19endif()
20
21if(NOT CMAKE_BUILD_TYPE)
22 set(CMAKE_BUILD_TYPE Release)
23endif()
24
25message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
26
27# This only works if building from the command line. There is currently no way
28# to set a variable's value based on the build type when using the MSVC IDE.
29if(CMAKE_BUILD_TYPE STREQUAL "Debug")
30 set(BUILD "${BUILD}d")
31endif()
32
DRCeb2b9d62010-10-15 04:55:13 +000033message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
34
DRC84697032010-10-15 03:43:24 +000035if(NOT DEFINED WITH_SIMD)
36 set(WITH_SIMD 1)
37endif()
38
39set(JPEG_LIB_VERSION 62)
40set(DLL_VERSION ${JPEG_LIB_VERSION})
41if(WITH_JPEG8)
42 set(JPEG_LIB_VERSION 80)
43 set(DLL_VERSION 8)
44 message(STATUS "Emulating libjpeg v8b API/ABI")
45elseif(WITH_JPEG7)
46 set(JPEG_LIB_VERSION 70)
47 set(DLL_VERSION 7)
48 message(STATUS "Emulating libjpeg v7 API/ABI")
49endif(WITH_JPEG8)
50
51if(MSVC)
52 # Use the static C library for all build types
53 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
54 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
55 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
56 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
57 if(${var} MATCHES "/MD")
58 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
59 endif()
60 endforeach()
61
62 add_definitions(-W3 -wd4996)
63endif()
64
65# Detect whether compiler is 64-bit
66if(MSVC AND CMAKE_CL_64)
67 set(SIMD_X86_64 1)
68 set(64BIT 1)
69elseif(CMAKE_SIZEOF_VOID_P MATCHES 8)
70 set(SIMD_X86_64 1)
71 set(64BIT 1)
72endif()
73
74if(64BIT)
75 message(STATUS "64-bit build")
76else()
77 message(STATUS "32-bit build")
78endif()
79
80configure_file(win/jconfig.h.in jconfig.h)
81configure_file(win/config.h.in config.h)
82
83include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
84
85
86#
87# Targets
88#
89
90set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
91 jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c
92 jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c
93 jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c
94 jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c
95 jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c
96 jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
97
98if(WITH_SIMD)
99 add_definitions(-DWITH_SIMD)
100 add_subdirectory(simd)
101 if(SIMD_X86_64)
102 set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_x86_64.c)
103 else()
104 set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_i386.c)
105 endif()
106 # This tells CMake that the "source" files haven't been generated yet
107 set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
108else()
109 set(JPEG_SOURCES ${JPEG_SOURCES} jsimd_none.c)
110endif()
111
112add_subdirectory(sharedlib)
113
114add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS})
115add_dependencies(jpeg-static simd)
116if(NOT MSVC)
117 set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
118endif()
119if(WITH_SIMD)
120 add_dependencies(jpeg-static simd)
121endif()
122
123add_library(turbojpeg SHARED turbojpegl.c)
124set_target_properties(turbojpeg PROPERTIES DEFINE_SYMBOL DLLDEFINE)
125target_link_libraries(turbojpeg jpeg-static)
126set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "")
127
128add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS}
129 turbojpegl.c)
130add_dependencies(turbojpeg-static simd)
131if(NOT MSVC)
132 set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
133endif()
134if(WITH_SIMD)
135 add_dependencies(turbojpeg-static simd)
136endif()
137
138add_executable(jpegut jpegut.c)
139target_link_libraries(jpegut turbojpeg)
140
141add_executable(jpegut-static jpegut.c)
142target_link_libraries(jpegut-static turbojpeg-static)
143
144add_executable(jpgtest jpgtest.cxx bmp.c)
145target_link_libraries(jpgtest turbojpeg)
146
147add_executable(jpgtest-static jpgtest.cxx bmp.c)
148target_link_libraries(jpgtest-static turbojpeg-static)
149
150add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c
151 rdtarga.c)
152set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS
153 "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
154target_link_libraries(cjpeg-static jpeg-static)
155
156add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c wrgif.c
157 wrppm.c wrtarga.c)
158set_property(TARGET djpeg-static PROPERTY COMPILE_FLAGS
159 "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
160target_link_libraries(djpeg-static jpeg-static)
161
162add_executable(jpegtran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
163target_link_libraries(jpegtran-static jpeg-static)
164
165add_executable(rdjpgcom rdjpgcom.c)
166
167add_executable(wrjpgcom rdjpgcom.c)
168
169
170#
171# Tests
172#
173
174enable_testing()
175add_test(jpegut jpegut)
176add_test(cjpeg-int sharedlib/cjpeg -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
177add_test(cjpeg-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
178add_test(cjpeg-fast sharedlib/cjpeg -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
179add_test(cjpeg-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
180add_test(cjpeg-float sharedlib/cjpeg -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
181if(WITH_SIMD)
182add_test(cjpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
183else()
184add_test(cjpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
185endif()
186add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
187add_test(djpeg-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
188add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
189add_test(djpeg-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
190add_test(djpeg-float sharedlib/djpeg -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
191if(WITH_SIMD)
192add_test(djpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
193else()
194add_test(djpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
195endif()
196add_test(djpeg-256 sharedlib/djpeg -dct int -bmp -colors 256 -outfile testout.bmp ${CMAKE_SOURCE_DIR}/testorig.jpg)
197add_test(djpeg-256-cmp cmp ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
198add_test(cjpeg-prog sharedlib/cjpeg -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
199add_test(cjpeg-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
200add_test(jpegtran-prog sharedlib/jpegtran -outfile testoutt.jpg testoutp.jpg)
201add_test(jpegtran-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
202add_test(jpegtran-crop sharedlib/jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
203add_test(jpegtran-crop-cmp cmp ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)
204
205add_test(jpegut-static jpegut-static)
206add_test(cjpeg-static-int cjpeg-static -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
207add_test(cjpeg-static-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
208add_test(cjpeg-static-fast cjpeg-static -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
209add_test(cjpeg-static-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
210add_test(cjpeg-static-float cjpeg-static -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
211if(WITH_SIMD)
212add_test(cjpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
213else()
214add_test(cjpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
215endif()
216add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
217add_test(djpeg-static-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
218add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
219add_test(djpeg-static-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
220add_test(djpeg-static-float djpeg-static -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
221if(WITH_SIMD)
222add_test(djpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
223else()
224add_test(djpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
225endif()
226add_test(djpeg-static-256 djpeg-static -dct int -bmp -colors 256 -outfile testout.bmp ${CMAKE_SOURCE_DIR}/testorig.jpg)
227add_test(djpeg-static-256-cmp cmp ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
228add_test(cjpeg-static-prog cjpeg-static -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
229add_test(cjpeg-static-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
230add_test(jpegtran-static-prog jpegtran-static -outfile testoutt.jpg testoutp.jpg)
231add_test(jpegtran-static-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
232add_test(jpegtran-static-crop jpegtran-static -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
233add_test(jpegtran-static-crop-cmp cmp ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)