summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/jpeg-xl/cmake
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/cmake')
-rw-r--r--third_party/jpeg-xl/cmake/FindAtomics.cmake53
-rw-r--r--third_party/jpeg-xl/cmake/FindBrotli.cmake75
-rw-r--r--third_party/jpeg-xl/cmake/FindHWY.cmake66
-rw-r--r--third_party/jpeg-xl/cmake/FindLCMS2.cmake59
4 files changed, 253 insertions, 0 deletions
diff --git a/third_party/jpeg-xl/cmake/FindAtomics.cmake b/third_party/jpeg-xl/cmake/FindAtomics.cmake
new file mode 100644
index 0000000000..9a6cdc39ec
--- /dev/null
+++ b/third_party/jpeg-xl/cmake/FindAtomics.cmake
@@ -0,0 +1,53 @@
+# Original issue:
+# * https://gitlab.kitware.com/cmake/cmake/-/issues/23021#note_1098733
+#
+# For reference:
+# * https://gcc.gnu.org/wiki/Atomic/GCCMM
+#
+# riscv64 specific:
+# * https://lists.debian.org/debian-riscv/2022/01/msg00009.html
+#
+# ATOMICS_FOUND - system has c++ atomics
+# ATOMICS_LIBRARIES - libraries needed to use c++ atomics
+
+include(CheckCXXSourceCompiles)
+
+# RISC-V only has 32-bit and 64-bit atomic instructions. GCC is supposed
+# to convert smaller atomics to those larger ones via masking and
+# shifting like LLVM, but it’s a known bug that it does not. This means
+# anything that wants to use atomics on 1-byte or 2-byte types needs
+# -latomic, but not 4-byte or 8-byte (though it does no harm).
+set(atomic_code
+ "
+ #include <atomic>
+ #include <cstdint>
+ std::atomic<uint8_t> n8 (0); // riscv64
+ std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
+ int main() {
+ ++n8;
+ ++n64;
+ return 0;
+ }")
+
+check_cxx_source_compiles("${atomic_code}" ATOMICS_LOCK_FREE_INSTRUCTIONS)
+
+if(ATOMICS_LOCK_FREE_INSTRUCTIONS)
+ set(ATOMICS_FOUND TRUE)
+ set(ATOMICS_LIBRARIES)
+else()
+ set(CMAKE_REQUIRED_LIBRARIES "-latomic")
+ check_cxx_source_compiles("${atomic_code}" ATOMICS_IN_LIBRARY)
+ set(CMAKE_REQUIRED_LIBRARIES)
+ if(ATOMICS_IN_LIBRARY)
+ set(ATOMICS_LIBRARY atomic)
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Atomics DEFAULT_MSG ATOMICS_LIBRARY)
+ set(ATOMICS_LIBRARIES ${ATOMICS_LIBRARY})
+ unset(ATOMICS_LIBRARY)
+ else()
+ if(Atomics_FIND_REQUIRED)
+ message(FATAL_ERROR "Neither lock free instructions nor -latomic found.")
+ endif()
+ endif()
+endif()
+unset(atomic_code)
diff --git a/third_party/jpeg-xl/cmake/FindBrotli.cmake b/third_party/jpeg-xl/cmake/FindBrotli.cmake
new file mode 100644
index 0000000000..9fb78e47d8
--- /dev/null
+++ b/third_party/jpeg-xl/cmake/FindBrotli.cmake
@@ -0,0 +1,75 @@
+# 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(brlibs brotlicommon brotlienc brotlidec)
+
+find_package(PkgConfig QUIET)
+if (PkgConfig_FOUND)
+ foreach(brlib IN ITEMS ${brlibs})
+ string(TOUPPER "${brlib}" BRPREFIX)
+ pkg_check_modules("PC_${BRPREFIX}" lib${brlib})
+ endforeach()
+endif()
+
+find_path(BROTLI_INCLUDE_DIR
+ NAMES brotli/decode.h
+ HINTS ${PC_BROTLICOMMON_INCLUDEDIR} ${PC_BROTLICOMMON_INCLUDE_DIRS}
+)
+
+foreach(brlib IN ITEMS ${brlibs})
+ string(TOUPPER "${brlib}" BRPREFIX)
+ find_library(${BRPREFIX}_LIBRARY
+ NAMES ${${BRPREFIX}_NAMES} ${brlib}
+ HINTS ${PC_${BRPREFIX}_LIBDIR} ${PC_${BRPREFIX}_LIBRARY_DIRS}
+ )
+
+ if (${BRPREFIX}_LIBRARY AND NOT TARGET ${brlib})
+ if(CMAKE_VERSION VERSION_LESS "3.13.5")
+ add_library(${brlib} INTERFACE IMPORTED GLOBAL)
+ set_property(TARGET ${brlib} PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BROTLI_INCLUDE_DIR})
+ target_link_libraries(${brlib} INTERFACE ${${BRPREFIX}_LIBRARY})
+ set_property(TARGET ${brlib} PROPERTY INTERFACE_COMPILE_OPTIONS ${PC_${BRPREFIX}_CFLAGS_OTHER})
+ else()
+ add_library(${brlib} INTERFACE IMPORTED GLOBAL)
+ target_include_directories(${brlib}
+ INTERFACE ${BROTLI_INCLUDE_DIR})
+ target_link_libraries(${brlib}
+ INTERFACE ${${BRPREFIX}_LIBRARY})
+ target_link_options(${brlib}
+ INTERFACE ${PC_${BRPREFIX}_LDFLAGS_OTHER})
+ target_compile_options(${brlib}
+ INTERFACE ${PC_${BRPREFIX}_CFLAGS_OTHER})
+ endif()
+ endif()
+endforeach()
+
+if (BROTLICOMMON_FOUND AND BROTLIENC_FOUND AND BROTLIDEC_FOUND)
+ set(Brotli_FOUND ON)
+else ()
+ set(Brotli_FOUND OFF)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Brotli
+ FOUND_VAR Brotli_FOUND
+ REQUIRED_VARS
+ BROTLI_INCLUDE_DIR
+ BROTLICOMMON_LIBRARY
+ BROTLIENC_LIBRARY
+ BROTLIDEC_LIBRARY
+ VERSION_VAR Brotli_VERSION
+)
+
+mark_as_advanced(
+ BROTLI_INCLUDE_DIR
+ BROTLICOMMON_LIBRARY
+ BROTLIENC_LIBRARY
+ BROTLIDEC_LIBRARY
+)
+
+if (Brotli_FOUND)
+ set(Brotli_LIBRARIES ${BROTLICOMMON_LIBRARY} ${BROTLIENC_LIBRARY} ${BROTLIDEC_LIBRARY})
+ set(Brotli_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR})
+endif()
diff --git a/third_party/jpeg-xl/cmake/FindHWY.cmake b/third_party/jpeg-xl/cmake/FindHWY.cmake
new file mode 100644
index 0000000000..c1deb9b851
--- /dev/null
+++ b/third_party/jpeg-xl/cmake/FindHWY.cmake
@@ -0,0 +1,66 @@
+# 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.
+
+find_package(PkgConfig QUIET)
+if (PkgConfig_FOUND)
+ pkg_check_modules(PC_HWY QUIET libhwy)
+ set(HWY_VERSION ${PC_HWY_VERSION})
+endif ()
+
+find_path(HWY_INCLUDE_DIR
+ NAMES hwy/highway.h
+ HINTS ${PC_HWY_INCLUDEDIR} ${PC_HWY_INCLUDE_DIRS}
+)
+
+find_library(HWY_LIBRARY
+ NAMES ${HWY_NAMES} hwy
+ HINTS ${PC_HWY_LIBDIR} ${PC_HWY_LIBRARY_DIRS}
+)
+
+if (HWY_INCLUDE_DIR AND NOT HWY_VERSION)
+ if (EXISTS "${HWY_INCLUDE_DIR}/hwy/highway.h")
+ file(READ "${HWY_INCLUDE_DIR}/hwy/highway.h" HWY_VERSION_CONTENT)
+
+ string(REGEX MATCH "#define HWY_MAJOR +([0-9]+)" _dummy "${HWY_VERSION_CONTENT}")
+ set(HWY_VERSION_MAJOR "${CMAKE_MATCH_1}")
+
+ string(REGEX MATCH "#define +HWY_MINOR +([0-9]+)" _dummy "${HWY_VERSION_CONTENT}")
+ set(HWY_VERSION_MINOR "${CMAKE_MATCH_1}")
+
+ string(REGEX MATCH "#define +HWY_PATCH +([0-9]+)" _dummy "${HWY_VERSION_CONTENT}")
+ set(HWY_VERSION_PATCH "${CMAKE_MATCH_1}")
+
+ set(HWY_VERSION "${HWY_VERSION_MAJOR}.${HWY_VERSION_MINOR}.${HWY_VERSION_PATCH}")
+ endif ()
+endif ()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(HWY
+ FOUND_VAR HWY_FOUND
+ REQUIRED_VARS HWY_LIBRARY HWY_INCLUDE_DIR
+ VERSION_VAR HWY_VERSION
+)
+
+if (HWY_LIBRARY AND NOT TARGET hwy)
+ add_library(hwy INTERFACE IMPORTED GLOBAL)
+
+ if(CMAKE_VERSION VERSION_LESS "3.13.5")
+ set_property(TARGET hwy PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HWY_INCLUDE_DIR})
+ target_link_libraries(hwy INTERFACE ${HWY_LIBRARY})
+ set_property(TARGET hwy PROPERTY INTERFACE_COMPILE_OPTIONS ${PC_HWY_CFLAGS_OTHER})
+ else()
+ target_include_directories(hwy INTERFACE ${HWY_INCLUDE_DIR})
+ target_link_libraries(hwy INTERFACE ${HWY_LIBRARY})
+ target_link_options(hwy INTERFACE ${PC_HWY_LDFLAGS_OTHER})
+ target_compile_options(hwy INTERFACE ${PC_HWY_CFLAGS_OTHER})
+ endif()
+endif()
+
+mark_as_advanced(HWY_INCLUDE_DIR HWY_LIBRARY)
+
+if (HWY_FOUND)
+ set(HWY_LIBRARIES ${HWY_LIBRARY})
+ set(HWY_INCLUDE_DIRS ${HWY_INCLUDE_DIR})
+endif ()
diff --git a/third_party/jpeg-xl/cmake/FindLCMS2.cmake b/third_party/jpeg-xl/cmake/FindLCMS2.cmake
new file mode 100644
index 0000000000..0a7b54eb96
--- /dev/null
+++ b/third_party/jpeg-xl/cmake/FindLCMS2.cmake
@@ -0,0 +1,59 @@
+# 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.
+
+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 ()