blob: 1b39b20f90a32c35ebd5860e59e842d9cb0127b9 [file] [log] [blame]
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05001project(PNG)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -06002
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05003# Copyright (C) 2007 Glenn Randers-Pehrson
4# For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -06005
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -05006set(PNGLIB_MAJOR 1)
7set(PNGLIB_MINOR 4)
8set(PNGLIB_RELEASE 0)
9set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
10set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060011
12# needed packages
13find_package(ZLIB REQUIRED)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050014if(NOT WIN32)
15 find_library(M_LIBRARY
16 NAMES m
17 PATHS /usr/lib /usr/local/lib
18 )
19 if(NOT M_LIBRARY)
20 message(STATUS
21 "math library 'libm' not found - floating point support disabled")
22 endif(NOT M_LIBRARY)
23else(NOT WIN32)
24 # not needed on windows
25 set(M_LIBRARY "")
26endif(NOT WIN32)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060027
28
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050029# COMMAND LINE OPTIONS
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060030option(PNG_SHARED "Build shared lib" YES)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050031option(PNG_STATIC "Build static lib" YES)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060032option(PNG_TESTS "Build pngtest" YES)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050033option(PNG_NO_CONSOLE_IO "FIXME" YES)
34option(PNG_NO_STDIO "FIXME" YES)
35option(PNG_DEBUG "Build with debug output" YES)
36option(PNGARG "FIXME" YES)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060037#TODO:
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060038# PNG_CONSOLE_IO_SUPPORTED
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060039
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050040# maybe needs improving, but currently I don't know when we can enable what :)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060041set(png_asm_tmp "OFF")
42if(NOT WIN32)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050043 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
44 if(uname_executable)
45 EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
46 if("uname_output" MATCHES "^.*i[1-9]86.*$")
47 set(png_asm_tmp "ON")
48 else("uname_output" MATCHES "^.*i[1-9]86.*$")
49 set(png_asm_tmp "OFF")
50 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
51 endif(uname_executable)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060052endif(NOT WIN32)
53
54option(PNG_MMX "Use MMX assembler code (x86 only)" ${png_asm_tmp})
55
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050056# SET LIBNAME
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060057# msvc does not append 'lib' - do it here to have consistent name
58if(MSVC)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050059 set(PNG_LIB_NAME lib)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060060endif(MSVC)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050061set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060062
63# to distinguish between debug and release lib
64set(CMAKE_DEBUG_POSTFIX "d")
65
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060066
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050067# OUR SOURCES
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060068set(libpng_sources
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050069 png.h
70 pngconf.h
71 png.c
72 pngerror.c
73 pngget.c
74 pngmem.c
75 pngpread.c
76 pngread.c
77 pngrio.c
78 pngrtran.c
79 pngrutil.c
80 pngset.c
81 pngtrans.c
82 pngwio.c
83 pngwrite.c
84 pngwtran.c
85 pngwutil.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060086)
87set(pngtest_sources
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050088 pngtest.c
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060089)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050090# SOME NEEDED DEFINITIONS
91add_definitions(-DZLIB_DLL)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060092
93if(MSVC)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -050094 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
95 FILE(WRITE pngdefs.h "#define PNG_USE_PNGVCRD\n")
96 set(libpng_sources ${libpng_sources}
97 pngvcrd.c
98 )
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -060099else(MSVC)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500100 FILE(WRITE pngdefs.h "#define PNG_USE_PNGGCCRD\n")
101 set(libpng_sources ${libpng_sources}
102 pnggccrd.c
103 )
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600104endif(MSVC)
105
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500106if(NOT MSVC)
107 if(NOT PNG_MMX)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600108 FILE(APPEND pngdefs.h "#define PNG_NO_MMX_CODE\n")
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500109 endif(NOT PNG_MMX)
110else(NOT MSVC)
111 if(PNG_MMX)
112 # maybe add this to pngconf.h ?
113 FILE(APPEND pngdefs.h "#define PNG_MMX_MMX_CODE_SUPPORTED\n")
114 endif(PNG_MMX)
115endif(NOT MSVC)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600116
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600117
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500118if(PNG_CONSOLE_IO_SUPPORTED)
119 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
120endif(PNG_CONSOLE_IO_SUPPORTED)
121
122if(PNG_NO_CONSOLE_IO)
123 add_definitions(-DPNG_NO_CONSOLE_IO)
124endif(PNG_NO_CONSOLE_IO)
125
126if(PNG_NO_STDIO)
127 add_definitions(-DPNG_NO_STDIO)
128endif(PNG_NO_STDIO)
129
130if(PNG_DEBUG)
131 add_definitions(-DPNG_DEBUG)
132endif(PNG_DEBUG)
133
134if(NOT M_LIBRARY)
135 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
136endif(NOT M_LIBRARY)
137
138# NOW BUILD OUR TARGET
139include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600140
141if(PNG_SHARED)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500142 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
143 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600144endif(PNG_SHARED)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500145if(PNG_STATIC)
146# does not work without changing name
147 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
148 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
149endif(PNG_STATIC)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600150
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600151if(PNG_SHARED AND WIN32)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500152 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600153endif(PNG_SHARED AND WIN32)
154
155if(PNG_TESTS)
156# does not work with msvc due to png_lib_ver issue
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500157 add_executable(pngtest ${pngtest_sources})
158 target_link_libraries(pngtest ${PNG_LIB_NAME})
159# add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600160endif(PNG_TESTS)
161
162
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500163# CREATE PKGCONFIG FILES
164# we use the same files like ./configure, so we have to set its vars
165set(prefix ${CMAKE_INSTALL_PREFIX})
166set(exec_prefix ${CMAKE_INSTALL_PREFIX})
167set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
168set(includedir ${CMAKE_INSTALL_PREFIX}/include)
169
170configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
171 ${PNG_BINARY_DIR}/libpng.pc)
172configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
173 ${PNG_BINARY_DIR}/libpng-config)
174configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
175 ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
176configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
177 ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
178
179# SET UP LINKS
180set_target_properties(${PNG_LIB_NAME} PROPERTIES
Glenn Randers-Pehrson glennrp@comcast.net92d95342009-05-02 15:12:50 -0500181# VERSION 0.${PNGLIB_RELEASE}.1.4.0beta57
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500182 VERSION 0.${PNGLIB_RELEASE}.0
183 SOVERSION 0
184 CLEAN_DIRECT_OUTPUT 1)
185set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
186 OUTPUT_NAME ${PNG_LIB_NAME}
187 CLEAN_DIRECT_OUTPUT 1)
188
189# INSTALL
190install_targets(/lib ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC})
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600191install(FILES png.h pngconf.h pngpriv.h pngdefs.h DESTINATION include)
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500192install(FILES png.h pngconf.h pngpriv.h pngdefs.h DESTINATION include/${PNGLIB_NAME})
193install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
194install(FILES png.5 DESTINATION man/man5)
195install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig)
196install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin)
197install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig)
198install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
199
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600200# what's with libpng.txt and all the extra files?
201
202
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500203# UNINSTALL
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600204# do we need this?
205
206
Glenn Randers-Pehrsona7dbcba2007-05-15 16:16:34 -0500207# DIST
Glenn Randers-Pehrson7edd4582006-12-07 19:16:44 -0600208# do we need this?
209
210# to create msvc import lib for mingw compiled shared lib
211# pexports libpng.dll > libpng.def
212# lib /def:libpng.def /machine:x86