Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/libtiff-src/CMakeLists.txt

raw
1 # CMake build for libtiff
2 #
3 # Copyright © 2015 Open Microscopy Environment / University of Dundee
4 # Written by Roger Leigh <[email protected]>
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and
7 # its documentation for any purpose is hereby granted without fee, provided
8 # that (i) the above copyright notices and this permission notice appear in
9 # all copies of the software and related documentation, and (ii) the names of
10 # Sam Leffler and Silicon Graphics may not be used in any advertising or
11 # publicity relating to the software without the specific, prior written
12 # permission of Sam Leffler and Silicon Graphics.
13 #
14 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
16 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 #
18 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
19 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
20 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
22 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 # OF THIS SOFTWARE.
24
25 # Generate headers
26 # and update configuration settings and package / version information.
27 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in
28 ${CMAKE_CURRENT_BINARY_DIR}/tif_config.h
29 @ONLY)
30 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in
31 ${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h
32 @ONLY)
33 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tiffvers.h.cmake.in
34 ${CMAKE_CURRENT_BINARY_DIR}/tiffvers.h
35 @ONLY)
36
37 set(tiff_public_HEADERS
38 tiff.h
39 tiffio.h
40 ${CMAKE_CURRENT_BINARY_DIR}/tiffvers.h
41 ${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h)
42
43 set(tiff_private_HEADERS
44 t4.h
45 tif_dir.h
46 tif_predict.h
47 tiffiop.h
48 uvcode.h
49 ${CMAKE_CURRENT_BINARY_DIR}/tif_config.h)
50
51
52 add_library(tiff libtiff.def)
53 add_library(TIFF::tiff ALIAS tiff)
54
55 target_sources(tiff PRIVATE
56 ${tiff_public_HEADERS}
57 ${tiff_private_HEADERS}
58 tif_aux.c
59 tif_close.c
60 tif_codec.c
61 tif_color.c
62 tif_compress.c
63 tif_dir.c
64 tif_dirinfo.c
65 tif_dirread.c
66 tif_dirwrite.c
67 tif_dumpmode.c
68 tif_error.c
69 tif_extension.c
70 tif_fax3.c
71 tif_fax3sm.c
72 tif_flush.c
73 tif_getimage.c
74 tif_hash_set.c
75 tif_jbig.c
76 tif_jpeg.c
77 tif_jpeg_12.c
78 tif_lerc.c
79 tif_luv.c
80 tif_lzma.c
81 tif_lzw.c
82 tif_next.c
83 tif_ojpeg.c
84 tif_open.c
85 tif_packbits.c
86 tif_pixarlog.c
87 tif_predict.c
88 tif_print.c
89 tif_read.c
90 tif_strip.c
91 tif_swab.c
92 tif_thunder.c
93 tif_tile.c
94 tif_version.c
95 tif_warning.c
96 tif_webp.c
97 tif_write.c
98 tif_zip.c
99 tif_zstd.c)
100
101 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
102 set_property(SOURCE tif_jpeg.c tif_jpeg12.c PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
103 endif ()
104
105 # For all files (but tif_open.c, tif_unix.c and tif_win32.c), forbid the use
106 # of _TIFFmalloc/_TIFFfree and require the use of their "Ext" versions
107 target_compile_definitions(tiff PRIVATE TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS)
108 set_property(SOURCE tif_open.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS)
109
110 if(USE_WIN32_FILEIO)
111 target_sources(tiff PRIVATE tif_win32.c)
112 set_property(SOURCE tif_win32.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS)
113 else()
114 target_sources(tiff PRIVATE tif_unix.c)
115 set_property(SOURCE tif_unix.c APPEND PROPERTY COMPILE_DEFINITIONS ALLOW_TIFF_NON_EXT_ALLOC_FUNCTIONS)
116 endif()
117
118 target_include_directories(tiff
119 PUBLIC
120 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
121 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
122 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
123 PRIVATE
124 ${TIFF_INCLUDES}
125 )
126
127 # Windows specific resource preparation
128 if (WIN32)
129 message(STATUS "Include resource version information for LibTIFF")
130 target_sources(tiff PRIVATE tif_win32_versioninfo.rc)
131 source_group("Resource Files" FILES tif_win32_versioninfo.rc)
132 endif ()
133
134
135 set(tiff_libs_private_list "") # cmake list
136 set(tiff_requires_private "") # cmake string
137
138 if(ZIP_SUPPORT)
139 target_link_libraries(tiff PRIVATE ZLIB::ZLIB)
140 string(APPEND tiff_requires_private " zlib")
141 endif()
142 if(ZIP_SUPPORT AND LIBDEFLATE_SUPPORT)
143 target_link_libraries(tiff PRIVATE Deflate::Deflate)
144 if(Deflate_VERSION_STRING VERSION_GREATER_EQUAL "1.9")
145 string(APPEND tiff_requires_private " libdeflate")
146 else()
147 list(APPEND tiff_libs_private_list "${Deflate_LIBRARY}")
148 endif()
149 endif()
150 if(JPEG_SUPPORT)
151 target_link_libraries(tiff PRIVATE JPEG::JPEG)
152 string(APPEND tiff_requires_private " libjpeg")
153 if(HAVE_JPEGTURBO_DUAL_MODE_8_12)
154 target_compile_definitions(tiff PRIVATE HAVE_JPEGTURBO_DUAL_MODE_8_12)
155 elseif(JPEG_DUAL_MODE_8_12)
156 target_include_directories(tiff PRIVATE ${JPEG12_INCLUDE_DIR})
157 target_link_libraries(tiff PRIVATE ${JPEG12_LIBRARIES})
158 endif()
159 endif()
160 if(JBIG_SUPPORT)
161 target_link_libraries(tiff PRIVATE JBIG::JBIG)
162 list(APPEND tiff_libs_private_list "${JBIG_LIBRARY}")
163 endif()
164 if(LERC_SUPPORT)
165 target_link_libraries(tiff PRIVATE LERC::LERC)
166 if(LERC_VERSION_STRING VERSION_GREATER_EQUAL "4.0")
167 if(NOT BUILD_SHARED_LIBS)
168 set_target_properties(tiff PROPERTIES COMPILE_DEFINITIONS LERC_STATIC)
169 endif()
170 string(APPEND tiff_requires_private " Lerc")
171 else()
172 list(APPEND tiff_libs_private_list "${LERC_LIBRARY}")
173 endif()
174 endif()
175 if(LZMA_SUPPORT)
176 target_link_libraries(tiff PRIVATE liblzma::liblzma)
177 string(APPEND tiff_requires_private " liblzma")
178 endif()
179 if(ZSTD_SUPPORT)
180 target_link_libraries(tiff PRIVATE ZSTD::ZSTD)
181 string(APPEND tiff_requires_private " libzstd")
182 endif()
183 if(WEBP_SUPPORT)
184 target_link_libraries(tiff PRIVATE WebP::webp)
185 string(APPEND tiff_requires_private " libwebp")
186 endif()
187 if(CMath_LIBRARY)
188 target_link_libraries(tiff PRIVATE CMath::CMath)
189 list(APPEND tiff_libs_private_list "${CMath_LIBRARY}")
190 endif()
191
192 set(tiff_libs_private_list "${tiff_libs_private_list}" PARENT_SCOPE)
193 set(tiff_requires_private "${tiff_requires_private}" PARENT_SCOPE)
194
195 set_target_properties(tiff PROPERTIES SOVERSION ${SO_COMPATVERSION})
196 if(NOT CYGWIN)
197 # This property causes shared libraries on Linux to have the full version
198 # encoded into their final filename. We disable this on Cygwin because
199 # it causes cygz-${TIFF_FULL_VERSION}.dll to be created when cygz.dll
200 # seems to be the default.
201 set_target_properties(tiff PROPERTIES VERSION ${SO_VERSION})
202 endif()
203 if(HAVE_LD_VERSION_SCRIPT)
204 set_target_properties(tiff PROPERTIES LINK_FLAGS
205 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libtiff.map")
206 endif()
207
208 if(tiff-install)
209 export(TARGETS tiff NAMESPACE TIFF:: FILE "${CMAKE_CURRENT_BINARY_DIR}/libtiffTargets.cmake")
210 install(TARGETS tiff EXPORT TiffTargets
211 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
212 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
213 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
214
215 install(FILES ${tiff_public_HEADERS}
216 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
217
218 set(TIFF_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/tiff)
219 install(EXPORT TiffTargets
220 FILE TiffTargets.cmake
221 NAMESPACE TIFF::
222 DESTINATION ${TIFF_CONFIGDIR}
223 )
224
225 include(CMakePackageConfigHelpers)
226 write_basic_package_version_file(
227 TiffConfigVersion.cmake
228 VERSION ${LIBTIFF_VERSION}
229 COMPATIBILITY SameMajorVersion)
230 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TiffConfigVersion.cmake DESTINATION ${TIFF_CONFIGDIR})
231
232 configure_file(${PROJECT_SOURCE_DIR}/cmake/TiffConfig.cmake.in
233 ${CMAKE_CURRENT_BINARY_DIR}/TiffConfig.cmake @ONLY)
234 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TiffConfig.cmake DESTINATION ${TIFF_CONFIGDIR})
235 endif()
236
237 if(CXX_SUPPORT)
238 set(tiffxx_HEADERS
239 tiffio.hxx)
240
241 # No .def file for this library.
242 if (WIN32 AND NOT MINGW)
243 add_library(tiffxx STATIC ../placeholder.h)
244 else()
245 add_library(tiffxx ../placeholder.h)
246 endif()
247
248 add_library(TIFF::CXX ALIAS tiffxx)
249
250 target_sources(tiffxx PRIVATE
251 ${tiffxx_HEADERS}
252 tif_stream.cxx)
253 target_link_libraries(tiffxx tiff)
254 set_target_properties(tiffxx PROPERTIES SOVERSION ${SO_COMPATVERSION})
255 if(NOT CYGWIN)
256 # This property causes shared libraries on Linux to have the full version
257 # encoded into their final filename. We disable this on Cygwin because
258 # it causes cygz-${TIFF_FULL_VERSION}.dll to be created when cygz.dll
259 # seems to be the default.
260 set_target_properties(tiffxx PROPERTIES VERSION ${SO_VERSION})
261 endif()
262 if(HAVE_LD_VERSION_SCRIPT)
263 set_target_properties(tiffxx PROPERTIES LINK_FLAGS
264 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libtiffxx.map")
265 endif()
266
267 if(tiff-install)
268 install(TARGETS tiffxx
269 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
270 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
271 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
272
273 install(FILES ${tiffxx_HEADERS}
274 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
275 endif()
276
277 endif()
278
279 if(NOT CMAKE_CROSSCOMPILING)
280 add_executable(tiff_mkg3states ../placeholder.h)
281 target_sources(tiff_mkg3states PRIVATE mkg3states.c tif_fax3.h)
282 target_link_libraries(tiff_mkg3states tiff tiff_port)
283
284 add_custom_target(tiff_faxtable
285 DEPENDS tiff_mkg3states
286 COMMAND ${CMAKE_COMMAND} -E rm "tif_fax3sm.c"
287 COMMAND tiff_mkg3states -b -c const "tif_fax3sm.c"
288 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
289 endif()