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