]> granicus.if.org Git - libjpeg-turbo/commitdiff
First pass at a CMake build system
authorDRC <dcommander@users.sourceforge.net>
Fri, 15 Oct 2010 03:43:24 +0000 (03:43 +0000)
committerDRC <dcommander@users.sourceforge.net>
Fri, 15 Oct 2010 03:43:24 +0000 (03:43 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@257 632fc199-4ca6-4c93-a231-07263d6284db

CMakeLists.txt [new file with mode: 0644]
cmakescripts/getdate.bat [new file with mode: 0644]
sharedlib/CMakeLists.txt [new file with mode: 0755]
simd/CMakeLists.txt [new file with mode: 0755]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9d0c059
--- /dev/null
@@ -0,0 +1,231 @@
+#
+# Setup
+#
+
+cmake_minimum_required(VERSION 2.6)
+
+project(libjpeg-turbo)
+set(VERSION 1.0.80)
+
+if(UNIX OR MINGW OR CYGWIN)
+  execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
+  string(REGEX REPLACE "\n" "" BUILD ${BUILD})
+elseif(WIN32)
+  execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
+    OUTPUT_VARIABLE BUILD)
+  string(REGEX REPLACE "\n" "" BUILD ${BUILD})
+else()
+  message(FATAL_ERROR "date not implemented")
+endif()
+
+if(NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE Release)
+endif()
+
+message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
+
+# This only works if building from the command line.  There is currently no way
+# to set a variable's value based on the build type when using the MSVC IDE.
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(BUILD "${BUILD}d")
+endif()
+
+if(NOT DEFINED WITH_SIMD)
+  set(WITH_SIMD 1)
+endif()
+
+set(JPEG_LIB_VERSION 62)
+set(DLL_VERSION ${JPEG_LIB_VERSION})
+if(WITH_JPEG8)
+  set(JPEG_LIB_VERSION 80)
+  set(DLL_VERSION 8)
+  message(STATUS "Emulating libjpeg v8b API/ABI")
+elseif(WITH_JPEG7)
+  set(JPEG_LIB_VERSION 70)
+  set(DLL_VERSION 7)
+  message(STATUS "Emulating libjpeg v7 API/ABI")
+endif(WITH_JPEG8)
+
+if(MSVC)
+  # Use the static C library for all build types
+  foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+    CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+    CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+    CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+    if(${var} MATCHES "/MD")
+      string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
+    endif()
+  endforeach()
+
+  add_definitions(-W3 -wd4996)
+endif()
+
+# Detect whether compiler is 64-bit
+if(MSVC AND CMAKE_CL_64)
+  set(SIMD_X86_64 1)
+  set(64BIT 1)
+elseif(CMAKE_SIZEOF_VOID_P MATCHES 8)
+  set(SIMD_X86_64 1)
+  set(64BIT 1)
+endif()
+
+if(64BIT)
+  message(STATUS "64-bit build")
+else()
+  message(STATUS "32-bit build")
+endif()
+
+configure_file(win/jconfig.h.in jconfig.h)
+configure_file(win/config.h.in config.h)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
+
+
+#
+# Targets
+#
+
+set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
+  jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c
+  jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c
+  jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c
+  jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c
+  jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c
+  jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
+
+if(WITH_SIMD)
+  add_definitions(-DWITH_SIMD)
+  add_subdirectory(simd)
+  if(SIMD_X86_64)
+    set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_x86_64.c)
+  else()
+    set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_i386.c)
+  endif()
+  # This tells CMake that the "source" files haven't been generated yet
+  set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
+else()
+  set(JPEG_SOURCES ${JPEG_SOURCES} jsimd_none.c)
+endif()
+
+add_subdirectory(sharedlib)
+
+add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS})
+add_dependencies(jpeg-static simd)
+if(NOT MSVC)
+  set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
+endif()
+if(WITH_SIMD)
+  add_dependencies(jpeg-static simd)
+endif()
+
+add_library(turbojpeg SHARED turbojpegl.c)
+set_target_properties(turbojpeg PROPERTIES DEFINE_SYMBOL DLLDEFINE)
+target_link_libraries(turbojpeg jpeg-static)
+set_target_properties(turbojpeg PROPERTIES LINK_INTERFACE_LIBRARIES "")
+
+add_library(turbojpeg-static STATIC ${JPEG_SOURCES} ${SIMD_OBJS}
+  turbojpegl.c)
+add_dependencies(turbojpeg-static simd)
+if(NOT MSVC)
+  set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
+endif()
+if(WITH_SIMD)
+  add_dependencies(turbojpeg-static simd)
+endif()
+
+add_executable(jpegut jpegut.c)
+target_link_libraries(jpegut turbojpeg)
+
+add_executable(jpegut-static jpegut.c)
+target_link_libraries(jpegut-static turbojpeg-static)
+
+add_executable(jpgtest jpgtest.cxx bmp.c)
+target_link_libraries(jpgtest turbojpeg)
+
+add_executable(jpgtest-static jpgtest.cxx bmp.c)
+target_link_libraries(jpgtest-static turbojpeg-static)
+
+add_executable(cjpeg-static cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c
+  rdtarga.c)
+set_property(TARGET cjpeg-static PROPERTY COMPILE_FLAGS
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
+target_link_libraries(cjpeg-static jpeg-static)
+
+add_executable(djpeg-static djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c wrgif.c
+  wrppm.c wrtarga.c)
+set_property(TARGET djpeg-static PROPERTY COMPILE_FLAGS
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
+target_link_libraries(djpeg-static jpeg-static)
+
+add_executable(jpegtran-static jpegtran.c cdjpeg.c rdswitch.c transupp.c)
+target_link_libraries(jpegtran-static jpeg-static)
+
+add_executable(rdjpgcom rdjpgcom.c)
+
+add_executable(wrjpgcom rdjpgcom.c)
+
+
+#
+# Tests
+#
+
+enable_testing()
+add_test(jpegut jpegut)
+add_test(cjpeg-int sharedlib/cjpeg -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
+add_test(cjpeg-fast sharedlib/cjpeg -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
+add_test(cjpeg-float sharedlib/cjpeg -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+if(WITH_SIMD)
+add_test(cjpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
+else()
+add_test(cjpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
+endif()
+add_test(djpeg-int sharedlib/djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
+add_test(djpeg-fast sharedlib/djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
+add_test(djpeg-float sharedlib/djpeg -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+if(WITH_SIMD)
+add_test(djpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
+else()
+add_test(djpeg-float-cmp cmp ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
+endif()
+add_test(djpeg-256 sharedlib/djpeg -dct int -bmp -colors 256 -outfile testout.bmp  ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-256-cmp cmp ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
+add_test(cjpeg-prog sharedlib/cjpeg -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
+add_test(jpegtran-prog sharedlib/jpegtran -outfile testoutt.jpg testoutp.jpg)
+add_test(jpegtran-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
+add_test(jpegtran-crop sharedlib/jpegtran -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(jpegtran-crop-cmp cmp ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)
+
+add_test(jpegut-static jpegut-static)
+add_test(cjpeg-static-int cjpeg-static -dct int -outfile testoutint.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-static-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
+add_test(cjpeg-static-fast cjpeg-static -dct fast -opt -outfile testoutfst.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-static-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
+add_test(cjpeg-static-float cjpeg-static -dct float -outfile testoutflt.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+if(WITH_SIMD)
+add_test(cjpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
+else()
+add_test(cjpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
+endif()
+add_test(djpeg-static-int djpeg-static -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-static-int-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
+add_test(djpeg-static-fast djpeg-static -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-static-fast-cmp cmp ${CMAKE_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
+add_test(djpeg-static-float djpeg-static -dct float -ppm -outfile testoutflt.ppm ${CMAKE_SOURCE_DIR}/testorig.jpg)
+if(WITH_SIMD)
+add_test(djpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
+else()
+add_test(djpeg-static-float-cmp cmp ${CMAKE_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
+endif()
+add_test(djpeg-static-256 djpeg-static -dct int -bmp -colors 256 -outfile testout.bmp  ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-static-256-cmp cmp ${CMAKE_SOURCE_DIR}/testimg.bmp testout.bmp)
+add_test(cjpeg-static-prog cjpeg-static -dct int -progressive -outfile testoutp.jpg ${CMAKE_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-static-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
+add_test(jpegtran-static-prog jpegtran-static -outfile testoutt.jpg testoutp.jpg)
+add_test(jpegtran-static-prog-cmp cmp ${CMAKE_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
+add_test(jpegtran-static-crop jpegtran-static -crop 120x90+20+50 -transpose -perfect -outfile testoutcrop.jpg ${CMAKE_SOURCE_DIR}/testorig.jpg)
+add_test(jpegtran-static-crop-cmp cmp ${CMAKE_SOURCE_DIR}/testimgcrop.jpg testoutcrop.jpg)
diff --git a/cmakescripts/getdate.bat b/cmakescripts/getdate.bat
new file mode 100644 (file)
index 0000000..b4251bb
--- /dev/null
@@ -0,0 +1,3 @@
+@echo off
+for /f "tokens=1-4 eol=/ DELIMS=/ " %%i in ('date /t') do set BUILD=%%l%%j%%k
+echo %BUILD%
diff --git a/sharedlib/CMakeLists.txt b/sharedlib/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..530842b
--- /dev/null
@@ -0,0 +1,54 @@
+# Anything that must be linked against the shared C library on Windows must\r
+# be built in this subdirectory, because CMake doesn't allow us to override\r
+# the compiler flags for each build type except at directory scope.  Note\r
+# to CMake developers:  Add a COMPILE_FLAGS_<CONFIG> target property, or\r
+# better yet, provide a friendly way of configuring a Windows target to use the\r
+# static C library.\r
+\r
+if(MSVC)\r
+  # Build all configurations against shared C library\r
+  foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE\r
+    CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO\r
+    CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE\r
+    CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)\r
+    if(${var} MATCHES "/MT")\r
+      string(REGEX REPLACE "/MT" "/MD" ${var} "${${var}}")\r
+    endif()\r
+  endforeach()\r
+endif()\r
+\r
+foreach(src ${JPEG_SOURCES})\r
+  set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_SOURCE_DIR}/${src})\r
+endforeach()\r
+\r
+set(JPEG_DEF ../win/jpeg.def)\r
+\r
+if(WITH_SIMD)\r
+  # This tells CMake that the "source" files haven't been generated yet\r
+  set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)\r
+endif()\r
+\r
+add_library(jpeg SHARED ${JPEG_SRCS} ${SIMD_OBJS} ${JPEG_DEF})\r
+if(MSVC)\r
+  set_target_properties(jpeg PROPERTIES SUFFIX ${DLL_VERSION}.dll)\r
+elseif(MINGW)\r
+  set_target_properties(jpeg PROPERTIES SUFFIX -${DLL_VERSION}.dll)\r
+endif(MSVC)\r
+if(WITH_SIMD)\r
+  add_dependencies(jpeg simd)\r
+endif()\r
+\r
+add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdbmp.c ../rdgif.c ../rdppm.c\r
+  ../rdswitch.c ../rdtarga.c)\r
+set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS\r
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")\r
+target_link_libraries(cjpeg jpeg)\r
+\r
+add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c\r
+  ../wrbmp.c ../wrgif.c ../wrppm.c ../wrtarga.c)\r
+set_property(TARGET djpeg PROPERTY COMPILE_FLAGS\r
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")\r
+target_link_libraries(djpeg jpeg)\r
+\r
+add_executable(jpegtran ../jpegtran.c ../cdjpeg.c ../rdswitch.c ../transupp.c)\r
+target_link_libraries(jpegtran jpeg)\r
diff --git a/simd/CMakeLists.txt b/simd/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..5b47d8f
--- /dev/null
@@ -0,0 +1,49 @@
+if(SIMD_X86_64)\r
+  set(NAFLAGS -fwin64 -DWIN64 -D__x86_64__ -I${CMAKE_SOURCE_DIR}/win/\r
+    -I${CMAKE_CURRENT_SOURCE_DIR}/)\r
+else()\r
+  set(NAFLAGS -fwin32 -DWIN32 -I${CMAKE_SOURCE_DIR}/win/\r
+    -I${CMAKE_CURRENT_SOURCE_DIR}/)\r
+endif()\r
+\r
+if(MSVC)\r
+  set(NAFLAGS ${NAFLAGS} -DMSVC)\r
+endif()\r
+\r
+# This only works if building from the command line.  There is currently no way\r
+# to set a variable's value based on the build type when using the MSVC IDE.\r
+if(CMAKE_BUILD_TYPE STREQUAL "Debug"\r
+  OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")\r
+  set(NAFLAGS ${NAFLAGS} -g)\r
+endif()\r
+\r
+if(SIMD_X86_64)\r
+  set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcsamss2-64\r
+    jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 jiss2red-64\r
+    jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64)\r
+  message(STATUS "Building x86_64 SIMD extensions")\r
+else()\r
+  set(SIMD_BASENAMES jsimdcpu jccolmmx jdcolmmx jcsammmx jdsammmx jdmermmx\r
+    jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn jf3dnflt\r
+    ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jdcolss2 jcsamss2 jdsamss2\r
+    jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int jiss2fst jcqnts2f\r
+    jiss2flt)\r
+  message(STATUS "Building i386 SIMD extensions")\r
+endif()\r
+\r
+if(MSVC_IDE)\r
+  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/$(OutDir)")\r
+else()\r
+  set(OBJDIR ${CMAKE_CURRENT_BINARY_DIR})\r
+endif()\r
+\r
+foreach(file ${SIMD_BASENAMES})\r
+  set(SIMD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${file}.asm)\r
+  set(SIMD_OBJ ${OBJDIR}/${file}.obj)\r
+  add_custom_command(OUTPUT ${SIMD_OBJ} DEPENDS ${SIMD_SRC} *.inc\r
+    COMMAND nasm ${NAFLAGS} ${SIMD_SRC} -o${SIMD_OBJ})\r
+  set(SIMD_OBJS ${SIMD_OBJS} ${SIMD_OBJ})\r
+endforeach()\r
+\r
+set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE)\r
+add_custom_target(simd DEPENDS ${SIMD_OBJS})\r