Skip to content
169 changes: 164 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

# ==================================================================================================
Expand All @@ -111,6 +117,9 @@ if(MSVC)
add_definitions(-D_AFX_SECURE_NO_WARNINGS)
endif()

# For variables in $<INSTALL_INTERFACE:...>
include(GNUInstallDirs)

# -- Check dependencies --------------------------------------------------------------------------------

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} )
Expand Down Expand Up @@ -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)
Comment on lines +287 to +288
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CMake files support Windows and macOS as well. Why would this feature be restricted to Linux?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CMake files support Windows and macOS as well. Why would this feature be restricted to Linux?

I just need to extend this code to detect the OS the system is building under, I'm not sure what the best way is to do this.


# 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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -475,7 +583,7 @@ endif()

target_include_directories(raw
PUBLIC
$<INSTALL_INTERFACE:libraw>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libraw>
$<BUILD_INTERFACE:${LIBRAW_PATH}>)

target_link_libraries(raw PUBLIC ${MATH_LIBRARY})
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since XMP is pulled in via add_subdirectory, doesn't it have CMake targets that could be referenced here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since XMP is pulled in via add_subdirectory, doesn't it have CMake targets that could be referenced here?

It does but what seems to be happening is in the Adobe build script it moves the .a static libraries to being a .ac file in a way that Cmake isn't aware of and if you attempt to link it using the targets then it will try to link to the .a files which no longer exist.

I'm not sure really what the solution was other than to point to it directly like this.

${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()
Expand Down Expand Up @@ -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
$<INSTALL_INTERFACE:libraw>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/libraw>
$<BUILD_INTERFACE:${LIBRAW_PATH}>)

if(WIN32)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this standard practice for the DNG SDK? Normally, a library should only ship its own headers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this standard practice for the DNG SDK? Normally, a library should only ship its own headers.

No, I think we would have to move this to an install step for the DNG SDK. The reason being is downstream libraries need the "dng_host.h" in order to configure libraw to use the Adobe SDK as you need to pass it an instance of the dng host class.

# 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
Expand Down Expand Up @@ -726,4 +885,4 @@ if(ENABLE_EXAMPLES)
LIBRAW_BUILD_SAMPLES(half_mt.c raw_r)
endif()
endif()
endif()
endif()
3 changes: 3 additions & 0 deletions cmake/data/libraw_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down