diff --git a/CMakeLists.txt b/CMakeLists.txt index 889fddf..d6fb88c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,15 +86,21 @@ option(ENABLE_LCMS "Build library with LCMS support option(ENABLE_JASPER "Build library with libjasper support (default=ON)" ON) option(ENABLE_EXAMPLES "Build library with sample command-line programs (default=ON)" ${MASTER_PROJECT}) option(ENABLE_RAWSPEED "Build library with extra RawSpeed codec support (default=OFF)" OFF) +option(ENABLE_DNG_SDK "Build library with extra Adobe DNG SDK support (default=OFF)" OFF) option(ENABLE_DCRAW_DEBUG "Build library with debug message from dcraw (default=OFF)" OFF) option(ENABLE_X3FTOOLS "Build library with Foveon X3F support (default=OFF)" OFF) option(ENABLE_6BY9RPI "Build library with Raspberry Pi RAW support (default=OFF)" OFF) option(LIBRAW_UNINSTALL_TARGET "Add a custom target to ease removal of installed targets" ${MASTER_PROJECT}) option(LIBRAW_INSTALL "Generate the install target." ${MASTER_PROJECT}) +option(DNG_SDK_RPATH "Relative path to extra Adobe DNG SDK (default=dng_sdk)" "dng_sdk") +option(DNG_SDK_PATH "Absolute path to extra Adobe DNG SDK (default=${CMAKE_CURRENT_SOURCE_DIR}/${DNG_SDK_RPATH}" "${CMAKE_CURRENT_SOURCE_DIR}/${DNG_SDK_RPATH}") +option(XMP_SDK_RPATH "Relative path to extra Adobe XMP SDK (default=xmp_toolkit)" "xmp_toolkit") +option(XMP_SDK_PATH "Absolute path to extra Adobe XMP SDK (default=${CMAKE_CURRENT_SOURCE_DIR}/${DNG_SDK_RPATH}" "${CMAKE_CURRENT_SOURCE_DIR}/${DNG_SDK_RPATH}") + + set(RAWSPEED_RPATH "RawSpeed" CACHE STRING "Relative path to extra RawSpeed codec (default=RawSpeed)") - set(RAWSPEED_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${RAWSPEED_RPATH}") # ================================================================================================== @@ -111,6 +117,9 @@ if(MSVC) add_definitions(-D_AFX_SECURE_NO_WARNINGS) endif() +# For variables in $ +include(GNUInstallDirs) + # -- Check dependencies -------------------------------------------------------------------------------- set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} ) @@ -222,6 +231,95 @@ endif() # For registration to libraw_config.h MACRO_BOOL_TO_01(JASPER_SUPPORT_CAN_BE_COMPILED LIBRAW_USE_REDCINECODEC) +# For Adobe DNG SDK Support +set(DNG_SDK_FOUND false) +set(XMP_SDK_FOUND false) +set(DNG_SDK_SUPPORT_CAN_BE_COMPILED false) +set(XMP_CMAKE_PROJECT "${XMP_SDK_PATH}/build") + +if (ENABLE_DNG_SDK) + + if(ZLIB_FOUND) + + if(EXISTS "${DNG_SDK_PATH}/source") + set(DNG_SDK_FOUND true) + else() + message(STATUS "DNG SDK source code not found. Please download source code from Adobe website and set DNG_SDK_PATH") + endif() + + if(EXISTS "${XMP_CMAKE_PROJECT}") + set(XMP_SDK_FOUND true) + else() + message(STATUS "XMP SDK source code not found. Please download source code from https://github.com/adobe/XMP-Toolkit-SDK and set XMP_ROOT") + endif() + + else() + message(STATUS "LibZ dependency not resolved. LibRaw cannot be compiled with DNG SDK") + endif() + + if (DNG_SDK_FOUND AND XMP_SDK_FOUND) + set(DNG_SDK_SUPPORT_CAN_BE_COMPILED on) + endif() +endif() + +# For registration to libraw_config.h +MACRO_BOOL_TO_01(DNG_SDK_SUPPORT_CAN_BE_COMPILED LIBRAW_USE_DNG_SDK) + +# -- Compilation rules for Adobe DNG SDK ------------------------------------------------------------- + +if (DNG_SDK_SUPPORT_CAN_BE_COMPILED) + + include_directories(${DNG_SDK_PATH}/source/) + include_directories(${XMP_SDK_PATH}/public/include/) + + # Enable use of the DNG SDK in libraw + # + add_definitions(-DUSE_DNGSDK) + + # Compile Adobe's libraries with internal symbols enabled which the DNG + # SDK uses. + # + add_definitions(-DAdobePrivate=1) + + # Adobe's SDKs need information about the platform they are being compiled + # for. + # + add_definitions(-DqLinux) + add_definitions(-DUNIX_ENV=1) + + # Disable XMPFiles support in the DNG SDK as we don't need it in order to + # use the DNG SDK with libraw. + # + add_definitions(-DqDNGXMPFiles=0) + + # Disable XMP Document Operation support in the DNG SDK as we don't need it in order to + # use the DNG SDK with libraw. + # + add_definitions(-DqDNGXMPDocOps=0) + + # We need a reference to where the libries are located as the XMP toolkit + # outputs .ar files and we need to link to them when building the DNG SDK + # since cmake defaults to trying to link to the .a files. + # + set(XMP_LIB_DIR ${XMP_SDK_PATH}/public/libraries/i80386linux/release/) + message("XMP_LIB_DIR: ${XMP_LIB_DIR}") + + # We need to build the XMP Toolkit statically as the DNG SDK requires methods + # from the library which are only built for the static version of the library. + # + set(XMP_BUILD_STATIC On) + message("XMP_BUILD_STATIC: ${XMP_BUILD_STATIC}") + + # Note: The XMP bundled with the DNG SDK doesn't compile for Linux due to some missing + # build files - so we build it directly + # + add_subdirectory(${XMP_CMAKE_PROJECT} build/xmp) + + # Grab the DNG SDK headers + file(GLOB dng_LIB_SRCS ${DNG_SDK_PATH}/source/*.cpp) + file(GLOB dng_LIB_HEADERS ${DNG_SDK_PATH}/source/*.h) +endif() + # For RawSpeed Codec Support set(RAWSPEED_FOUND false) @@ -403,6 +501,12 @@ else() message(STATUS " Libraw will be compiled with DNG lossy codec support ......... NO") endif() +if(DNG_SDK_SUPPORT_CAN_BE_COMPILED) + message(STATUS " Libraw will be compiled with DNG SDK support ................ YES") +else() + message(STATUS " Libraw will be compiled with DNG SDK support ................ NO") +endif() + if(RAWSPEED_SUPPORT_CAN_BE_COMPILED) message(STATUS " Libraw will be compiled with RawSpeed support ................ YES") else() @@ -454,6 +558,10 @@ else() list(REMOVE_ITEM libraw_LIB_SRCS ${exclude_libraw_LIB_SRCS}) endif() +if(DNG_SDK_SUPPORT_CAN_BE_COMPILED) + set(libraw_LIB_SRCS ${libraw_LIB_SRCS} ${dng_LIB_SRCS}) +endif() + if(RAWSPEED_SUPPORT_CAN_BE_COMPILED) set(libraw_LIB_SRCS ${libraw_LIB_SRCS} ${librawspeed_LIB_SRCS}) endif() @@ -475,7 +583,7 @@ endif() target_include_directories(raw PUBLIC - $ + $ $) target_link_libraries(raw PUBLIC ${MATH_LIBRARY}) @@ -507,6 +615,25 @@ if(JASPER_SUPPORT_CAN_BE_COMPILED) target_link_libraries(raw PUBLIC ${JASPER_LIBRARIES}) endif() +if (DNG_SDK_SUPPORT_CAN_BE_COMPILED) + target_link_libraries( + raw + PUBLIC + + ${XMP_LIB_DIR}/staticXMPCore.ar + ${XMP_LIB_DIR}/staticXMPFiles.ar + + # If we just try to link the static libraries generated by XMP we get a bunch of + # duplicate symbol errors as for some reason we currently have an issue where some + # of the symbols from the core library end up in the XMPFiles library but we still + # need to import both. So we have to tell the linker we don't care for these particular + # libraries and to just link them anyway. + # + "-Wl,--whole-archive" + "-Wl,--no-whole-archive" + ) +endif() + if(RAWSPEED_SUPPORT_CAN_BE_COMPILED) target_link_libraries(raw PUBLIC ${LIBXML2_LIBRARIES}) endif() @@ -544,7 +671,7 @@ set_target_properties(raw_r PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(raw_r PUBLIC ${MATH_LIBRARY}) target_include_directories(raw_r PUBLIC - $ + $ $) if(WIN32) @@ -574,6 +701,28 @@ if(JASPER_SUPPORT_CAN_BE_COMPILED) target_link_libraries(raw_r PUBLIC ${JASPER_LIBRARIES}) endif() +if (DNG_SDK_SUPPORT_CAN_BE_COMPILED) + + target_link_libraries( + raw_r + PUBLIC + ${XMP_LIB_DIR}/staticXMPCore.ar + ${XMP_LIB_DIR}/staticXMPFiles.ar + + # If we just try to link the static libraries generated by XMP we get a bunch of + # duplicate symbol errors as for some reason we currently have an issue where some + # of the symbols from the core library end up in the XMPFiles library but we still + # need to import both. So we have to tell the linker we don't care for these particular + # libraries and to just link them anyway. + # + "-Wl,--whole-archive" + "-Wl,--no-whole-archive" + ) + + add_dependencies(raw XMPCoreStatic XMPFilesStatic) + add_dependencies(raw_r XMPCoreStatic XMPFilesStatic) +endif() + if(RAWSPEED_SUPPORT_CAN_BE_COMPILED) target_link_libraries(raw_r PUBLIC ${LIBXML2_LIBRARIES} Threads::Threads) endif() @@ -586,7 +735,6 @@ set_target_properties(raw_r PROPERTIES COMPILE_PDB_NAME "raw_r") # -- Files to install ------------------------------------------------------------------------------------- if (LIBRAW_INSTALL) # Configure and install data file for packaging. - include(GNUInstallDirs) if(NOT MSVC) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/data/libraw.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libraw.pc @ONLY) @@ -633,6 +781,17 @@ if (LIBRAW_INSTALL) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/FindLibRaw.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/libraw) + # Install DNG SDK's host header as downstream clients may need it + # in order to configure libraw for DNG SDK + # + if (DNG_SDK_SUPPORT_CAN_BE_COMPILED) + # Install DNG SDK files. + install(FILES ${dng_LIB_HEADERS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libraw + COMPONENT Devel + ) + endif() + # Install doc data files. if(NOT MSVC) install(FILES ${LIBRAW_PATH}/COPYRIGHT @@ -726,4 +885,4 @@ if(ENABLE_EXAMPLES) LIBRAW_BUILD_SAMPLES(half_mt.c raw_r) endif() endif() -endif() +endif() \ No newline at end of file diff --git a/cmake/data/libraw_config.h.cmake b/cmake/data/libraw_config.h.cmake index 4e4b314..876fb07 100644 --- a/cmake/data/libraw_config.h.cmake +++ b/cmake/data/libraw_config.h.cmake @@ -35,6 +35,9 @@ it under the terms of the one of two licenses as you choose: /* Define to 1 if LibRaw have been compiled with RedCine codec support */ #cmakedefine LIBRAW_USE_REDCINECODEC 1 +/* Define to 1 if LibRaw have been compiled with Adobe DNG SDK support */ +#cmakedefine LIBRAW_USE_DNG_SDK 1 + /* Define to 1 if LibRaw have been compiled with RawSpeed codec support */ #cmakedefine LIBRAW_USE_RAWSPEED 1