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 8set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..) 9set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..) 10set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..) 11 12if(MSVC) 13 # Build all configurations against shared C library 14 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE 15 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) 16 if(${var} MATCHES "/MT") 17 string(REGEX REPLACE "/MT" "/MD" ${var} "${${var}}") 18 endif() 19 endforeach() 20endif() 21 22foreach(src ${JPEG_SOURCES}) 23 set(JPEG_SRCS ${JPEG_SRCS} ../${src}) 24endforeach() 25 26if(WITH_SIMD AND MSVC_IDE) 27 # This tells CMake that the "source" files haven't been generated yet 28 set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1) 29endif() 30 31if(WIN32) 32 if(WITH_MEM_SRCDST) 33 set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}-memsrcdst.def) 34 else() 35 set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}.def) 36 endif() 37endif() 38add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd> 39 ${SIMD_OBJS}) 40 41set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION} 42 VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION}) 43if(APPLE AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET OR 44 CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER 10.4)) 45 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG) 46 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,") 47 endif() 48 set_target_properties(jpeg PROPERTIES MACOSX_RPATH 1) 49endif() 50if(MAPFLAG) 51 set_target_properties(jpeg PROPERTIES 52 LINK_FLAGS "${MAPFLAG}${CMAKE_CURRENT_BINARY_DIR}/../libjpeg.map") 53endif() 54if(MSVC) 55 set_target_properties(jpeg PROPERTIES 56 RUNTIME_OUTPUT_NAME jpeg${SO_MAJOR_VERSION}) 57 # The jsimd_*.c file is built using /MT, so this prevents a linker warning. 58 set_target_properties(jpeg PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCMTD") 59elseif(MINGW) 60 set_target_properties(jpeg PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll) 61endif() 62 63if(WIN32) 64 set(USE_SETMODE "-DUSE_SETMODE") 65endif() 66if(WITH_12BIT) 67 set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}") 68else() 69 set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}") 70 set(CJPEG_BMP_SOURCES ../rdbmp.c ../rdtarga.c) 71 set(DJPEG_BMP_SOURCES ../wrbmp.c ../wrtarga.c) 72endif() 73 74add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c 75 ../rdswitch.c ${CJPEG_BMP_SOURCES}) 76set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS}) 77target_link_libraries(cjpeg jpeg) 78 79add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c 80 ../wrgif.c ../wrppm.c ${DJPEG_BMP_SOURCES}) 81set_property(TARGET djpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS}) 82target_link_libraries(djpeg jpeg) 83 84add_executable(jpegtran ../jpegtran.c ../cdjpeg.c ../rdswitch.c ../transupp.c) 85target_link_libraries(jpegtran jpeg) 86set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "${USE_SETMODE}") 87 88add_executable(jcstest ../jcstest.c) 89target_link_libraries(jcstest jpeg) 90 91install(TARGETS jpeg cjpeg djpeg jpegtran 92 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 93 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 94 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 95if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND 96 CMAKE_C_LINKER_SUPPORTS_PDB) 97 install(FILES "$<TARGET_PDB_FILE:jpeg>" 98 DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL) 99endif() 100