(metux) configure.ac: removed broken and obsolete AC_C_CONST
[mirror-ossqm-libpng.git] / CMakeLists.txt
blob2ee5bf3384d969fa46e4bcb0b24e5d8858057b7a
1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
4 if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
5   if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
6     # workaround CMake 2.4.x bug
7     set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
8         "Choose the type of build, options are:
9            None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
10            Debug
11            Release
12            RelWithDebInfo
13            MinSizeRel.")
14   else()
15     set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
16         "Choose the type of build, options are:
17            None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
18            Debug
19            Release
20            RelWithDebInfo
21            MinSizeRel.")
22   endif()
23 endif()
25 project(libpng C)
26 enable_testing()
28 # Copyright (C) 2007-2011 Glenn Randers-Pehrson
30 # This code is released under the libpng license.
31 # For conditions of distribution and use, see the disclaimer
32 # and license in png.h
34 set(PNGLIB_MAJOR 1)
35 set(PNGLIB_MINOR 5)
36 set(PNGLIB_RELEASE 1)
37 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
38 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
40 # needed packages
41 find_package(ZLIB REQUIRED)
42 include_directories(${ZLIB_INCLUDE_DIR})
44 if(NOT WIN32)
45   find_library(M_LIBRARY
46     NAMES m
47     PATHS /usr/lib /usr/local/lib
48   )
49   if(NOT M_LIBRARY)
50     message(STATUS
51       "math library 'libm' not found - floating point support disabled")
52   endif()
53 else()
54   # not needed on windows
55   set(M_LIBRARY "")
56 endif()
58 # COMMAND LINE OPTIONS
59 if(DEFINED PNG_SHARED)
60   option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
61 else()
62   option(PNG_SHARED "Build shared lib" ON)
63 endif()
64 if(DEFINED PNG_STATIC)
65   option(PNG_STATIC "Build static lib" ${PNG_STATIC})
66 else()
67   option(PNG_STATIC "Build static lib" ON)
68 endif()
70 if(MINGW)
71   option(PNG_TESTS  "Build pngtest" NO)
72 else()
73   option(PNG_TESTS  "Build pngtest" YES)
74 endif()
76 option(PNG_NO_CONSOLE_IO "FIXME" YES)
77 option(PNG_NO_STDIO      "FIXME" YES)
78 option(PNG_DEBUG         "Build with debug output" NO)
79 option(PNGARG            "FIXME" YES)
80 #TODO:
81 # PNG_CONSOLE_IO_SUPPORTED
83 # maybe needs improving, but currently I don't know when we can enable what :)
84 set(png_asm_tmp "OFF")
85 if(NOT WIN32)
86   find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
87   if(uname_executable)
88     exec_program(${uname_executable}
89                  ARGS --machine OUTPUT_VARIABLE uname_output)
90     if("uname_output" MATCHES "^.*i[1-9]86.*$")
91       set(png_asm_tmp "ON")
92     else("uname_output" MATCHES "^.*i[1-9]86.*$")
93       set(png_asm_tmp "OFF")
94     endif("uname_output" MATCHES "^.*i[1-9]86.*$")
95   endif(uname_executable)
96 else()
97   # this env var is normally only set on win64
98   set(TEXT "ProgramFiles(x86)")
99   if("$ENV{${TEXT}}" STREQUAL "")
100     set(png_asm_tmp "ON")
101   endif("$ENV{${TEXT}}" STREQUAL "")
102 endif()
104 # SET LIBNAME
105 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
107 # to distinguish between debug and release lib
108 set(CMAKE_DEBUG_POSTFIX "d")
110 # Use the prebuilt pnglibconf.h file from the scripts folder
111 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
112                ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
113 include_directories(${CMAKE_CURRENT_BINARY_DIR})
115 # OUR SOURCES
116 set(libpng_public_hdrs
117   png.h
118   pngconf.h
119   ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
121 set(libpng_sources
122   ${libpng_public_hdrs}
123   pngdebug.h
124   pnginfo.h
125   pngpriv.h
126   pngstruct.h
127   png.c
128   pngerror.c
129   pngget.c
130   pngmem.c
131   pngpread.c
132   pngread.c
133   pngrio.c
134   pngrtran.c
135   pngrutil.c
136   pngset.c
137   pngtrans.c
138   pngwio.c
139   pngwrite.c
140   pngwtran.c
141   pngwutil.c
143 set(pngtest_sources
144   pngtest.c
146 # SOME NEEDED DEFINITIONS
148 add_definitions(-DPNG_CONFIGURE_LIBPNG)
150 if(_AIX)
151   add_definitions(-D_ALL_SOURCE)
152 endif(_AIX)
154 if(MSVC)
155   add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
156 endif(MSVC)
158 if(PNG_SHARED OR  NOT MSVC)
159   #if building msvc static this has NOT to be defined
160   add_definitions(-DZLIB_DLL)
161 endif()
164 if(PNG_CONSOLE_IO_SUPPORTED)
165   add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
166 endif()
168 if(PNG_NO_CONSOLE_IO)
169   add_definitions(-DPNG_NO_CONSOLE_IO)
170 endif()
172 if(PNG_NO_STDIO)
173   add_definitions(-DPNG_NO_STDIO)
174 endif()
176 if(PNG_DEBUG)
177   add_definitions(-DPNG_DEBUG)
178 endif()
180 if(NOT M_LIBRARY AND NOT WIN32)
181   add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
182 endif()
184 # NOW BUILD OUR TARGET
185 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
187 if(PNG_SHARED)
188   add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
189   if(MSVC)
190     # msvc does not append 'lib' - do it here to have consistent name
191     set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
192     set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
193   endif()
194   target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
195 endif()
197 if(PNG_STATIC)
198 # does not work without changing name
199   set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
200   add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
201   if(MSVC)
202     # msvc does not append 'lib' - do it here to have consistent name
203     set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
204   endif()
205   target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
206 endif()
209 if(PNG_SHARED AND WIN32)
210   set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
211 endif()
213 if(PNG_TESTS AND PNG_SHARED)
214   # does not work with msvc due to png_lib_ver issue
215   add_executable(pngtest ${pngtest_sources})
216   target_link_libraries(pngtest ${PNG_LIB_NAME})
217   add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
218 endif()
221 # Set a variable with CMake code which:
222 # Creates a symlink from src to dest (if possible) or alternatively
223 # copies if different.
224 macro(_png_generate_symlink_code CODE SRC DEST)
225   if(WIN32 AND NOT CYGWIN)
226     set(_png_gsc_message "Copying ${SRC} to ${DEST} if needed")
227     set(_png_gsc_operation "copy_if_different")
228   else()
229     set(_png_gsc_message "Symlinking ${SRC} to ${DEST}")
230     set(_png_gsc_operation "create_symlink")
231   endif()
233   set(${CODE} "
234     message(STATUS \"${_png_gsc_message}\")
235     execute_process(COMMAND \${CMAKE_COMMAND} -E ${_png_gsc_operation}
236       \"${SRC}\" \"${DEST}\")
237     ")
238 endmacro()
240 # CREATE PKGCONFIG FILES
241 # we use the same files like ./configure, so we have to set its vars
242 if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
243   set(CMAKE_INSTALL_LIBDIR lib)
244 endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
245 set(prefix      ${CMAKE_INSTALL_PREFIX})
246 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
247 set(libdir      ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
248 set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
249 set(LIBS        "-lz -lm")
250 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
251   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
252 _png_generate_symlink_code(PNG_PC_INSTALL_CODE
253   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
254   ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
255 install(CODE ${PNG_PC_INSTALL_CODE})
257 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
258   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
259 _png_generate_symlink_code(PNG_CONFIG_INSTALL_CODE
260   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
261   ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
262 install(CODE ${PNG_CONFIG_INSTALL_CODE})
264 # SET UP LINKS
265 if(PNG_SHARED)
266   set_target_properties(${PNG_LIB_NAME} PROPERTIES
267 #   VERSION 15.${PNGLIB_RELEASE}.1.5.1
268     VERSION 15.${PNGLIB_RELEASE}.0
269     SOVERSION 15
270     CLEAN_DIRECT_OUTPUT 1)
271 endif()
272 if(PNG_STATIC)
273   # MSVC doesn't use a different file extension for shared vs. static
274   # libs.  We are able to change OUTPUT_NAME to remove the _static
275   # for all other platforms.
276   if(NOT MSVC)
277     set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
278       OUTPUT_NAME ${PNG_LIB_NAME}
279       CLEAN_DIRECT_OUTPUT 1)
280   endif()
281 endif()
283 # If CMake > 2.4.x, we set a variable used below to export
284 # targets to an export file.
285 # TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
286 if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
287   set(PNG_EXPORT_RULE EXPORT libpng)
288 elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
289   set(PNG_EXPORT_RULE EXPORT libpng)
290 endif()
292 # INSTALL
293 if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
294   if(PNG_SHARED)
295     install(TARGETS ${PNG_LIB_NAME}
296         ${PNG_EXPORT_RULE}
297         RUNTIME DESTINATION bin
298         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
299         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
301     # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
302     if(CYGWIN)
303       _png_generate_symlink_code(PNG_SHARED_IMPLIB_INSTALL_CODE
304         ${PNGLIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}
305         libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
306       install(CODE ${PNG_SHARED_IMPLIB_INSTALL_CODE})
307       install(FILES
308         ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
309         DESTINATION ${CMAKE_INSTALL_LIBDIR})
310     endif()
312     if(NOT WIN32)
313       IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
314         _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
315  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
316  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
317                 install(CODE ${PNG_SHARED_INSTALL_CODE})
318                 install(FILES
319  ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
320                 DESTINATION ${CMAKE_INSTALL_LIBDIR})
321       ELSE(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
322         _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
323            ${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
324            libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
325         install(CODE ${PNG_SHARED_INSTALL_CODE})
326         install(FILES
327            ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
328                 DESTINATION ${CMAKE_INSTALL_LIBDIR})
329       ENDIF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
330     endif()
331   endif()
333   if(PNG_STATIC)
334     install(TARGETS ${PNG_LIB_NAME_STATIC}
335         ${PNG_EXPORT_RULE}
336             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
337             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
338     if(NOT WIN32 OR CYGWIN)
339       IF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
340          _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
341 ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
342         ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
343         install(CODE ${PNG_STATIC_INSTALL_CODE})
344         install(FILES
345           ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
346              DESTINATION ${CMAKE_INSTALL_LIBDIR})
347       ELSE(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
348         _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
349            ${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
350            libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
351         install(CODE ${PNG_STATIC_INSTALL_CODE})
352         install(FILES
353           ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
354                      DESTINATION ${CMAKE_INSTALL_LIBDIR})
355       ENDIF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
356     endif()
357   endif()
358 endif()
360 if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
361   install(FILES ${libpng_public_hdrs}   DESTINATION include)
362   install(FILES ${libpng_public_hdrs}   DESTINATION include/${PNGLIB_NAME})
363 endif()
364 if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
365   install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
366   install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
367           DESTINATION bin)
368 endif()
369 if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
370   # Install man pages
371   if(NOT PNG_MAN_DIR)
372     set(PNG_MAN_DIR "share/man")
373   endif()
374   install(FILES libpng.3 libpngpf.3      DESTINATION ${PNG_MAN_DIR}/man3)
375   install(FILES png.5                    DESTINATION ${PNG_MAN_DIR}/man5)
376   # Install pkg-config files
377   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
378           DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
379   install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
380           DESTINATION bin)
381   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
382           DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
383   install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
384           DESTINATION bin)
385 endif()
387 # On versions of CMake that support it, create an export file CMake
388 # users can include() to import our targets
389 if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
390   install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
391 endif()
393 # what's with libpng-$VER%.txt and all the extra files?
396 # UNINSTALL
397 # do we need this?
400 # DIST
401 # do we need this?
403 # to create msvc import lib for mingw compiled shared lib
404 # pexports libpng.dll > libpng.def
405 # lib /def:libpng.def /machine:x86