blob: 3a01fde32e516f91f48704620e890c7baac71552 [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
DRC378da4d2010-10-15 19:11:11 +000010if(MINGW OR CYGWIN)
DRC84697032010-10-15 03:43:24 +000011 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()
DRC378da4d2010-10-15 19:11:11 +000018 message(FATAL_ERROR "Platform not supported by this build system. Use autotools instead.")
DRC84697032010-10-15 03:43:24 +000019endif()
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})
DRCa9d5b252010-10-15 06:42:45 +000041set(FULLVERSION ${DLL_VERSION}.0.0)
DRC84697032010-10-15 03:43:24 +000042if(WITH_JPEG8)
43 set(JPEG_LIB_VERSION 80)
44 set(DLL_VERSION 8)
DRCa9d5b252010-10-15 06:42:45 +000045 set(FULLVERSION ${DLL_VERSION}.0.2)
DRC84697032010-10-15 03:43:24 +000046 message(STATUS "Emulating libjpeg v8b API/ABI")
47elseif(WITH_JPEG7)
48 set(JPEG_LIB_VERSION 70)
49 set(DLL_VERSION 7)
DRCa9d5b252010-10-15 06:42:45 +000050 set(FULLVERSION ${DLL_VERSION}.0.0)
DRC84697032010-10-15 03:43:24 +000051 message(STATUS "Emulating libjpeg v7 API/ABI")
52endif(WITH_JPEG8)
53
54if(MSVC)
55 # Use the static C library for all build types
56 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
57 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
58 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
59 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
60 if(${var} MATCHES "/MD")
61 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
62 endif()
63 endforeach()
64
65 add_definitions(-W3 -wd4996)
66endif()
67
68# Detect whether compiler is 64-bit
69if(MSVC AND CMAKE_CL_64)
70 set(SIMD_X86_64 1)
71 set(64BIT 1)
72elseif(CMAKE_SIZEOF_VOID_P MATCHES 8)
73 set(SIMD_X86_64 1)
74 set(64BIT 1)
75endif()
76
77if(64BIT)
78 message(STATUS "64-bit build")
79else()
80 message(STATUS "32-bit build")
81endif()
82
83configure_file(win/jconfig.h.in jconfig.h)
84configure_file(win/config.h.in config.h)
85
86include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
87
88
89#
90# Targets
91#
92
93set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
94 jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c
95 jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c
96 jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c
97 jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c
98 jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c
99 jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
100
101if(WITH_SIMD)
102 add_definitions(-DWITH_SIMD)
103 add_subdirectory(simd)
104 if(SIMD_X86_64)
105 set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_x86_64.c)
106 else()
107 set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_i386.c)
108 endif()
109 # This tells CMake that the "source" files haven't been generated yet
110 set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
111else()
112 set(JPEG_SOURCES ${JPEG_SOURCES} jsimd_none.c)
DRC6f4ba612010-10-16 21:27:38 +0000113 message(STATUS "Not using SIMD acceleration")
DRC84697032010-10-15 03:43:24 +0000114endif()
115
116add_subdirectory(sharedlib)
117
118add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS})
DRC84697032010-10-15 03:43:24 +0000119if(NOT MSVC)
120 set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
121endif()
122if(WITH_SIMD)
123 add_dependencies(jpeg-static simd)
124endif()
125
126add_library(turbojpeg SHARED turbojpegl.c)
127set_target_properties(turbojpeg PROPERTIES DEFINE_SYMBOL DLLDEFINE)
128target_link_libraries(turbojpeg jpeg-static)
129set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "")
130
131add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS}
132 turbojpegl.c)
DRC84697032010-10-15 03:43:24 +0000133if(NOT MSVC)
134 set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
135endif()
136if(WITH_SIMD)
137 add_dependencies(turbojpeg-static simd)
138endif()
139
140add_executable(jpegut jpegut.c)
141target_link_libraries(jpegut turbojpeg)
142
143add_executable(jpegut-static jpegut.c)
144target_link_libraries(jpegut-static turbojpeg-static)
145
146add_executable(jpgtest jpgtest.cxx bmp.c)
147target_link_libraries(jpgtest turbojpeg)
148
149add_executable(jpgtest-static jpgtest.cxx bmp.c)
150target_link_libraries(jpgtest-static turbojpeg-static)
151
152add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c
153 rdtarga.c)
154set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS
155 "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
156target_link_libraries(cjpeg-static jpeg-static)
157
158add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c wrgif.c
159 wrppm.c wrtarga.c)
160set_property(TARGET djpeg-static PROPERTY COMPILE_FLAGS
161 "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
162target_link_libraries(djpeg-static jpeg-static)
163
164add_executable(jpegtran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
165target_link_libraries(jpegtran-static jpeg-static)
166
167add_executable(rdjpgcom rdjpgcom.c)
168
169add_executable(wrjpgcom rdjpgcom.c)
170
171
172#
173# Tests
174#
175
176enable_testing()
177add_test(jpegut jpegut)
178add_test(cjpeg-int sharedlib/cjpeg -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000179add_test(cjpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
DRC84697032010-10-15 03:43:24 +0000180add_test(cjpeg-fast sharedlib/cjpeg -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000181add_test(cjpeg-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
DRC84697032010-10-15 03:43:24 +0000182add_test(cjpeg-float sharedlib/cjpeg -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
183if(WITH_SIMD)
DRCb42a48c2010-10-18 01:06:36 +0000184add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
DRC84697032010-10-15 03:43:24 +0000185else()
DRCb42a48c2010-10-18 01:06:36 +0000186add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
DRC84697032010-10-15 03:43:24 +0000187endif()
188add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000189add_test(djpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
DRC84697032010-10-15 03:43:24 +0000190add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000191add_test(djpeg-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
DRC84697032010-10-15 03:43:24 +0000192add_test(djpeg-float sharedlib/djpeg -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
193if(WITH_SIMD)
DRCb42a48c2010-10-18 01:06:36 +0000194add_test(djpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
DRC84697032010-10-15 03:43:24 +0000195else()
DRCb42a48c2010-10-18 01:06:36 +0000196add_test(djpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
DRC84697032010-10-15 03:43:24 +0000197endif()
198add_test(djpeg-256 sharedlib/djpeg -dct int -bmp -colors 256 -outfile testout.bmp ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000199add_test(djpeg-256-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
DRC84697032010-10-15 03:43:24 +0000200add_test(cjpeg-prog sharedlib/cjpeg -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000201add_test(cjpeg-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
DRC84697032010-10-15 03:43:24 +0000202add_test(jpegtran-prog sharedlib/jpegtran -outfile testoutt.jpg testoutp.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000203add_test(jpegtran-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
DRC84697032010-10-15 03:43:24 +0000204add_test(jpegtran-crop sharedlib/jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000205add_test(jpegtran-crop-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)
DRC84697032010-10-15 03:43:24 +0000206
207add_test(jpegut-static jpegut-static)
208add_test(cjpeg-static-int cjpeg-static -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000209add_test(cjpeg-static-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
DRC84697032010-10-15 03:43:24 +0000210add_test(cjpeg-static-fast cjpeg-static -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000211add_test(cjpeg-static-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
DRC84697032010-10-15 03:43:24 +0000212add_test(cjpeg-static-float cjpeg-static -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
213if(WITH_SIMD)
DRCb42a48c2010-10-18 01:06:36 +0000214add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
DRC84697032010-10-15 03:43:24 +0000215else()
DRCb42a48c2010-10-18 01:06:36 +0000216add_test(cjpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
DRC84697032010-10-15 03:43:24 +0000217endif()
218add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000219add_test(djpeg-static-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
DRC84697032010-10-15 03:43:24 +0000220add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000221add_test(djpeg-static-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
DRC84697032010-10-15 03:43:24 +0000222add_test(djpeg-static-float djpeg-static -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
223if(WITH_SIMD)
DRCb42a48c2010-10-18 01:06:36 +0000224add_test(djpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
DRC84697032010-10-15 03:43:24 +0000225else()
DRCb42a48c2010-10-18 01:06:36 +0000226add_test(djpeg-static-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
DRC84697032010-10-15 03:43:24 +0000227endif()
228add_test(djpeg-static-256 djpeg-static -dct int -bmp -colors 256 -outfile testout.bmp ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000229add_test(djpeg-static-256-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
DRC84697032010-10-15 03:43:24 +0000230add_test(cjpeg-static-prog cjpeg-static -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
DRCb42a48c2010-10-18 01:06:36 +0000231add_test(cjpeg-static-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
DRC84697032010-10-15 03:43:24 +0000232add_test(jpegtran-static-prog jpegtran-static -outfile testoutt.jpg testoutp.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000233add_test(jpegtran-static-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
DRC84697032010-10-15 03:43:24 +0000234add_test(jpegtran-static-crop jpegtran-static -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
DRCb42a48c2010-10-18 01:06:36 +0000235add_test(jpegtran-static-crop-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)
DRC2c0a4e12010-10-16 08:51:43 +0000236
237
238#
239# Installer
240#
241
242set(INST_NAME ${CMAKE_PROJECT_NAME})
243
244if(MSVC)
245 set(INST_PLATFORM "Visual C++")
246elseif(MINGW)
247 set(INST_PLATFORM GCC)
248 set(INST_NAME ${INST_NAME}-gcc)
249 set(INST_DEFS -DGCC)
250endif()
251
252if(64BIT)
253 set(INST_PLATFORM "${INST_PLATFORM} 64-bit")
254 set(INST_NAME ${INST_NAME}64)
255 set(INST_DEFS ${INST_DEFS} -DWIN64)
256endif()
257
258if(MSVC_IDE)
259 set(INST_DEFS ${INST_DEFS} "-DBUILDDIR=$(OutDir)\\")
260else()
261 set(INST_DEFS ${INST_DEFS} "-DBUILDDIR=")
262endif()
263
264configure_file(release/libjpeg-turbo.nsi.in libjpeg-turbo.nsi @ONLY)
265
266add_custom_target(installer
267 makensis -nocd ${INST_DEFS} libjpeg-turbo.nsi
268 DEPENDS jpeg jpeg-static turbojpeg turbojpeg-static
269 SOURCES libjpeg-turbo.nsi)
DRC7284c9a2010-10-16 21:55:14 +0000270
271install(TARGETS jpeg-static turbojpeg turbojpeg-static rdjpgcom wrjpgcom
272 ARCHIVE DESTINATION lib
273 LIBRARY DESTINATION lib
274 RUNTIME DESTINATION bin
275)
276
277install(FILES ${CMAKE_SOURCE_DIR}/LGPL.txt ${CMAKE_SOURCE_DIR}/LICENSE.txt
278 ${CMAKE_SOURCE_DIR}/README ${CMAKE_SOURCE_DIR}/README-turbo.txt
279 ${CMAKE_SOURCE_DIR}/libjpeg.txt ${CMAKE_SOURCE_DIR}/usage.txt
280 DESTINATION doc)
DRCe2befde2010-10-17 07:28:08 +0000281
282install(FILES ${CMAKE_BINARY_DIR}/jconfig.h ${CMAKE_SOURCE_DIR}/jerror.h
283 ${CMAKE_SOURCE_DIR}/jmorecfg.h ${CMAKE_SOURCE_DIR}/jpeglib.h
284 ${CMAKE_SOURCE_DIR}/turbojpeg.h DESTINATION include)