CMakeLists.txt 6.5 KB
Newer Older
1 2
project(PNG C)
cmake_minimum_required(VERSION 2.4.3)
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

10 11 12 13 14
set(PNGLIB_MAJOR 1)
set(PNGLIB_MINOR 4)
set(PNGLIB_RELEASE 0)
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
15

16 17
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

18 19
# needed packages
find_package(ZLIB REQUIRED)
20 21
include_directories(${ZLIB_INCLUDE_DIR})

22 23 24 25 26 27 28 29
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")
30 31
 endif()
else()
32 33
 # not needed on windows
 set(M_LIBRARY "")
34
endif()
35

36
# COMMAND LINE OPTIONS
37 38 39 40 41 42 43 44 45 46 47
if(DEFINED PNG_SHARED)
  option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
else()
  option(PNG_SHARED "Build shared lib" ON)
endif()
if(DEFINED PNG_STATIC)
  option(PNG_STATIC "Build static lib" ${PNG_STATIC})
else()
  option(PNG_STATIC "Build static lib" ON)
endif()

48 49 50 51 52
if(MINGW)
  option(PNG_TESTS  "Build pngtest" NO)
else(MINGW)
  option(PNG_TESTS  "Build pngtest" YES)
endif(MINGW)
53

54 55
option(PNG_NO_CONSOLE_IO "FIXME" YES)
option(PNG_NO_STDIO      "FIXME" YES)
56
option(PNG_DEBUG         "Build with debug output" NO)
57
option(PNGARG            "FIXME" YES)
58 59 60
#TODO:
# PNG_CONSOLE_IO_SUPPORTED

61
# maybe needs improving, but currently I don't know when we can enable what :)
62 63
set(png_asm_tmp "OFF")
if(NOT WIN32)
64 65 66 67 68 69 70 71 72
 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)
73
else()
74 75 76 77 78
 # this env var is normally only set on win64
 SET(TEXT "ProgramFiles(x86)")
 if("$ENV{${TEXT}}" STREQUAL "")
  set(png_asm_tmp "ON")
 endif("$ENV{${TEXT}}" STREQUAL "")
79
endif()
80

81
# SET LIBNAME
82
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
83 84 85 86 87

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


88
# OUR SOURCES
89
set(libpng_sources
90 91
 png.h
 pngconf.h
92
 pngpriv.h
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
 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
108 109
)
set(pngtest_sources
110
       pngtest.c
111
)
112
# SOME NEEDED DEFINITIONS
113
if(MSVC)
114
  add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
115 116
endif(MSVC)

117 118 119 120
if(PNG_SHARED OR  NOT MSVC)
	#if building msvc static this has NOT do be defined
	add_definitions(-DZLIB_DLL)
endif()
121

122 123
if(PNG_CONSOLE_IO_SUPPORTED)
 add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
124
endif()
125 126 127

if(PNG_NO_CONSOLE_IO)
 add_definitions(-DPNG_NO_CONSOLE_IO)
128
endif()
129 130 131

if(PNG_NO_STDIO)
 add_definitions(-DPNG_NO_STDIO)
132
endif()
133 134 135

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

138
if(NOT M_LIBRARY AND NOT WIN32)
139
 add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
140
endif()
141 142 143

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

if(PNG_SHARED)
146
 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
147 148 149 150
 if(MSVC)
   # msvc does not append 'lib' - do it here to have consistent name
   set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
 endif()
151
 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
152 153
endif()

154 155 156 157
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})
158 159 160 161 162 163
 if(MSVC)
   # msvc does not append 'lib' - do it here to have consistent name
   set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
 endif()
endif()

164 165

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

169
if(PNG_TESTS AND PNG_SHARED)
170
# does not work with msvc due to png_lib_ver issue
171 172 173
 add_executable(pngtest ${pngtest_sources})
 target_link_libraries(pngtest ${PNG_LIB_NAME})
#  add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
174
endif()
175 176


177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
# 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
194 195
if(PNG_SHARED)
  set_target_properties(${PNG_LIB_NAME} PROPERTIES
196
#    VERSION 14.${PNGLIB_RELEASE}.1.4.0beta89
197 198
     VERSION 14.${PNGLIB_RELEASE}.0
     SOVERSION 14
199
     CLEAN_DIRECT_OUTPUT 1)
200
endif()
201
if(PNG_STATIC)
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
  if(NOT WIN32)
    # that's uncool on win32 - it overwrites our static import lib...
    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
       OUTPUT_NAME ${PNG_LIB_NAME}
       CLEAN_DIRECT_OUTPUT 1)
  endif()
endif()

# INSTALL
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
    if(PNG_SHARED)
        install(TARGETS ${PNG_LIB_NAME}
            RUNTIME DESTINATION bin
            LIBRARY DESTINATION lib
            ARCHIVE DESTINATION lib)
    endif()
    if(PNG_STATIC)
        install(TARGETS ${PNG_LIB_NAME_STATIC}
            LIBRARY DESTINATION lib
            ARCHIVE DESTINATION lib)
    endif()
endif()

if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
226 227
install(FILES png.h pngconf.h pngpriv.h  DESTINATION include)
install(FILES png.h pngconf.h pngpriv.h  DESTINATION include/${PNGLIB_NAME})
228 229 230 231 232 233 234 235 236
endif()
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
    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)
endif()
237

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


241
# UNINSTALL
242 243 244
# do we need this?


245
# DIST
246 247 248 249 250
# 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
251