Home | History | Annotate | Download | only in libpng
      1 cmake_minimum_required(VERSION 2.4.3)
      2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
      3 
      4 if(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.")
     12 endif()
     13 
     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 2)
     25 set(PNGLIB_RELEASE 46)
     26 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
     27 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
     28 
     29 # needed packages
     30 find_package(ZLIB REQUIRED)
     31 include_directories(${ZLIB_INCLUDE_DIR})
     32 
     33 if(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()
     42 else()
     43   # not needed on windows
     44   set(M_LIBRARY "")
     45 endif()
     46 
     47 # COMMAND LINE OPTIONS
     48 if(DEFINED PNG_SHARED)
     49   option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
     50 else()
     51   option(PNG_SHARED "Build shared lib" ON)
     52 endif()
     53 if(DEFINED PNG_STATIC)
     54   option(PNG_STATIC "Build static lib" ${PNG_STATIC})
     55 else()
     56   option(PNG_STATIC "Build static lib" ON)
     57 endif()
     58 
     59 if(MINGW)
     60   option(PNG_TESTS  "Build pngtest" NO)
     61 else()
     62   option(PNG_TESTS  "Build pngtest" YES)
     63 endif()
     64 
     65 option(PNG_NO_CONSOLE_IO "FIXME" YES)
     66 option(PNG_NO_STDIO      "FIXME" YES)
     67 option(PNG_DEBUG         "Build with debug output" NO)
     68 option(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 :)
     73 set(png_asm_tmp "OFF")
     74 if(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)
     85 else()
     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 "")
     91 endif()
     92 
     93 # SET LIBNAME
     94 set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
     95 
     96 # to distinguish between debug and release lib
     97 set(CMAKE_DEBUG_POSTFIX "d")
     98 
     99 
    100 # OUR SOURCES
    101 set(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 )
    120 set(pngtest_sources
    121   pngtest.c
    122 )
    123 # SOME NEEDED DEFINITIONS
    124 
    125 add_definitions(-DPNG_CONFIGURE_LIBPNG)
    126 
    127 if(_AIX)
    128   add_definitions(-D_ALL_SOURCE)
    129 endif(_AIX)
    130 
    131 if(MSVC)
    132   add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
    133 endif(MSVC)
    134 
    135 if(PNG_SHARED OR  NOT MSVC)
    136   #if building msvc static this has NOT to be defined
    137   add_definitions(-DZLIB_DLL)
    138 endif()
    139 
    140 add_definitions(-DLIBPNG_NO_MMX)
    141 add_definitions(-DPNG_NO_MMX_CODE)
    142 
    143 
    144 if(PNG_CONSOLE_IO_SUPPORTED)
    145   add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
    146 endif()
    147 
    148 if(PNG_NO_CONSOLE_IO)
    149   add_definitions(-DPNG_NO_CONSOLE_IO)
    150 endif()
    151 
    152 if(PNG_NO_STDIO)
    153   add_definitions(-DPNG_NO_STDIO)
    154 endif()
    155 
    156 if(PNG_DEBUG)
    157   add_definitions(-DPNG_DEBUG)
    158 endif()
    159 
    160 if(NOT M_LIBRARY AND NOT WIN32)
    161   add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
    162 endif()
    163 
    164 # NOW BUILD OUR TARGET
    165 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
    166 
    167 if(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})
    174 endif()
    175 
    176 if(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()
    184 endif()
    185 
    186 
    187 if(PNG_SHARED AND WIN32)
    188   set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
    189 endif()
    190 
    191 if(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)
    196 endif()
    197 
    198 
    199 # CREATE PKGCONFIG FILES
    200 # we use the same files like ./configure, so we have to set its vars
    201 set(prefix      ${CMAKE_INSTALL_PREFIX})
    202 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
    203 set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
    204 set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
    205 
    206 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in
    207   ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
    208 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in
    209   ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
    210 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng.pc.in
    211   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc)
    212 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/libpng-config.in
    213   ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config)
    214 
    215 # SET UP LINKS
    216 if(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)
    222 endif()
    223 if(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()
    230 endif()
    231 
    232 # INSTALL
    233 if(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()
    245 endif()
    246 
    247 if(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})
    250 endif()
    251 if(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)
    255 endif()
    256 if(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)
    269 endif()
    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