summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl_cms.cmake
blob: 04980066c126df6a0cb61921d9c65b580c562245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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.

include(jxl_lists.cmake)

# Headers for exporting/importing public headers
include(GenerateExportHeader)

add_library(jxl_cms
  ${JPEGXL_INTERNAL_CMS_SOURCES}
)
target_compile_options(jxl_cms PRIVATE "${JPEGXL_INTERNAL_FLAGS}")
set_target_properties(jxl_cms PROPERTIES
        POSITION_INDEPENDENT_CODE ON
        CXX_VISIBILITY_PRESET hidden
        VISIBILITY_INLINES_HIDDEN 1)
target_link_libraries(jxl_cms PUBLIC jxl_base)
target_include_directories(jxl_cms PRIVATE
  ${JXL_HWY_INCLUDE_DIRS}
)
generate_export_header(jxl_cms
  BASE_NAME JXL_CMS
  EXPORT_FILE_NAME include/jxl/jxl_cms_export.h)
target_include_directories(jxl_cms PUBLIC
  "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>")

set(JPEGXL_CMS_LIBRARY_REQUIRES "")

if (JPEGXL_ENABLE_SKCMS)
  target_link_skcms(jxl_cms)
else()
  target_link_libraries(jxl_cms PRIVATE lcms2)
  if (JPEGXL_FORCE_SYSTEM_LCMS2)
    set(JPEGXL_CMS_LIBRARY_REQUIRES "lcms2")
  endif()
endif()

target_link_libraries(jxl_cms PRIVATE hwy)

set_target_properties(jxl_cms PROPERTIES
        VERSION ${JPEGXL_LIBRARY_VERSION}
        SOVERSION ${JPEGXL_LIBRARY_SOVERSION})

# Check whether the linker support excluding libs
set(LINKER_EXCLUDE_LIBS_FLAG "-Wl,--exclude-libs=ALL")
include(CheckCSourceCompiles)
list(APPEND CMAKE_EXE_LINKER_FLAGS ${LINKER_EXCLUDE_LIBS_FLAG})
check_c_source_compiles("int main(){return 0;}" LINKER_SUPPORT_EXCLUDE_LIBS)
list(REMOVE_ITEM CMAKE_EXE_LINKER_FLAGS ${LINKER_EXCLUDE_LIBS_FLAG})

if(LINKER_SUPPORT_EXCLUDE_LIBS)
  set_property(TARGET jxl_cms APPEND_STRING PROPERTY
      LINK_FLAGS " ${LINKER_EXCLUDE_LIBS_FLAG}")
endif()

install(TARGETS jxl_cms
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

if (BUILD_SHARED_LIBS)
  set(JPEGXL_REQUIRES_TYPE "Requires.private")
  set(JPEGXL_CMS_PRIVATE_LIBS "-lm ${PKGCONFIG_CXX_LIB}")
else()
  set(JPEGXL_REQUIRES_TYPE "Requires")
  set(JPEGXL_CMS_PRIVATE_LIBS "-lm ${PKGCONFIG_CXX_LIB}")
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/jxl/libjxl_cms.pc.in"
               "libjxl_cms.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libjxl_cms.pc"
  DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")