summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/CMakeLists.txt
blob: 938f15dcbb0fc0a2e70fd106e2a221799be005b6 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# 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.

set(JPEGXL_MAJOR_VERSION 0)
set(JPEGXL_MINOR_VERSION 10)
set(JPEGXL_PATCH_VERSION 0)
set(JPEGXL_LIBRARY_VERSION
    "${JPEGXL_MAJOR_VERSION}.${JPEGXL_MINOR_VERSION}.${JPEGXL_PATCH_VERSION}")

# This is the library API/ABI compatibility version. Changing this value makes
# the shared library incompatible with previous version. A program linked
# against this shared library SOVERSION will not run with an older SOVERSION.
# It is important to update this value when making incompatible API/ABI changes
# so that programs that depend on libjxl can update their dependencies. Semantic
# versioning allows 0.y.z to have incompatible changes in minor versions.
set(JPEGXL_SO_MINOR_VERSION 10)
if (JPEGXL_MAJOR_VERSION EQUAL 0)
  set(JPEGXL_LIBRARY_SOVERSION
      "${JPEGXL_MAJOR_VERSION}.${JPEGXL_SO_MINOR_VERSION}")
else()
  set(JPEGXL_LIBRARY_SOVERSION "${JPEGXL_MAJOR_VERSION}")
endif()


# List of warning and feature flags for our library and tests.
if (MSVC)
  set(JPEGXL_INTERNAL_FLAGS
    # TODO(janwas): add flags
  )
else ()
  set(JPEGXL_INTERNAL_FLAGS
    # F_FLAGS
    -fmerge-all-constants
    -fno-builtin-fwrite
    -fno-builtin-fread

    # WARN_FLAGS
    -Wall
    -Wextra
    -Wc++11-compat
    -Warray-bounds
    -Wformat-security
    -Wimplicit-fallthrough
    -Wno-register  # Needed by public headers in lcms
    -Wno-unused-function
    -Wno-unused-parameter
    -Wnon-virtual-dtor
    -Woverloaded-virtual
    -Wvla
  )

  # Warning flags supported by clang.
  if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    list(APPEND JPEGXL_INTERNAL_FLAGS
      -Wdeprecated-increment-bool
      # TODO(deymo): Add -Wextra-semi once we update third_party/highway.
      # -Wextra-semi
      -Wfloat-overflow-conversion
      -Wfloat-zero-conversion
      -Wfor-loop-analysis
      -Wgnu-redeclared-enum
      -Winfinite-recursion
      -Wliteral-conversion
      -Wno-c++98-compat
      -Wno-unused-command-line-argument
      -Wprivate-header
      -Wself-assign
      -Wstring-conversion
      -Wtautological-overlap-compare
      -Wthread-safety-analysis
      -Wundefined-func-template
      -Wunreachable-code
      -Wunused-comparison
    )
    if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
      list(APPEND HWY_FLAGS -Wc++2a-extensions)
    endif()
  endif()  # Clang

  if (WIN32)
    list(APPEND JPEGXL_INTERNAL_FLAGS
      -Wno-cast-align
      -Wno-double-promotion
      -Wno-float-equal
      -Wno-format-nonliteral
      -Wno-shadow
      -Wno-sign-conversion
      -Wno-zero-as-null-pointer-constant
    )

    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
      list(APPEND JPEGXL_INTERNAL_FLAGS
        -Wno-used-but-marked-unused
        -Wno-unused-template
        -Wno-unused-member-function
        -Wno-shadow-field-in-constructor
        -Wno-language-extension-token
        -Wno-global-constructors
        -Wno-c++98-compat-pedantic
      )
    endif()  # Clang
  else()  # WIN32
    list(APPEND JPEGXL_INTERNAL_FLAGS
      -fsized-deallocation
      -fno-exceptions

      # Language flags
      -fmath-errno
    )

    if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
      list(APPEND JPEGXL_INTERNAL_FLAGS
        -fnew-alignment=8
        -fno-cxx-exceptions
        -fno-slp-vectorize
        -fno-vectorize

        -disable-free
        -disable-llvm-verifier
      )
    endif()  # Clang
  endif()  # WIN32
endif()  #!MSVC

if (JPEGXL_ENABLE_SKCMS)
  list(APPEND JPEGXL_INTERNAL_FLAGS -DJPEGXL_ENABLE_SKCMS=1)
endif ()

# strips the -internal suffix from all the elements in LIST
function(strip_internal OUTPUT_VAR LIB_LIST)
  foreach(lib IN LISTS ${LIB_LIST})
    string(REGEX REPLACE "-internal$" "" lib "${lib}")
    list(APPEND out_list "${lib}")
  endforeach()
  set(${OUTPUT_VAR} ${out_list} PARENT_SCOPE)
endfunction()

# set variables for jxl_cms.cmake and jxl.cmake
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
    set(PKGCONFIG_TARGET_INCLUDES "${CMAKE_INSTALL_INCLUDEDIR}")
else()
    set(PKGCONFIG_TARGET_INCLUDES "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
    set(PKGCONFIG_TARGET_LIBS "${CMAKE_INSTALL_LIBDIR}")
else()
    set(PKGCONFIG_TARGET_LIBS "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()

# The jxl_cms library definition.
include(jxl_cms.cmake)
# The jxl library definition.
include(jxl.cmake)

# Other libraries outside the core jxl library.
if(JPEGXL_ENABLE_TOOLS OR BUILD_TESTING)
  include(jxl_extras.cmake)
endif()
include(jxl_threads.cmake)
if (JPEGXL_ENABLE_JPEGLI)
  include(jpegli.cmake)
endif()

# For simplicity all the library headers, both source and generated ones, are
# gathered in the binary folder. There is no distinction on which libraries use
# which header since it is expected that all developer libraries are available
# together at build time.
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/jxl
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

if(BUILD_TESTING)
  include(GoogleTest)
endif()

# Tests for the jxl library.
include(jxl_tests.cmake)

if(BUILD_TESTING)
  # Google benchmark for the jxl library
  include(jxl_benchmark.cmake)
endif()