Warning, /graphics/krita/cmake/modules/FindOpenJPEG.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2023 L. E. Segovia <amy@amyspark.me> 0002 # SPDX-License-Identifier: BSD-3-Clause 0003 # 0004 #[=======================================================================[.rst: 0005 FindOpenJPEG 0006 -------------- 0007 0008 Find OpenJPEG headers and libraries. 0009 0010 Imported Targets 0011 ^^^^^^^^^^^^^^^^ 0012 0013 ``OpenJPEG::openjp2`` 0014 The OpenJPEG library, if found. 0015 0016 ``OpenJPEG::opj_decompress`` 0017 The OpenJPEG decompression executable, if found. 0018 0019 ``OpenJPEG::opj_compress`` 0020 The OpenJPEG compression executable, if found. 0021 0022 ``OpenJPEG::opj_dump`` 0023 The OpenJPEG dump executable, if found. 0024 0025 Result Variables 0026 ^^^^^^^^^^^^^^^^ 0027 0028 This will define the following variables in your project: 0029 0030 ``OpenJPEG_FOUND`` 0031 true if (the requested version of) OpenJPEG is available. 0032 ``OpenJPEG_VERSION`` 0033 the version of OpenJPEG. 0034 ``OpenJPEG_LIBRARIES`` 0035 the libraries to link against to use OpenJPEG. 0036 ``OpenJPEG_INCLUDE_DIRS`` 0037 where to find the OpenJPEG headers. 0038 ``OpenJPEG_COMPILE_OPTIONS`` 0039 this should be passed to target_compile_options(), if the 0040 target is not used for linking 0041 0042 #]=======================================================================] 0043 0044 include(FindPackageHandleStandardArgs) 0045 0046 # No hints in this case because the library versions semantically 0047 # the module folder, and it's also capitalized, so let CMake handle it. 0048 find_package(OPENJPEG QUIET NO_MODULE NAMES OpenJPEG) 0049 mark_as_advanced(OPENJPEG_DIR) 0050 0051 if(OPENJPEG_FOUND) 0052 if (TARGET openjp2 AND NOT TARGET OpenJPEG::openjp2) 0053 add_library(OpenJPEG::openjp2 ALIAS openjp2) 0054 endif() 0055 0056 if (TARGET OpenJPEG::openjp2) 0057 set(OpenJPEG_openjp2_FOUND ON) 0058 else () 0059 set(OpenJPEG_openjp2_FOUND OFF) 0060 endif () 0061 0062 if (TARGET opj_decompress AND NOT TARGET OpenJPEG::opj_decompress) 0063 add_executable(OpenJPEG::opj_decompress ALIAS opj_decompress) 0064 endif() 0065 0066 if (TARGET OpenJPEG::opj_decompress) 0067 set(OpenJPEG_opj_decompress_FOUND ON) 0068 else () 0069 set(OpenJPEG_opj_decompress_FOUND OFF) 0070 endif () 0071 0072 if (TARGET opj_compress AND NOT TARGET OpenJPEG::opj_compress) 0073 add_executable(OpenJPEG::opj_compress ALIAS opj_compress) 0074 endif() 0075 0076 if (TARGET OpenJPEG::opj_compress) 0077 set(OpenJPEG_opj_compress_FOUND ON) 0078 else () 0079 set(OpenJPEG_opj_compress_FOUND OFF) 0080 endif () 0081 0082 if (TARGET opj_dump AND NOT TARGET OpenJPEG::opj_dump) 0083 add_executable(OpenJPEG::opj_dump ALIAS opj_dump) 0084 endif() 0085 0086 if (TARGET OpenJPEG::opj_dump) 0087 set(OpenJPEG_opj_dump_FOUND ON) 0088 else () 0089 set(OpenJPEG_opj_dump_FOUND OFF) 0090 endif () 0091 0092 if (TARGET openjpip AND NOT TARGET OpenJPEG::openjpip) 0093 add_library(OpenJPEG::openjpip ALIAS openjpip) 0094 endif() 0095 0096 if (TARGET OpenJPEG::openjpip) 0097 set(OpenJPEG_openjpip_FOUND ON) 0098 else () 0099 set(OpenJPEG_openjpip_FOUND OFF) 0100 endif () 0101 0102 if (TARGET openjpip_server AND NOT TARGET OpenJPEG::openjpip_server) 0103 add_library(OpenJPEG::openjpip_server ALIAS openjpip_server) 0104 endif() 0105 0106 if (TARGET OpenJPEG::openjpip_server) 0107 set(OpenJPEG_openjpip_server_FOUND ON) 0108 else () 0109 set(OpenJPEG_openjpip_server_FOUND OFF) 0110 endif () 0111 0112 # Patch in the version string, if needed. 0113 if (NOT OpenJPEG_VERSION) 0114 set(OpenJPEG_VERSION "${OPENJPEG_MAJOR_VERSION}.${OPENJPEG_MINOR_VERSION}.${OPENJPEG_BUILD_VERSION}") 0115 endif () 0116 0117 # Patch in the library and include dirs. 0118 if (NOT OpenJPEG_LIBRARIES) 0119 set(OpenJPEG_LIBRARIES OpenJPEG::openjp2) 0120 endif() 0121 set(OpenJPEG_INCLUDE_DIRS "${OPENJPEG_INCLUDE_DIRS}") 0122 0123 find_package_handle_standard_args(OpenJPEG 0124 FOUND_VAR OpenJPEG_FOUND 0125 REQUIRED_VARS OpenJPEG_INCLUDE_DIRS OpenJPEG_LIBRARIES 0126 HANDLE_COMPONENTS 0127 VERSION_VAR OpenJPEG_VERSION 0128 NAME_MISMATCHED 0129 # Don't, it defines mismatching cased variables. 0130 # CONFIG_MODE 0131 ) 0132 return() 0133 endif() 0134 0135 find_package(PkgConfig QUIET) 0136 0137 if (PkgConfig_FOUND) 0138 pkg_check_modules(PC_OPENJPEG QUIET libopenjp2) 0139 set(OpenJPEG_VERSION ${PC_OPENJPEG_VERSION}) 0140 set(OpenJPEG_COMPILE_OPTIONS "${PC_OPENJPEG_CFLAGS};${PC_OPENJPEG_CFLAGS_OTHER}") 0141 0142 pkg_check_modules(PC_OPENJPIP QUIET openjpip) 0143 endif () 0144 0145 find_path(OpenJPEG_INCLUDE_DIR 0146 NAMES openjpeg.h 0147 HINTS ${PC_OPENJPEG_INCLUDEDIR} ${PC_OPENJPEG_INCLUDE_DIRS} 0148 ) 0149 0150 find_library(OpenJPEG_LIBRARY 0151 NAMES openjp2 libopenjp2 0152 HINTS ${PC_OPENJPEG_LIBDIR} ${PC_OPENJPEG_LIBRARY_DIRS} 0153 ) 0154 0155 # There's nothing in the OpenJPEG headers that could be used to detect the exact 0156 # OpenJPEG version being used so don't attempt to do so. A version can only be found 0157 # through pkg-config 0158 if (NOT OpenJPEG_VERSION) 0159 message(WARNING "Cannot determine OpenJPEG version without pkg-config") 0160 endif () 0161 0162 if (OpenJPEG_INCLUDE_DIR AND OpenJPEG_LIBRARY) 0163 set(OpenJPEG_openjp2_FOUND ON) 0164 else() 0165 set(OpenJPEG_openjp2_FOUND OFF) 0166 endif() 0167 0168 # Find components 0169 if ("openjpip" IN_LIST OpenJPEG_FIND_COMPONENTS) 0170 find_library(OpenJPEG_openjpip_LIBRARY 0171 NAMES openjpip libopenjpip 0172 HINTS ${PC_OPENJPIP_LIBDIR} ${PC_OPENJPIP_LIBRARY_DIRS} 0173 ) 0174 0175 if (OpenJPEG_openjpip_LIBRARY) 0176 set(OpenJPEG_openjpip_FOUND ON) 0177 else () 0178 set(OpenJPEG_openjpip_FOUND OFF) 0179 endif () 0180 endif () 0181 0182 if ("openjpip_server" IN_LIST OpenJPEG_FIND_COMPONENTS) 0183 find_library(OpenJPEG_openjpip_server_LIBRARY 0184 NAMES openjpip_server libopenjpip_server 0185 HINTS ${PC_OPENJPIP_LIBDIR} ${PC_OPENJPIP_LIBRARY_DIRS} 0186 ) 0187 0188 if (OpenJPEG_openjpip_server_LIBRARY) 0189 set(OpenJPEG_openjpip_server_FOUND ON) 0190 else () 0191 set(OpenJPEG_openjpip_server_FOUND OFF) 0192 endif () 0193 endif () 0194 0195 find_package_handle_standard_args(OpenJPEG 0196 FOUND_VAR OpenJPEG_FOUND 0197 REQUIRED_VARS OpenJPEG_INCLUDE_DIR OpenJPEG_LIBRARY 0198 HANDLE_COMPONENTS 0199 VERSION_VAR OpenJPEG_VERSION 0200 ) 0201 0202 if (OpenJPEG_FOUND) 0203 if (OpenJPEG_LIBRARY AND NOT TARGET OpenJPEG::openjp2) 0204 add_library(OpenJPEG::openjp2 UNKNOWN IMPORTED GLOBAL) 0205 set_target_properties(OpenJPEG::openjp2 PROPERTIES 0206 IMPORTED_LOCATION "${OpenJPEG_LIBRARY}" 0207 INTERFACE_COMPILE_OPTIONS "${PC_OPENJPEG_CFLAGS};${PC_OPENJPEG_CFLAGS_OTHER}" 0208 INTERFACE_INCLUDE_DIRECTORIES "${OpenJPEG_INCLUDE_DIR};${PC_OPENJPEG_INCLUDE_DIRS}" 0209 INTERFACE_LINK_LIBRARIES "${PC_OPENJPEG_LINK_LIBRARIES}" 0210 ) 0211 endif () 0212 0213 if (OpenJPEG_openjpip_LIBRARY AND NOT TARGET OpenJPEG::openjpip) 0214 add_library(OpenJPEG::openjpip UNKNOWN IMPORTED GLOBAL) 0215 set_target_properties(OpenJPEG::openjpip PROPERTIES 0216 IMPORTED_LOCATION "${OpenJPEG_openjpip_LIBRARY}" 0217 INTERFACE_COMPILE_OPTIONS "${PC_OPENJPIP_CFLAGS};${PC_OPENJPIP_CFLAGS_OTHER}" 0218 INTERFACE_INCLUDE_DIRECTORIES "${OpenJPEG_INCLUDE_DIR};${PC_OPENJPIP_INCLUDE_DIRS}" 0219 INTERFACE_LINK_LIBRARIES "${PC_OPENJPIP_LINK_LIBRARIES}" 0220 ) 0221 endif () 0222 0223 if (OpenJPEG_openjpip_server_LIBRARY AND NOT TARGET OpenJPEG::openjpip_server) 0224 add_library(OpenJPEG::openjpip_server UNKNOWN IMPORTED GLOBAL) 0225 set_target_properties(OpenJPEG::openjpip_server PROPERTIES 0226 IMPORTED_LOCATION "${OpenJPEG_openjpip_server_LIBRARY}" 0227 INTERFACE_COMPILE_OPTIONS "${PC_OPENJPIP_CFLAGS};${PC_OPENJPIP_CFLAGS_OTHER}" 0228 INTERFACE_INCLUDE_DIRECTORIES "${OpenJPEG_INCLUDE_DIR};${PC_OPENJPIP_INCLUDE_DIRS}" 0229 INTERFACE_LINK_LIBRARIES "${PC_OPENJPIP_LINK_LIBRARIES}" 0230 ) 0231 endif () 0232 0233 mark_as_advanced( 0234 OpenJPEG_INCLUDE_DIR 0235 OpenJPEG_LIBRARY 0236 OpenJPEG_openjpip_LIBRARY 0237 OpenJPEG_openjpip_server_LIBRARY 0238 ) 0239 0240 set(OpenJPEG_LIBRARIES ${OpenJPEG_LIBRARY} ${OpenJPEG_openjpip_LIBRARY} ${OpenJPEG_openjpip_server_LIBRARY}) 0241 set(OpenJPEG_INCLUDE_DIRS ${OpenJPEG_INCLUDE_DIR}) 0242 0243 endif()