summaryrefslogtreecommitdiff
path: root/scripts/CMakeLists.txt
blob: 9a430264d364401a12d98e58fa7c7c2ab98458a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
project(PNG)

# Copyright (C) 2007 Glenn Randers-Pehrson
# For conditions of distribution and use, see copyright notice in png.h

set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 0)
set(PNGLIB_RELEASE 25)
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})

# needed packages
find_package(ZLIB REQUIRED)
if(NOT WIN32)
 find_library(M_LIBRARY
     NAMES m
     PATHS /usr/lib /usr/local/lib
 )
 if(NOT M_LIBRARY)
   message(STATUS
     "math library 'libm' not found - floating point support disabled")
 endif(NOT M_LIBRARY)
else(NOT WIN32)
 # not needed on windows
 set(M_LIBRARY "")
endif(NOT WIN32)


# COMMAND LINE OPTIONS
option(PNG_SHARED "Build shared lib" YES)
option(PNG_STATIC "Build static lib" YES)
option(PNG_TESTS  "Build pngtest" YES)
option(PNG_NO_CONSOLE_IO "FIXME" YES)
option(PNG_NO_STDIO      "FIXME" YES)
option(PNG_DEBUG         "Build with debug output" YES)
option(PNGARG            "FIXME" YES)
#TODO:
# PNG_CONSOLE_IO_SUPPORTED

# maybe needs improving, but currently I don't know when we can enable what :)
set(png_asm_tmp "OFF")
if(NOT WIN32)
 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
 if(uname_executable)
   EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
   if("uname_output" MATCHES "^.*i[1-9]86.*$")
      set(png_asm_tmp "ON")
   else("uname_output" MATCHES "^.*i[1-9]86.*$")
      set(png_asm_tmp "OFF")
   endif("uname_output" MATCHES "^.*i[1-9]86.*$")
 endif(uname_executable)
endif(NOT WIN32)

option(PNG_MMX "Use MMX assembler code (x86 only)" ${png_asm_tmp})

# SET LIBNAME
# msvc does not append 'lib' - do it here to have consistent name
if(MSVC)
 set(PNG_LIB_NAME lib)
endif(MSVC)
set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})

# to distinguish between debug and release lib
set(CMAKE_DEBUG_POSTFIX "d")


# OUR SOURCES
set(libpng_sources
 png.h
 pngconf.h
 png.c
 pngerror.c
 pngget.c
 pngmem.c
 pngpread.c
 pngread.c
 pngrio.c
 pngrtran.c
 pngrutil.c
 pngset.c
 pngtrans.c
 pngwio.c
 pngwrite.c
 pngwtran.c
 pngwutil.c
)
set(pngtest_sources
       pngtest.c
)
# SOME NEEDED DEFINITIONS
add_definitions(-DZLIB_DLL)

if(MSVC)
 add_definitions(-DPNG_USE_PNGVCRD -DPNG_NO_MODULEDEF
   -D_CRT_SECURE_NO_DEPRECATE)
 set(libpng_sources ${libpng_sources}
         pngvcrd.c
 )
else(MSVC)
 add_definitions(-DPNG_USE_PNGGCCRD)
 set(libpng_sources ${libpng_sources}
         pnggccrd.c
 )
endif(MSVC)

if(NOT MSVC)
 if(NOT PNG_MMX)
   add_definitions(-DLIBPNG_NO_MMX)
   add_definitions(-DPNG_NO_MMX_CODE)
 endif(NOT PNG_MMX)
else(NOT MSVC)
 if(PNG_MMX)
 # maybe add this to pngconf.h ?
 add_definitions(-DPNG_MMX_CODE_SUPPORTED)
 endif(PNG_MMX)
endif(NOT MSVC)


if(PNG_CONSOLE_IO_SUPPORTED)
 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
endif(PNG_CONSOLE_IO_SUPPORTED)

if(PNG_NO_CONSOLE_IO)
 add_definitions(-DPNG_NO_CONSOLE_IO)
endif(PNG_NO_CONSOLE_IO)

if(PNG_NO_STDIO)
 add_definitions(-DPNG_NO_STDIO)
endif(PNG_NO_STDIO)

if(PNG_DEBUG)
 add_definitions(-DPNG_DEBUG)
endif(PNG_DEBUG)

if(NOT M_LIBRARY)
 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
endif(NOT M_LIBRARY)

# NOW BUILD OUR TARGET
include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})

if(PNG_SHARED)
 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
endif(PNG_SHARED)
if(PNG_STATIC)
# does not work without changing name
 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
endif(PNG_STATIC)

if(PNG_SHARED AND WIN32)
 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
endif(PNG_SHARED AND WIN32)

if(PNG_TESTS)
# does not work with msvc due to png_lib_ver issue
 add_executable(pngtest ${pngtest_sources})
 target_link_libraries(pngtest ${PNG_LIB_NAME})
#  add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
endif(PNG_TESTS)


# CREATE PKGCONFIG FILES
# we use the same files like ./configure, so we have to set its vars
set(prefix      ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
set(includedir  ${CMAKE_INSTALL_PREFIX}/include)

configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
  ${PNG_BINARY_DIR}/libpng.pc)
configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
  ${PNG_BINARY_DIR}/libpng-config)
configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
  ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
  ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)

# SET UP LINKS
set_target_properties(${PNG_LIB_NAME} PROPERTIES
#    VERSION 0.${PNGLIB_RELEASE}.1.0.25rc1
     VERSION 0.${PNGLIB_RELEASE}.0
     SOVERSION 0
     CLEAN_DIRECT_OUTPUT 1)
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
     OUTPUT_NAME ${PNG_LIB_NAME}
     CLEAN_DIRECT_OUTPUT 1)

# INSTALL
install_targets(/lib ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC})
install(FILES png.h pngconf.h         DESTINATION include)
install(FILES png.h pngconf.h         DESTINATION include/${PNGLIB_NAME})
install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
install(FILES png.5                           DESTINATION man/man5)
install(FILES ${PNG_BINARY_DIR}/libpng.pc     DESTINATION lib/pkgconfig)
install(FILES ${PNG_BINARY_DIR}/libpng-config      DESTINATION bin)
install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc  DESTINATION lib/pkgconfig)
install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)

# what's with libpng.txt and all the extra files?


# UNINSTALL
# do we need this?


# DIST
# do we need this?

# to create msvc import lib for mingw compiled shared lib
# pexports libpng.dll > libpng.def
# lib /def:libpng.def /machine:x86