CMakeLists.txt 7.3 KB
Newer Older
1
cmake_minimum_required(VERSION 2.4.3)
2 3
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

4
if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
5 6 7 8 9 10 11
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING 
      "Choose the type of build, options are:
         None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
         Debug
         Release
         RelWithDebInfo
         MinSizeRel.")
12 13
endif()

14
project(libpng C)
15
enable_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

23
set(PNGLIB_MAJOR 1)
24
set(PNGLIB_MINOR 5)
25 26 27
set(PNGLIB_RELEASE 0)
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
28 29 30

# needed packages
find_package(ZLIB REQUIRED)
31 32
include_directories(${ZLIB_INCLUDE_DIR})

33
if(NOT WIN32)
34 35 36 37 38 39 40 41
  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()
42
else()
43 44
  # not needed on windows
  set(M_LIBRARY "")
45
endif()
46

47
# COMMAND LINE OPTIONS
48 49 50 51 52 53 54 55 56 57 58
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()

59 60
if(MINGW)
  option(PNG_TESTS  "Build pngtest" NO)
61
else()
62
  option(PNG_TESTS  "Build pngtest" YES)
63
endif()
64

65 66
option(PNG_NO_CONSOLE_IO "FIXME" YES)
option(PNG_NO_STDIO      "FIXME" YES)
67
option(PNG_DEBUG         "Build with debug output" NO)
68
option(PNGARG            "FIXME" YES)
69 70 71
#TODO:
# PNG_CONSOLE_IO_SUPPORTED

72
# maybe needs improving, but currently I don't know when we can enable what :)
73 74
set(png_asm_tmp "OFF")
if(NOT WIN32)
75 76 77 78 79
  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.*$")
80
      set(png_asm_tmp "ON")
81
    else("uname_output" MATCHES "^.*i[1-9]86.*$")
82
      set(png_asm_tmp "OFF")
83 84
    endif("uname_output" MATCHES "^.*i[1-9]86.*$")
  endif(uname_executable)
85
else()
86 87 88 89 90
  # 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 "")
91
endif()
92

93
# SET LIBNAME
94
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
95 96 97 98 99

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


100
# OUR SOURCES
101
set(libpng_sources
102 103
  png.h
  pngconf.h
104
  pngpriv.h
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  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
120 121
)
set(pngtest_sources
122
  pngtest.c
123
)
124
# SOME NEEDED DEFINITIONS
125

126
if(MSVC)
127
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
128 129
endif(MSVC)

130
if(PNG_SHARED OR  NOT MSVC)
131 132
  #if building msvc static this has NOT to be defined
  add_definitions(-DZLIB_DLL)
133
endif()
134

135

136
if(PNG_CONSOLE_IO_SUPPORTED)
137
  add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
138
endif()
139 140

if(PNG_NO_CONSOLE_IO)
141
  add_definitions(-DPNG_NO_CONSOLE_IO)
142
endif()
143 144

if(PNG_NO_STDIO)
145
  add_definitions(-DPNG_NO_STDIO)
146
endif()
147 148

if(PNG_DEBUG)
149
  add_definitions(-DPNG_DEBUG=1)
150
endif()
151

152
if(NOT M_LIBRARY AND NOT WIN32)
153
  add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
154
endif()
155 156

# NOW BUILD OUR TARGET
157
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
158 159

if(PNG_SHARED)
160 161 162 163 164 165
  add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
  if(MSVC)
    # msvc does not append 'lib' - do it here to have consistent name
    set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
  endif()
  target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
166 167
endif()

168 169
if(PNG_STATIC)
# does not work without changing name
170 171 172 173 174 175
  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
  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()
176 177
endif()

178 179

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

183
if(PNG_TESTS AND PNG_SHARED)
184 185 186 187
  # 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 pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
188
endif()
189 190


191 192 193 194 195 196 197
# 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)

198 199 200 201 202 203 204 205
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
  ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
  ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
  ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config)
206 207

# SET UP LINKS
208 209
if(PNG_SHARED)
  set_target_properties(${PNG_LIB_NAME} PROPERTIES
210
#   VERSION 15.${PNGLIB_RELEASE}.1.5.0beta43
211 212
    VERSION 15.${PNGLIB_RELEASE}.0
    SOVERSION 15
213
    CLEAN_DIRECT_OUTPUT 1)
214
endif()
215
if(PNG_STATIC)
216 217 218
  if(NOT WIN32)
    # that's uncool on win32 - it overwrites our static import lib...
    set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
219 220
      OUTPUT_NAME ${PNG_LIB_NAME}
      CLEAN_DIRECT_OUTPUT 1)
221 222 223 224 225
  endif()
endif()

# INSTALL
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
226 227
  if(PNG_SHARED)
    install(TARGETS ${PNG_LIB_NAME}
228 229 230
            RUNTIME DESTINATION bin
            LIBRARY DESTINATION lib
            ARCHIVE DESTINATION lib)
231 232 233
  endif()
  if(PNG_STATIC)
    install(TARGETS ${PNG_LIB_NAME_STATIC}
234 235
            LIBRARY DESTINATION lib
            ARCHIVE DESTINATION lib)
236
  endif()
237 238 239
endif()

if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
240 241
  install(FILES png.h pngconf.h         DESTINATION include)
  install(FILES png.h pngconf.h         DESTINATION include/${PNGLIB_NAME})
242 243
endif()
if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
244 245 246
  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
  install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
          DESTINATION bin)
247 248
endif()
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
249 250 251 252 253 254 255 256 257 258 259 260
  # Install man pages
  install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
  install(FILES png.5                           DESTINATION man/man5)
  # Install pkg-config files
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
          DESTINATION lib/pkgconfig)
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
          DESTINATION bin)
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
          DESTINATION lib/pkgconfig)
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
          DESTINATION bin)
261
endif()
262

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


266
# UNINSTALL
267 268 269
# do we need this?


270
# DIST
271 272 273 274 275
# 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
276