2009-08-27 16:59:40 -04:00
|
|
|
cmake_minimum_required(VERSION 2.4.3)
|
2010-02-07 19:08:50 -05:00
|
|
|
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
|
|
|
|
2009-10-30 16:42:54 -04:00
|
|
|
if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
|
2010-02-07 19:08:50 -05:00
|
|
|
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.")
|
2009-10-30 16:42:54 -04:00
|
|
|
endif()
|
|
|
|
|
2010-02-07 19:08:50 -05:00
|
|
|
project(libpng C)
|
2009-10-30 16:42:54 -04:00
|
|
|
enable_testing()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2009-12-29 17:50:15 -05:00
|
|
|
# Copyright (C) 2007-2010 Glenn Randers-Pehrson
|
2009-06-24 10:31:28 -04:00
|
|
|
|
2009-06-26 22:46:52 -04:00
|
|
|
# This code is released under the libpng license.
|
2009-06-25 14:43:50 -04:00
|
|
|
# For conditions of distribution and use, see the disclaimer
|
2009-06-24 11:27:36 -04:00
|
|
|
# and license in png.h
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
set(PNGLIB_MAJOR 1)
|
2010-02-07 19:08:50 -05:00
|
|
|
set(PNGLIB_MINOR 5)
|
2007-05-15 17:16:34 -04:00
|
|
|
set(PNGLIB_RELEASE 0)
|
|
|
|
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
|
|
|
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
|
2006-12-07 20:16:44 -05:00
|
|
|
|
|
|
|
# needed packages
|
|
|
|
find_package(ZLIB REQUIRED)
|
2009-08-27 16:59:40 -04:00
|
|
|
include_directories(${ZLIB_INCLUDE_DIR})
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
if(NOT WIN32)
|
2010-02-07 19:08:50 -05:00
|
|
|
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()
|
2009-08-27 16:59:40 -04:00
|
|
|
else()
|
2010-02-07 19:08:50 -05:00
|
|
|
# not needed on windows
|
|
|
|
set(M_LIBRARY "")
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# COMMAND LINE OPTIONS
|
2009-08-27 16:59:40 -04:00
|
|
|
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()
|
|
|
|
|
2009-05-02 16:36:08 -04:00
|
|
|
if(MINGW)
|
|
|
|
option(PNG_TESTS "Build pngtest" NO)
|
2010-02-07 19:08:50 -05:00
|
|
|
else()
|
2009-05-02 16:36:08 -04:00
|
|
|
option(PNG_TESTS "Build pngtest" YES)
|
2010-02-07 19:08:50 -05:00
|
|
|
endif()
|
2009-08-27 16:59:40 -04:00
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
option(PNG_NO_CONSOLE_IO "FIXME" YES)
|
|
|
|
option(PNG_NO_STDIO "FIXME" YES)
|
2009-08-27 16:59:40 -04:00
|
|
|
option(PNG_DEBUG "Build with debug output" NO)
|
2007-05-15 17:16:34 -04:00
|
|
|
option(PNGARG "FIXME" YES)
|
2006-12-07 20:16:44 -05:00
|
|
|
#TODO:
|
|
|
|
# PNG_CONSOLE_IO_SUPPORTED
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# maybe needs improving, but currently I don't know when we can enable what :)
|
2006-12-07 20:16:44 -05:00
|
|
|
set(png_asm_tmp "OFF")
|
|
|
|
if(NOT WIN32)
|
2010-02-07 19:08:50 -05:00
|
|
|
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.*$")
|
2007-05-15 17:16:34 -04:00
|
|
|
set(png_asm_tmp "ON")
|
2010-02-07 19:08:50 -05:00
|
|
|
else("uname_output" MATCHES "^.*i[1-9]86.*$")
|
2007-05-15 17:16:34 -04:00
|
|
|
set(png_asm_tmp "OFF")
|
2010-02-07 19:08:50 -05:00
|
|
|
endif("uname_output" MATCHES "^.*i[1-9]86.*$")
|
|
|
|
endif(uname_executable)
|
2009-08-27 16:59:40 -04:00
|
|
|
else()
|
2010-02-07 19:08:50 -05:00
|
|
|
# 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 "")
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# SET LIBNAME
|
2009-08-27 16:59:40 -04:00
|
|
|
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
2006-12-07 20:16:44 -05:00
|
|
|
|
|
|
|
# to distinguish between debug and release lib
|
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
|
|
|
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# OUR SOURCES
|
2006-12-07 20:16:44 -05:00
|
|
|
set(libpng_sources
|
2010-02-07 19:08:50 -05:00
|
|
|
png.h
|
|
|
|
pngconf.h
|
2010-03-14 10:15:49 -04:00
|
|
|
pngpriv.h
|
2010-02-07 19:08:50 -05:00
|
|
|
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
|
2006-12-07 20:16:44 -05:00
|
|
|
)
|
|
|
|
set(pngtest_sources
|
2010-02-07 19:08:50 -05:00
|
|
|
pngtest.c
|
2006-12-07 20:16:44 -05:00
|
|
|
)
|
2007-05-15 17:16:34 -04:00
|
|
|
# SOME NEEDED DEFINITIONS
|
2009-11-07 13:02:48 -05:00
|
|
|
|
2006-12-07 20:16:44 -05:00
|
|
|
if(MSVC)
|
2010-03-14 10:15:49 -04:00
|
|
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
2006-12-07 20:16:44 -05:00
|
|
|
endif(MSVC)
|
|
|
|
|
2009-08-27 16:59:40 -04:00
|
|
|
if(PNG_SHARED OR NOT MSVC)
|
2010-02-07 19:08:50 -05:00
|
|
|
#if building msvc static this has NOT to be defined
|
|
|
|
add_definitions(-DZLIB_DLL)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2010-02-07 19:08:50 -05:00
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
if(PNG_CONSOLE_IO_SUPPORTED)
|
2010-02-07 19:08:50 -05:00
|
|
|
add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
|
|
|
if(PNG_NO_CONSOLE_IO)
|
2010-02-07 19:08:50 -05:00
|
|
|
add_definitions(-DPNG_NO_CONSOLE_IO)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
|
|
|
if(PNG_NO_STDIO)
|
2010-02-07 19:08:50 -05:00
|
|
|
add_definitions(-DPNG_NO_STDIO)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
|
|
|
if(PNG_DEBUG)
|
2010-03-14 10:15:49 -04:00
|
|
|
add_definitions(-DPNG_DEBUG=1)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
2009-05-02 16:36:08 -04:00
|
|
|
if(NOT M_LIBRARY AND NOT WIN32)
|
2010-02-07 19:08:50 -05:00
|
|
|
add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
|
|
|
# NOW BUILD OUR TARGET
|
2010-02-07 19:08:50 -05:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
|
2006-12-07 20:16:44 -05:00
|
|
|
|
|
|
|
if(PNG_SHARED)
|
2010-02-07 19:08:50 -05:00
|
|
|
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})
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
if(PNG_STATIC)
|
|
|
|
# does not work without changing name
|
2010-02-07 19:08:50 -05:00
|
|
|
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()
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
|
|
|
|
2006-12-07 20:16:44 -05:00
|
|
|
|
|
|
|
if(PNG_SHARED AND WIN32)
|
2010-02-07 19:08:50 -05:00
|
|
|
set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
2009-08-27 16:59:40 -04:00
|
|
|
if(PNG_TESTS AND PNG_SHARED)
|
2010-02-07 19:08:50 -05:00
|
|
|
# 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)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2006-12-07 20:16:44 -05:00
|
|
|
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# 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)
|
|
|
|
|
2010-02-07 19:08:50 -05:00
|
|
|
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)
|
2007-05-15 17:16:34 -04:00
|
|
|
|
|
|
|
# SET UP LINKS
|
2009-08-27 16:59:40 -04:00
|
|
|
if(PNG_SHARED)
|
|
|
|
set_target_properties(${PNG_LIB_NAME} PROPERTIES
|
2010-08-11 10:02:49 -04:00
|
|
|
# VERSION 15.${PNGLIB_RELEASE}.1.5.0beta42
|
2010-02-08 16:36:41 -05:00
|
|
|
VERSION 15.${PNGLIB_RELEASE}.0
|
|
|
|
SOVERSION 15
|
2010-02-07 19:08:50 -05:00
|
|
|
CLEAN_DIRECT_OUTPUT 1)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2009-05-02 16:36:08 -04:00
|
|
|
if(PNG_STATIC)
|
2009-08-27 16:59:40 -04:00
|
|
|
if(NOT WIN32)
|
|
|
|
# that's uncool on win32 - it overwrites our static import lib...
|
|
|
|
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
|
2010-02-07 19:08:50 -05:00
|
|
|
OUTPUT_NAME ${PNG_LIB_NAME}
|
|
|
|
CLEAN_DIRECT_OUTPUT 1)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# INSTALL
|
|
|
|
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
|
2010-02-07 19:08:50 -05:00
|
|
|
if(PNG_SHARED)
|
|
|
|
install(TARGETS ${PNG_LIB_NAME}
|
2009-08-27 16:59:40 -04:00
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib)
|
2010-02-07 19:08:50 -05:00
|
|
|
endif()
|
|
|
|
if(PNG_STATIC)
|
|
|
|
install(TARGETS ${PNG_LIB_NAME_STATIC}
|
2009-08-27 16:59:40 -04:00
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
ARCHIVE DESTINATION lib)
|
2010-02-07 19:08:50 -05:00
|
|
|
endif()
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
|
2010-02-07 19:08:50 -05:00
|
|
|
install(FILES png.h pngconf.h DESTINATION include)
|
|
|
|
install(FILES png.h pngconf.h DESTINATION include/${PNGLIB_NAME})
|
2009-10-30 16:42:54 -04:00
|
|
|
endif()
|
|
|
|
if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
|
2010-02-07 19:08:50 -05:00
|
|
|
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
|
|
|
|
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
|
|
|
|
DESTINATION bin)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
|
|
|
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
|
2010-02-07 19:08:50 -05:00
|
|
|
# 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)
|
2009-08-27 16:59:40 -04:00
|
|
|
endif()
|
2007-05-15 17:16:34 -04:00
|
|
|
|
2006-12-07 20:16:44 -05:00
|
|
|
# what's with libpng.txt and all the extra files?
|
|
|
|
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# UNINSTALL
|
2006-12-07 20:16:44 -05:00
|
|
|
# do we need this?
|
|
|
|
|
|
|
|
|
2007-05-15 17:16:34 -04:00
|
|
|
# DIST
|
2006-12-07 20:16:44 -05:00
|
|
|
# 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
|
2009-05-02 16:36:08 -04:00
|
|
|
|