CMakeLists.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Anything that must be linked against the shared C library on Windows must
  2. # be built in this subdirectory, because CMake doesn't allow us to override
  3. # the compiler flags for each build type except at directory scope. Note
  4. # to CMake developers: Add a COMPILE_FLAGS_<CONFIG> target property, or
  5. # better yet, provide a friendly way of configuring a Windows target to use the
  6. # static C library.
  7. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
  8. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
  9. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
  10. if(MSVC)
  11. # Build all configurations against shared C library
  12. foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  13. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
  14. if(${var} MATCHES "/MT")
  15. string(REGEX REPLACE "/MT" "/MD" ${var} "${${var}}")
  16. endif()
  17. endforeach()
  18. endif()
  19. foreach(src ${JPEG_SOURCES})
  20. set(JPEG_SRCS ${JPEG_SRCS} ../${src})
  21. endforeach()
  22. if(WITH_SIMD AND (MSVC_IDE OR XCODE))
  23. # This tells CMake that the "source" files haven't been generated yet
  24. set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
  25. endif()
  26. if(WIN32)
  27. if(WITH_MEM_SRCDST)
  28. set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}-memsrcdst.def)
  29. else()
  30. set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}.def)
  31. endif()
  32. endif()
  33. add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd>
  34. ${SIMD_OBJS})
  35. set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION}
  36. VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION})
  37. if(APPLE AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET OR
  38. CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.4))
  39. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
  40. set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
  41. endif()
  42. set_target_properties(jpeg PROPERTIES MACOSX_RPATH 1)
  43. endif()
  44. if(MAPFLAG)
  45. set_target_properties(jpeg PROPERTIES
  46. LINK_FLAGS "${MAPFLAG}${CMAKE_CURRENT_BINARY_DIR}/../libjpeg.map")
  47. endif()
  48. if(MSVC)
  49. set_target_properties(jpeg PROPERTIES
  50. RUNTIME_OUTPUT_NAME jpeg${SO_MAJOR_VERSION})
  51. # The jsimd_*.c file is built using /MT, so this prevents a linker warning.
  52. set_target_properties(jpeg PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCMTD")
  53. elseif(MINGW)
  54. set_target_properties(jpeg PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll)
  55. endif()
  56. if(WIN32)
  57. set(USE_SETMODE "-DUSE_SETMODE")
  58. endif()
  59. if(WITH_12BIT)
  60. set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
  61. else()
  62. set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
  63. set(CJPEG_BMP_SOURCES ../rdbmp.c ../rdtarga.c)
  64. set(DJPEG_BMP_SOURCES ../wrbmp.c ../wrtarga.c)
  65. endif()
  66. add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c
  67. ../rdswitch.c ${CJPEG_BMP_SOURCES})
  68. set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
  69. target_link_libraries(cjpeg jpeg)
  70. add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c
  71. ../wrgif.c ../wrppm.c ${DJPEG_BMP_SOURCES})
  72. set_property(TARGET djpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
  73. target_link_libraries(djpeg jpeg)
  74. add_executable(jpegtran ../jpegtran.c ../cdjpeg.c ../rdswitch.c ../transupp.c)
  75. target_link_libraries(jpegtran jpeg)
  76. set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "${USE_SETMODE}")
  77. add_executable(jcstest ../jcstest.c)
  78. target_link_libraries(jcstest jpeg)
  79. install(TARGETS jpeg cjpeg djpeg jpegtran
  80. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  81. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  82. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  83. if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
  84. CMAKE_C_LINKER_SUPPORTS_PDB)
  85. install(FILES "$<TARGET_PDB_FILE:jpeg>"
  86. DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
  87. endif()