4 # Copyright (C) 2007 Glenn Randers-Pehrson
5 # For conditions of distribution and use, see copyright notice in png.h
10 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
11 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
14 find_package(ZLIB REQUIRED)
16 find_library(M_LIBRARY
18 PATHS /usr/lib /usr/local/lib
22 "math library 'libm' not found - floating point support disabled")
25 # not needed on windows
30 # COMMAND LINE OPTIONS
31 option(PNG_SHARED "Build shared lib" YES)
32 option(PNG_STATIC "Build static lib" YES)
34 option(PNG_TESTS "Build pngtest" NO)
36 option(PNG_TESTS "Build pngtest" YES)
38 option(PNG_NO_CONSOLE_IO "FIXME" YES)
39 option(PNG_NO_STDIO "FIXME" YES)
40 option(PNG_DEBUG "Build with debug output" YES)
41 option(PNGARG "FIXME" YES)
43 # PNG_CONSOLE_IO_SUPPORTED
45 # maybe needs improving, but currently I don't know when we can enable what :)
46 set(png_asm_tmp "OFF")
48 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
50 EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
51 if("uname_output" MATCHES "^.*i[1-9]86.*$")
53 else("uname_output" MATCHES "^.*i[1-9]86.*$")
54 set(png_asm_tmp "OFF")
55 endif("uname_output" MATCHES "^.*i[1-9]86.*$")
56 endif(uname_executable)
58 # this env var is normally only set on win64
59 SET(TEXT "ProgramFiles(x86)")
60 if("$ENV{${TEXT}}" STREQUAL "")
62 endif("$ENV{${TEXT}}" STREQUAL "")
66 # msvc does not append 'lib' - do it here to have consistent name
70 set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})
72 # to distinguish between debug and release lib
73 set(CMAKE_DEBUG_POSTFIX "d")
99 # SOME NEEDED DEFINITIONS
101 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
104 add_definitions(-DZLIB_DLL)
106 add_definitions(-DLIBPNG_NO_MMX)
107 add_definitions(-DPNG_NO_MMX_CODE)
109 if(PNG_CONSOLE_IO_SUPPORTED)
110 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
111 endif(PNG_CONSOLE_IO_SUPPORTED)
113 if(PNG_NO_CONSOLE_IO)
114 add_definitions(-DPNG_NO_CONSOLE_IO)
115 endif(PNG_NO_CONSOLE_IO)
118 add_definitions(-DPNG_NO_STDIO)
122 add_definitions(-DPNG_DEBUG)
125 if(NOT M_LIBRARY AND NOT WIN32)
126 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
127 endif(NOT M_LIBRARY AND NOT WIN32)
129 # NOW BUILD OUR TARGET
130 include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
133 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
134 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
137 # does not work without changing name
138 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
139 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
142 if(PNG_SHARED AND WIN32)
143 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
144 endif(PNG_SHARED AND WIN32)
147 # does not work with msvc due to png_lib_ver issue
148 add_executable(pngtest ${pngtest_sources})
149 target_link_libraries(pngtest ${PNG_LIB_NAME})
150 # add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
154 # CREATE PKGCONFIG FILES
155 # we use the same files like ./configure, so we have to set its vars
156 set(prefix ${CMAKE_INSTALL_PREFIX})
157 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
158 set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
159 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
161 configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
162 ${PNG_BINARY_DIR}/libpng.pc)
163 configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
164 ${PNG_BINARY_DIR}/libpng-config)
165 configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
166 ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
167 configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
168 ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
171 set_target_properties(${PNG_LIB_NAME} PROPERTIES
172 # VERSION 0.${PNGLIB_RELEASE}.1.2.34
173 VERSION 0.${PNGLIB_RELEASE}.0
175 CLEAN_DIRECT_OUTPUT 1)
177 # that's uncool on win32 - it overwrites our static import lib...
178 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
179 OUTPUT_NAME ${PNG_LIB_NAME}
180 CLEAN_DIRECT_OUTPUT 1)
183 install_targets(/lib ${PNG_LIB_NAME})
185 install_targets(/lib ${PNG_LIB_NAME_STATIC})
188 install(FILES png.h pngconf.h DESTINATION include)
189 install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME})
190 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3)
191 install(FILES png.5 DESTINATION man/man5)
192 install(FILES ${PNG_BINARY_DIR}/libpng.pc DESTINATION lib/pkgconfig)
193 install(FILES ${PNG_BINARY_DIR}/libpng-config DESTINATION bin)
194 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc DESTINATION lib/pkgconfig)
195 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
197 # what's with libpng.txt and all the extra files?
207 # to create msvc import lib for mingw compiled shared lib
208 # pexports libpng.dll > libpng.def
209 # lib /def:libpng.def /machine:x86