Home | History | Annotate | Download | only in scripts
      1 
      2 project(PNG)
      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 set(PNGLIB_MAJOR 1)
     11 set(PNGLIB_MINOR 2)
     12 set(PNGLIB_RELEASE 38)
     13 set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
     14 set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
     15 
     16 # needed packages
     17 find_package(ZLIB REQUIRED)
     18 if(NOT WIN32)
     19  find_library(M_LIBRARY
     20      NAMES m
     21      PATHS /usr/lib /usr/local/lib
     22  )
     23  if(NOT M_LIBRARY)
     24    message(STATUS
     25      "math library 'libm' not found - floating point support disabled")
     26  endif(NOT M_LIBRARY)
     27 else(NOT WIN32)
     28  # not needed on windows
     29  set(M_LIBRARY "")
     30 endif(NOT WIN32)
     31 
     32 
     33 # COMMAND LINE OPTIONS
     34 option(PNG_SHARED "Build shared lib" YES)
     35 option(PNG_STATIC "Build static lib" YES)
     36 if(MINGW)
     37   option(PNG_TESTS  "Build pngtest" NO)
     38 else(MINGW)
     39   option(PNG_TESTS  "Build pngtest" YES)
     40 endif(MINGW)
     41 option(PNG_NO_CONSOLE_IO "FIXME" YES)
     42 option(PNG_NO_STDIO      "FIXME" YES)
     43 option(PNG_DEBUG         "Build with debug output" YES)
     44 option(PNGARG            "FIXME" YES)
     45 #TODO:
     46 # PNG_CONSOLE_IO_SUPPORTED
     47 
     48 # maybe needs improving, but currently I don't know when we can enable what :)
     49 set(png_asm_tmp "OFF")
     50 if(NOT WIN32)
     51  find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
     52  if(uname_executable)
     53    EXEC_PROGRAM(${uname_executable} ARGS --machine OUTPUT_VARIABLE uname_output)
     54    if("uname_output" MATCHES "^.*i[1-9]86.*$")
     55       set(png_asm_tmp "ON")
     56    else("uname_output" MATCHES "^.*i[1-9]86.*$")
     57       set(png_asm_tmp "OFF")
     58    endif("uname_output" MATCHES "^.*i[1-9]86.*$")
     59  endif(uname_executable)
     60 else(NOT WIN32)
     61  # this env var is normally only set on win64
     62  SET(TEXT "ProgramFiles(x86)")
     63  if("$ENV{${TEXT}}" STREQUAL "")
     64   set(png_asm_tmp "ON")
     65  endif("$ENV{${TEXT}}" STREQUAL "")
     66 endif(NOT WIN32)
     67 
     68 # SET LIBNAME
     69 # msvc does not append 'lib' - do it here to have consistent name
     70 if(MSVC)
     71  set(PNG_LIB_NAME lib)
     72 endif(MSVC)
     73 set(PNG_LIB_NAME ${PNG_LIB_NAME}png${PNGLIB_MAJOR}${PNGLIB_MINOR})
     74 
     75 # to distinguish between debug and release lib
     76 set(CMAKE_DEBUG_POSTFIX "d")
     77 
     78 
     79 # OUR SOURCES
     80 set(libpng_sources
     81  png.h
     82  pngconf.h
     83  png.c
     84  pngerror.c
     85  pngget.c
     86  pngmem.c
     87  pngpread.c
     88  pngread.c
     89  pngrio.c
     90  pngrtran.c
     91  pngrutil.c
     92  pngset.c
     93  pngtrans.c
     94  pngwio.c
     95  pngwrite.c
     96  pngwtran.c
     97  pngwutil.c
     98 )
     99 set(pngtest_sources
    100        pngtest.c
    101 )
    102 # SOME NEEDED DEFINITIONS
    103 if(MSVC)
    104   add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
    105 endif(MSVC)
    106 
    107 add_definitions(-DZLIB_DLL)
    108 
    109 add_definitions(-DLIBPNG_NO_MMX)
    110 add_definitions(-DPNG_NO_MMX_CODE)
    111 
    112 if(PNG_CONSOLE_IO_SUPPORTED)
    113  add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
    114 endif(PNG_CONSOLE_IO_SUPPORTED)
    115 
    116 if(PNG_NO_CONSOLE_IO)
    117  add_definitions(-DPNG_NO_CONSOLE_IO)
    118 endif(PNG_NO_CONSOLE_IO)
    119 
    120 if(PNG_NO_STDIO)
    121  add_definitions(-DPNG_NO_STDIO)
    122 endif(PNG_NO_STDIO)
    123 
    124 if(PNG_DEBUG)
    125  add_definitions(-DPNG_DEBUG)
    126 endif(PNG_DEBUG)
    127 
    128 if(NOT M_LIBRARY AND NOT WIN32)
    129  add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
    130 endif(NOT M_LIBRARY AND NOT WIN32)
    131 
    132 # NOW BUILD OUR TARGET
    133 include_directories(${PNG_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
    134 
    135 if(PNG_SHARED)
    136  add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
    137  target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
    138 endif(PNG_SHARED)
    139 if(PNG_STATIC)
    140 # does not work without changing name
    141  set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
    142  add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
    143 endif(PNG_STATIC)
    144 
    145 if(PNG_SHARED AND WIN32)
    146  set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
    147 endif(PNG_SHARED AND WIN32)
    148 
    149 if(PNG_TESTS)
    150 # does not work with msvc due to png_lib_ver issue
    151  add_executable(pngtest ${pngtest_sources})
    152  target_link_libraries(pngtest ${PNG_LIB_NAME})
    153 #  add_test(pngtest ${PNG_SOURCE_DIR}/pngtest.png)
    154 endif(PNG_TESTS)
    155 
    156 
    157 # CREATE PKGCONFIG FILES
    158 # we use the same files like ./configure, so we have to set its vars
    159 set(prefix      ${CMAKE_INSTALL_PREFIX})
    160 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
    161 set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
    162 set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
    163 
    164 configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
    165   ${PNG_BINARY_DIR}/libpng.pc)
    166 configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
    167   ${PNG_BINARY_DIR}/libpng-config)
    168 configure_file(${PNG_SOURCE_DIR}/scripts/libpng.pc.in
    169   ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc)
    170 configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
    171   ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config)
    172 
    173 # SET UP LINKS
    174 set_target_properties(${PNG_LIB_NAME} PROPERTIES
    175 #    VERSION 0.${PNGLIB_RELEASE}.1.2.38
    176      VERSION 0.${PNGLIB_RELEASE}.0
    177      SOVERSION 0
    178      CLEAN_DIRECT_OUTPUT 1)
    179 if(NOT WIN32)
    180   # that's uncool on win32 - it overwrites our static import lib...
    181   set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
    182      OUTPUT_NAME ${PNG_LIB_NAME}
    183      CLEAN_DIRECT_OUTPUT 1)
    184 endif(NOT WIN32)
    185 # INSTALL
    186 install_targets(/lib ${PNG_LIB_NAME})
    187 if(PNG_STATIC)
    188   install_targets(/lib ${PNG_LIB_NAME_STATIC})
    189 endif(PNG_STATIC)
    190 install(FILES png.h pngconf.h         DESTINATION include)
    191 install(FILES png.h pngconf.h         DESTINATION include/${PNGLIB_NAME})
    192 install(FILES libpng.3 libpngpf.3             DESTINATION man/man3)
    193 install(FILES png.5                           DESTINATION man/man5)
    194 install(FILES ${PNG_BINARY_DIR}/libpng.pc     DESTINATION lib/pkgconfig)
    195 install(FILES ${PNG_BINARY_DIR}/libpng-config      DESTINATION bin)
    196 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}.pc  DESTINATION lib/pkgconfig)
    197 install(FILES ${PNG_BINARY_DIR}/${PNGLIB_NAME}-config DESTINATION bin)
    198 
    199 # what's with libpng.txt and all the extra files?
    200 
    201 
    202 # UNINSTALL
    203 # do we need this?
    204 
    205 
    206 # DIST
    207 # do we need this?
    208 
    209 # to create msvc import lib for mingw compiled shared lib
    210 # pexports libpng.dll > libpng.def
    211 # lib /def:libpng.def /machine:x86
    212 
    213