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