• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2project(PNG)
3
4# Copyright (C) 2007 Glenn Randers-Pehrson
5
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10set(PNGLIB_MAJOR 1)
11set(PNGLIB_MINOR 2)
12set(PNGLIB_RELEASE 38)
13set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
14set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
15
16# needed packages
17find_package(ZLIB REQUIRED)
18if(NOT WIN32)
19 find_library(M_LIBRARY
20     NAMES m
21     PATHS /usr/lib /usr/local/lib
22 )
23 if(NOT M_LIBRARY)
24   message(STATUS
25     "math library 'libm' not found - floating point support disabled")
26 endif(NOT M_LIBRARY)
27else(NOT WIN32)
28 # not needed on windows
29 set(M_LIBRARY "")
30endif(NOT WIN32)
31
32
33# COMMAND LINE OPTIONS
34option(PNG_SHARED "Build shared lib" YES)
35option(PNG_STATIC "Build static lib" YES)
36if(MINGW)
37  option(PNG_TESTS  "Build pngtest" NO)
38else(MINGW)
39  option(PNG_TESTS  "Build pngtest" YES)
40endif(MINGW)
41option(PNG_NO_CONSOLE_IO "FIXME" YES)
42option(PNG_NO_STDIO      "FIXME" YES)
43option(PNG_DEBUG         "Build with debug output" YES)
44option(PNGARG            "FIXME" YES)
45#TODO:
46# PNG_CONSOLE_IO_SUPPORTED
47
48# maybe needs improving, but currently I don't know when we can enable what :)
49set(png_asm_tmp "OFF")
50if(NOT WIN32)
51 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
52 if(uname_executable)
53   EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
54   if("uname_output" MATCHES "^.*i[1-9]86.*$")
55      set(png_asm_tmp "ON")
56   else("uname_output" MATCHES "^.*i[1-9]86.*$")
57      set(png_asm_tmp "OFF")
58   endif("uname_output" MATCHES "^.*i[1-9]86.*$")
59 endif(uname_executable)
60else(NOT WIN32)
61 # this env var is normally only set on win64
62 SET(TEXT "ProgramFiles(x86)")
63 if("$ENV{${TEXT}}" STREQUAL "")
64  set(png_asm_tmp "ON")
65 endif("$ENV{${TEXT}}" STREQUAL "")
66endif(NOT WIN32)
67
68# SET LIBNAME
69# msvc does not append 'lib' - do it here to have consistent name
70if(MSVC)
71 set(PNG_LIB_NAME lib)
72endif(MSVC)
73set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})
74
75# to distinguish between debug and release lib
76set(CMAKE_DEBUG_POSTFIX "d")
77
78
79# OUR SOURCES
80set(libpng_sources
81 png.h
82 pngconf.h
83 png.c
84 pngerror.c
85 pngget.c
86 pngmem.c
87 pngpread.c
88 pngread.c
89 pngrio.c
90 pngrtran.c
91 pngrutil.c
92 pngset.c
93 pngtrans.c
94 pngwio.c
95 pngwrite.c
96 pngwtran.c
97 pngwutil.c
98)
99set(pngtest_sources
100       pngtest.c
101)
102# SOME NEEDED DEFINITIONS
103if(MSVC)
104  add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
105endif(MSVC)
106
107add_definitions(-DZLIB_DLL)
108
109add_definitions(-DLIBPNG_NO_MMX)
110add_definitions(-DPNG_NO_MMX_CODE)
111
112if(PNG_CONSOLE_IO_SUPPORTED)
113 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
114endif(PNG_CONSOLE_IO_SUPPORTED)
115
116if(PNG_NO_CONSOLE_IO)
117 add_definitions(-DPNG_NO_CONSOLE_IO)
118endif(PNG_NO_CONSOLE_IO)
119
120if(PNG_NO_STDIO)
121 add_definitions(-DPNG_NO_STDIO)
122endif(PNG_NO_STDIO)
123
124if(PNG_DEBUG)
125 add_definitions(-DPNG_DEBUG)
126endif(PNG_DEBUG)
127
128if(NOT M_LIBRARY AND NOT WIN32)
129 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
130endif(NOT M_LIBRARY AND NOT WIN32)
131
132# NOW BUILD OUR TARGET
133include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
134
135if(PNG_SHARED)
136 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
137 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
138endif(PNG_SHARED)
139if(PNG_STATIC)
140# does not work without changing name
141 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
142 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
143endif(PNG_STATIC)
144
145if(PNG_SHARED AND WIN32)
146 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
147endif(PNG_SHARED AND WIN32)
148
149if(PNG_TESTS)
150# does not work with msvc due to png_lib_ver issue
151 add_executable(pngtest ${pngtest_sources})
152 target_link_libraries(pngtest ${PNG_LIB_NAME})
153#  add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
154endif(PNG_TESTS)
155
156
157# CREATE PKGCONFIG FILES
158# we use the same files like ./configure, so we have to set its vars
159set(prefix      ${CMAKE_INSTALL_PREFIX})
160set(exec_prefix ${CMAKE_INSTALL_PREFIX})
161set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
162set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
163
164configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
165  ${PNG_BINARY_DIR}/libpng.pc)
166configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
167  ${PNG_BINARY_DIR}/libpng-config)
168configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
169  ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
170configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
171  ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
172
173# SET UP LINKS
174set_target_properties(${PNG_LIB_NAME} PROPERTIES
175#    VERSION 0.${PNGLIB_RELEASE}.1.2.38
176     VERSION 0.${PNGLIB_RELEASE}.0
177     SOVERSION 0
178     CLEAN_DIRECT_OUTPUT 1)
179if(NOT WIN32)
180  # that's uncool on win32 - it overwrites our static import lib...
181  set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
182     OUTPUT_NAME ${PNG_LIB_NAME}
183     CLEAN_DIRECT_OUTPUT 1)
184endif(NOT WIN32)
185# INSTALL
186install_targets(/lib ${PNG_LIB_NAME})
187if(PNG_STATIC)
188  install_targets(/lib ${PNG_LIB_NAME_STATIC})
189endif(PNG_STATIC)
190install(FILES png.h pngconf.h         DESTINATION include)
191install(FILES png.h pngconf.h         DESTINATION include/${PNGLIB_NAME})
192install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
193install(FILES png.5                           DESTINATION man/man5)
194install(FILES ${PNG_BINARY_DIR}/libpng.pc     DESTINATION lib/pkgconfig)
195install(FILES ${PNG_BINARY_DIR}/libpng-config      DESTINATION bin)
196install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc  DESTINATION lib/pkgconfig)
197install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
198
199# what's with libpng.txt and all the extra files?
200
201
202# UNINSTALL
203# do we need this?
204
205
206# DIST
207# do we need this?
208
209# to create msvc import lib for mingw compiled shared lib
210# pexports libpng.dll > libpng.def
211# lib /def:libpng.def /machine:x86
212
213