From f00550899b083385325b8949ded3a2e6e666cc41 Mon Sep 17 00:00:00 2001 From: Wojciech Jarosz Date: Tue, 4 Feb 2025 08:32:09 -0500 Subject: [PATCH] cmake work. requiring lcms2 --- CMakeLists.txt | 23 +++++++--- cmake/modules/FindLCMS2.cmake | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 cmake/modules/FindLCMS2.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 491033f..62ede1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,10 @@ CPMAddPackage( ) if(openexr_ADDED) message(STATUS "Building OpenEXR library with threading options: ${OPENEXR_THREADING_OPTIONS}") +elseif(TARGET OpenEXR::OpenEXR) + message(STATUS "Will link against system-installed OpenEXR library") +else() + message(FATAL_ERROR "OpenEXR library not found. Please install it.") endif() list(APPEND HDRVIEW_DEPENDENCIES "OpenEXR::OpenEXR") @@ -417,9 +421,9 @@ if(HDRVIEW_ENABLE_UHDR) "UHDR_ENABLE_INTRINSICS OFF" ) if(libuhdr_ADDED) - message(STATUS "Will build uhdr library with UHDR_BUILD_DEPS=${UHDR_BUILD_DEPS}") + message(STATUS "Building uhdr library with UHDR_BUILD_DEPS=${UHDR_BUILD_DEPS}") elseif(TARGET core) - message(STATUS "Using local uhdr library") + message(STATUS "Will link against system-installed uhdr library") else() message(FATAL_ERROR "uhdr library not found. Please install it or turn off HDRVIEW_ENABLE_UHDR.") endif() @@ -451,9 +455,9 @@ if(HDRVIEW_ENABLE_JPEGXL) "EXCLUDE_FROM_ALL YES" ) if(JXL_ADDED) - message(STATUS "Will build JPEG-XL library") + message(STATUS "Building JPEG-XL library") elseif(TARGET jxl) - message(STATUS "Using local JPEG-XL library") + message(STATUS "Using system-installed JPEG-XL library") else() message(FATAL_ERROR "JPEG-XL library not found. Please install it or turn off HDRVIEW_ENABLE_JPEGXL.") endif() @@ -462,11 +466,18 @@ if(HDRVIEW_ENABLE_JPEGXL) endif() if(TARGET lcms2) - message(STATUS "Using local lcms2 library") + message(STATUS "Using lcms2 target already provided by one of the other dependencies") list(APPEND HDRVIEW_DEPENDENCIES "lcms2") list(APPEND HDRVIEW_DEFINITIONS HDRVIEW_ENABLE_LCMS2) else() - message(STATUS "lcms2 library not found.") + find_package(LCMS2 REQUIRED) + if(LCMS2_FOUND) + message(STATUS "Using system-installed lcms2 library") + list(APPEND HDRVIEW_DEPENDENCIES "lcms2") + list(APPEND HDRVIEW_DEFINITIONS HDRVIEW_ENABLE_LCMS2) + else() + message(FATAL_ERROR "lcms2 library not found.") + endif() endif() option(HDRVIEW_ENABLE_HEIF "Enable HEIF/AVIF support" OFF) diff --git a/cmake/modules/FindLCMS2.cmake b/cmake/modules/FindLCMS2.cmake new file mode 100644 index 0000000..d837bfe --- /dev/null +++ b/cmake/modules/FindLCMS2.cmake @@ -0,0 +1,79 @@ +# cmake-format: off +# +# - Find LCMS2 +# Find the LCMS2 includes and library +# +# This module defines +# LCMS2_INCLUDE_DIRS, where to find lcms2.h +# LCMS2_LIBRARIES, the libraries needed to use LCMS2. +# LCMS2_VERSION, The value of LCMS_VERSION defined in lcms2.h +# LCMS2_FOUND, If false, do not try to use LCMS2. +# +# If found, it will also define an imported targets for the library: +# - lcms2 +# + +# Copyright (c) the JPEG XL Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. +# +# cmake-format: on + +find_package(PkgConfig QUIET) +if(PkgConfig_FOUND) + pkg_check_modules(PC_LCMS2 QUIET libLCMS2) + set(LCMS2_VERSION ${PC_LCMS2_VERSION}) +endif() + +find_path( + LCMS2_INCLUDE_DIR + NAMES lcms2.h + HINTS ${PC_LCMS2_INCLUDEDIR} ${PC_LCMS2_INCLUDE_DIRS} +) + +find_library( + LCMS2_LIBRARY + NAMES ${LCMS2_NAMES} lcms2 liblcms2 lcms-2 liblcms-2 + HINTS ${PC_LCMS2_LIBDIR} ${PC_LCMS2_LIBRARY_DIRS} +) + +if(LCMS2_INCLUDE_DIR AND NOT LCMS_VERSION) + file(READ ${LCMS2_INCLUDE_DIR}/lcms2.h LCMS2_VERSION_CONTENT) + string(REGEX MATCH "#define[ \t]+LCMS_VERSION[ \t]+([0-9]+)[ \t]*\n" LCMS2_VERSION_MATCH ${LCMS2_VERSION_CONTENT}) + if(LCMS2_VERSION_MATCH) + string(SUBSTRING ${CMAKE_MATCH_1} 0 1 LCMS2_VERSION_MAJOR) + string(SUBSTRING ${CMAKE_MATCH_1} 1 2 LCMS2_VERSION_MINOR) + set(LCMS2_VERSION "${LCMS2_VERSION_MAJOR}.${LCMS2_VERSION_MINOR}") + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + LCMS2 + FOUND_VAR LCMS2_FOUND + REQUIRED_VARS LCMS2_LIBRARY LCMS2_INCLUDE_DIR + VERSION_VAR LCMS2_VERSION +) + +if(LCMS2_LIBRARY AND NOT TARGET lcms2) + add_library(lcms2 INTERFACE IMPORTED GLOBAL) + + if(CMAKE_VERSION VERSION_LESS "3.13.5") + set_property(TARGET lcms2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${LCMS2_INCLUDE_DIR}) + target_link_libraries(lcms2 INTERFACE ${LCMS2_LIBRARY}) + set_property(TARGET lcms2 PROPERTY INTERFACE_COMPILE_OPTIONS ${PC_LCMS2_CFLAGS_OTHER}) + else() + target_include_directories(lcms2 INTERFACE ${LCMS2_INCLUDE_DIR}) + target_link_libraries(lcms2 INTERFACE ${LCMS2_LIBRARY}) + target_link_options(lcms2 INTERFACE ${PC_LCMS2_LDFLAGS_OTHER}) + target_compile_options(lcms2 INTERFACE ${PC_LCMS2_CFLAGS_OTHER}) + endif() +endif() + +mark_as_advanced(LCMS2_INCLUDE_DIR LCMS2_LIBRARY) + +if(LCMS2_FOUND) + set(LCMS2_LIBRARIES ${LCMS2_LIBRARY}) + set(LCMS2_INCLUDE_DIRS ${LCMS2_INCLUDE_DIR}) +endif()