1cmake_minimum_required(VERSION 2.4.3) 2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) 3 4if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE) 5 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING 6 "Choose the type of build, options are: 7 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) 8 Debug 9 Release 10 RelWithDebInfo 11 MinSizeRel.") 12endif() 13 14project(libpng C) 15enable_testing() 16 17# Copyright (C) 2007-2010 Glenn Randers-Pehrson 18 19# This code is released under the libpng license. 20# For conditions of distribution and use, see the disclaimer 21# and license in png.h 22 23set(PNGLIB_MAJOR 1) 24set(PNGLIB_MINOR 2) 25set(PNGLIB_RELEASE 46) 26set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) 27set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) 28 29# needed packages 30find_package(ZLIB REQUIRED) 31include_directories(${ZLIB_INCLUDE_DIR}) 32 33if(NOT WIN32) 34 find_library(M_LIBRARY 35 NAMES m 36 PATHS /usr/lib /usr/local/lib 37 ) 38 if(NOT M_LIBRARY) 39 message(STATUS 40 "math library 'libm' not found - floating point support disabled") 41 endif() 42else() 43 # not needed on windows 44 set(M_LIBRARY "") 45endif() 46 47# COMMAND LINE OPTIONS 48if(DEFINED PNG_SHARED) 49 option(PNG_SHARED "Build shared lib" ${PNG_SHARED}) 50else() 51 option(PNG_SHARED "Build shared lib" ON) 52endif() 53if(DEFINED PNG_STATIC) 54 option(PNG_STATIC "Build static lib" ${PNG_STATIC}) 55else() 56 option(PNG_STATIC "Build static lib" ON) 57endif() 58 59if(MINGW) 60 option(PNG_TESTS "Build pngtest" NO) 61else() 62 option(PNG_TESTS "Build pngtest" YES) 63endif() 64 65option(PNG_NO_CONSOLE_IO "FIXME" YES) 66option(PNG_NO_STDIO "FIXME" YES) 67option(PNG_DEBUG "Build with debug output" NO) 68option(PNGARG "FIXME" YES) 69#TODO: 70# PNG_CONSOLE_IO_SUPPORTED 71 72# maybe needs improving, but currently I don't know when we can enable what :) 73set(png_asm_tmp "OFF") 74if(NOT WIN32) 75 find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin) 76 if(uname_executable) 77 exec_program(${uname_executable} 78 ARGS --machine OUTPUT_VARIABLE uname_output) 79 if("uname_output" MATCHES "^.*i[1-9]86.*$") 80 set(png_asm_tmp "ON") 81 else("uname_output" MATCHES "^.*i[1-9]86.*$") 82 set(png_asm_tmp "OFF") 83 endif("uname_output" MATCHES "^.*i[1-9]86.*$") 84 endif(uname_executable) 85else() 86 # this env var is normally only set on win64 87 set(TEXT "ProgramFiles(x86)") 88 if("$ENV{${TEXT}}" STREQUAL "") 89 set(png_asm_tmp "ON") 90 endif("$ENV{${TEXT}}" STREQUAL "") 91endif() 92 93# SET LIBNAME 94set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) 95 96# to distinguish between debug and release lib 97set(CMAKE_DEBUG_POSTFIX "d") 98 99 100# OUR SOURCES 101set(libpng_sources 102 png.h 103 pngconf.h 104 png.c 105 pngerror.c 106 pngget.c 107 pngmem.c 108 pngpread.c 109 pngread.c 110 pngrio.c 111 pngrtran.c 112 pngrutil.c 113 pngset.c 114 pngtrans.c 115 pngwio.c 116 pngwrite.c 117 pngwtran.c 118 pngwutil.c 119) 120set(pngtest_sources 121 pngtest.c 122) 123# SOME NEEDED DEFINITIONS 124 125add_definitions(-DPNG_CONFIGURE_LIBPNG) 126 127if(_AIX) 128 add_definitions(-D_ALL_SOURCE) 129endif(_AIX) 130 131if(MSVC) 132 add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE) 133endif(MSVC) 134 135if(PNG_SHARED OR NOT MSVC) 136 #if building msvc static this has NOT to be defined 137 add_definitions(-DZLIB_DLL) 138endif() 139 140add_definitions(-DLIBPNG_NO_MMX) 141add_definitions(-DPNG_NO_MMX_CODE) 142 143 144if(PNG_CONSOLE_IO_SUPPORTED) 145 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED) 146endif() 147 148if(PNG_NO_CONSOLE_IO) 149 add_definitions(-DPNG_NO_CONSOLE_IO) 150endif() 151 152if(PNG_NO_STDIO) 153 add_definitions(-DPNG_NO_STDIO) 154endif() 155 156if(PNG_DEBUG) 157 add_definitions(-DPNG_DEBUG) 158endif() 159 160if(NOT M_LIBRARY AND NOT WIN32) 161 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED) 162endif() 163 164# NOW BUILD OUR TARGET 165include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) 166 167if(PNG_SHARED) 168 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources}) 169 if(MSVC) 170 # msvc does not append 'lib' - do it here to have consistent name 171 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib") 172 endif() 173 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY}) 174endif() 175 176if(PNG_STATIC) 177# does not work without changing name 178 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) 179 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) 180 if(MSVC) 181 # msvc does not append 'lib' - do it here to have consistent name 182 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib") 183 endif() 184endif() 185 186 187if(PNG_SHARED AND WIN32) 188 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) 189endif() 190 191if(PNG_TESTS AND PNG_SHARED) 192 # does not work with msvc due to png_lib_ver issue 193 add_executable(pngtest ${pngtest_sources}) 194 target_link_libraries(pngtest ${PNG_LIB_NAME}) 195 add_test(pngtest pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png) 196endif() 197 198 199# CREATE PKGCONFIG FILES 200# we use the same files like ./configure, so we have to set its vars 201set(prefix ${CMAKE_INSTALL_PREFIX}) 202set(exec_prefix ${CMAKE_INSTALL_PREFIX}) 203set(libdir ${CMAKE_INSTALL_PREFIX}/lib) 204set(includedir ${CMAKE_INSTALL_PREFIX}/include) 205 206configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in 207 ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc) 208configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in 209 ${CMAKE_CURRENT_BINARY_DIR}/libpng-config) 210configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in 211 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc) 212configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in 213 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config) 214 215# SET UP LINKS 216if(PNG_SHARED) 217 set_target_properties(${PNG_LIB_NAME} PROPERTIES 218# VERSION 0.${PNGLIB_RELEASE}.1.2.46 219 VERSION 0.${PNGLIB_RELEASE}.0 220 SOVERSION 0 221 CLEAN_DIRECT_OUTPUT 1) 222endif() 223if(PNG_STATIC) 224 if(NOT WIN32) 225 # that's uncool on win32 - it overwrites our static import lib... 226 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES 227 OUTPUT_NAME ${PNG_LIB_NAME} 228 CLEAN_DIRECT_OUTPUT 1) 229 endif() 230endif() 231 232# INSTALL 233if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) 234 if(PNG_SHARED) 235 install(TARGETS ${PNG_LIB_NAME} 236 RUNTIME DESTINATION bin 237 LIBRARY DESTINATION lib 238 ARCHIVE DESTINATION lib) 239 endif() 240 if(PNG_STATIC) 241 install(TARGETS ${PNG_LIB_NAME_STATIC} 242 LIBRARY DESTINATION lib 243 ARCHIVE DESTINATION lib) 244 endif() 245endif() 246 247if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) 248 install(FILES png.h pngconf.h DESTINATION include) 249 install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME}) 250endif() 251if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL ) 252 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) 253 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config 254 DESTINATION bin) 255endif() 256if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) 257 # Install man pages 258 install(FILES libpng.3 libpngpf.3 DESTINATION man/man3) 259 install(FILES png.5 DESTINATION man/man5) 260 # Install pkg-config files 261 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc 262 DESTINATION lib/pkgconfig) 263 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config 264 DESTINATION bin) 265 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc 266 DESTINATION lib/pkgconfig) 267 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config 268 DESTINATION bin) 269endif() 270 271# what's with libpng.txt and all the extra files? 272 273 274# UNINSTALL 275# do we need this? 276 277 278# DIST 279# do we need this? 280 281# to create msvc import lib for mingw compiled shared lib 282# pexports libpng.dll > libpng.def 283# lib /def:libpng.def /machine:x86 284 285