Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 1 | # CMakeLists.txt |
| 2 | |
John Bowler | 1b9b970 | 2013-06-05 11:41:44 -0500 | [diff] [blame] | 3 | # Copyright (C) 2007-2013 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 4 | |
| 5 | # This code is released under the libpng license. |
| 6 | # For conditions of distribution and use, see the disclaimer |
| 7 | # and license in png.h |
| 8 | |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 9 | cmake_minimum_required(VERSION 2.4.4) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 10 | set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) |
| 11 | |
Glenn Randers-Pehrson | 43f0311 | 2013-06-05 11:07:01 -0500 | [diff] [blame] | 12 | set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo") |
| 13 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 14 | project(libpng C) |
Glenn Randers-Pehrson | ee35abb | 2009-10-30 15:42:54 -0500 | [diff] [blame] | 15 | enable_testing() |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 16 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 17 | set(PNGLIB_MAJOR 1) |
Glenn Randers-Pehrson | 15ea1fa | 2011-11-23 15:28:01 -0600 | [diff] [blame] | 18 | set(PNGLIB_MINOR 6) |
Glenn Randers-Pehrson | 71d23c4 | 2014-03-06 19:52:04 -0600 | [diff] [blame] | 19 | set(PNGLIB_RELEASE 11) |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 20 | set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
| 21 | set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE}) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 22 | |
| 23 | # needed packages |
| 24 | find_package(ZLIB REQUIRED) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 25 | include_directories(${ZLIB_INCLUDE_DIR}) |
| 26 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 27 | if(NOT WIN32) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 28 | find_library(M_LIBRARY |
| 29 | NAMES m |
| 30 | PATHS /usr/lib /usr/local/lib |
| 31 | ) |
| 32 | if(NOT M_LIBRARY) |
| 33 | message(STATUS |
| 34 | "math library 'libm' not found - floating point support disabled") |
| 35 | endif() |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 36 | else() |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 37 | # not needed on windows |
| 38 | set(M_LIBRARY "") |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 39 | endif() |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 40 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 41 | # COMMAND LINE OPTIONS |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 42 | if(DEFINED PNG_SHARED) |
| 43 | option(PNG_SHARED "Build shared lib" ${PNG_SHARED}) |
| 44 | else() |
| 45 | option(PNG_SHARED "Build shared lib" ON) |
| 46 | endif() |
| 47 | if(DEFINED PNG_STATIC) |
| 48 | option(PNG_STATIC "Build static lib" ${PNG_STATIC}) |
| 49 | else() |
| 50 | option(PNG_STATIC "Build static lib" ON) |
| 51 | endif() |
| 52 | |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 53 | option(PNG_TESTS "Build libpng tests" YES) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 54 | |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 55 | # Many more configuration options could be added here |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 56 | option(PNG_DEBUG "Build with debug output" NO) |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 57 | option(PNGARG "Disable ANSI-C prototypes" NO) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 58 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 59 | # SET LIBNAME |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 60 | set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR}) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 61 | |
| 62 | # to distinguish between debug and release lib |
| 63 | set(CMAKE_DEBUG_POSTFIX "d") |
| 64 | |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 65 | # Use the prebuilt pnglibconf.h file from the scripts folder |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 66 | # TODO: fix this by building with awk; without this no cmake build can be |
| 67 | # configured directly (to do so indirectly use your local awk to build a |
| 68 | # pnglibconf.h in the build directory.) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 69 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt |
| 70 | ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h) |
| 71 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 72 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 73 | # OUR SOURCES |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 74 | set(libpng_public_hdrs |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 75 | png.h |
| 76 | pngconf.h |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 77 | ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h |
| 78 | ) |
| 79 | set(libpng_sources |
| 80 | ${libpng_public_hdrs} |
Glenn Randers-Pehrson | 07d9fc9 | 2010-08-26 17:11:55 -0500 | [diff] [blame] | 81 | pngdebug.h |
| 82 | pnginfo.h |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 83 | pngpriv.h |
Glenn Randers-Pehrson | 07d9fc9 | 2010-08-26 17:11:55 -0500 | [diff] [blame] | 84 | pngstruct.h |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 85 | png.c |
| 86 | pngerror.c |
| 87 | pngget.c |
| 88 | pngmem.c |
| 89 | pngpread.c |
| 90 | pngread.c |
| 91 | pngrio.c |
| 92 | pngrtran.c |
| 93 | pngrutil.c |
| 94 | pngset.c |
| 95 | pngtrans.c |
| 96 | pngwio.c |
| 97 | pngwrite.c |
| 98 | pngwtran.c |
| 99 | pngwutil.c |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 100 | ) |
| 101 | set(pngtest_sources |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 102 | pngtest.c |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 103 | ) |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 104 | set(pngvalid_sources |
John Bowler | c4081f0 | 2011-12-08 09:53:00 -0600 | [diff] [blame] | 105 | contrib/libtests/pngvalid.c |
| 106 | ) |
| 107 | set(pngstest_sources |
| 108 | contrib/libtests/pngstest.c |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 109 | ) |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 110 | # SOME NEEDED DEFINITIONS |
Glenn Randers-Pehrson | 69b0bc0 | 2009-11-07 12:02:48 -0600 | [diff] [blame] | 111 | |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 112 | if(MSVC) |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 113 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 114 | endif(MSVC) |
| 115 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 116 | if(PNG_DEBUG) |
Glenn Randers-Pehrson | 8c03730 | 2010-08-23 17:07:32 -0500 | [diff] [blame] | 117 | add_definitions(-DPNG_DEBUG) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 118 | endif() |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 119 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 120 | # NOW BUILD OUR TARGET |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 121 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR}) |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 122 | |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 123 | unset(PNG_LIB_TARGETS) |
| 124 | |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 125 | if(PNG_SHARED) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 126 | add_library(${PNG_LIB_NAME} SHARED ${libpng_sources}) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 127 | set(PNG_LIB_TARGETS ${PNG_LIB_NAME}) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 128 | if(MSVC) |
| 129 | # msvc does not append 'lib' - do it here to have consistent name |
| 130 | set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib") |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 131 | set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib") |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 132 | endif() |
| 133 | target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY}) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 134 | endif() |
| 135 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 136 | if(PNG_STATIC) |
| 137 | # does not work without changing name |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 138 | set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static) |
| 139 | add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources}) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 140 | list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC}) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 141 | if(MSVC) |
| 142 | # msvc does not append 'lib' - do it here to have consistent name |
| 143 | set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib") |
| 144 | endif() |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 145 | target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY}) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 146 | endif() |
| 147 | |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 148 | if(NOT PNG_LIB_TARGETS) |
| 149 | message(SEND_ERROR |
| 150 | "No library variant selected to build. " |
| 151 | "Please enable at least one of the following options: PNG_STATIC, PNG_SHARED") |
| 152 | endif() |
| 153 | |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 154 | if(PNG_SHARED AND WIN32) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 155 | set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 156 | endif() |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 157 | |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 158 | if(PNG_TESTS AND PNG_SHARED) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 159 | # does not work with msvc due to png_lib_ver issue |
| 160 | add_executable(pngtest ${pngtest_sources}) |
| 161 | target_link_libraries(pngtest ${PNG_LIB_NAME}) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 162 | add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png) |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 163 | # |
| 164 | add_executable(pngvalid ${pngvalid_sources}) |
| 165 | target_link_libraries(pngvalid ${PNG_LIB_NAME}) |
| 166 | add_test(pngvalid ./pngvalid) |
John Bowler | c4081f0 | 2011-12-08 09:53:00 -0600 | [diff] [blame] | 167 | add_executable(pngstest ${pngstest_sources}) |
| 168 | target_link_libraries(pngstest ${PNG_LIB_NAME}) |
| 169 | add_test(pngstest ./pngstest |
| 170 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g01.png |
| 171 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g02.png |
| 172 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g04.png |
| 173 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g08.png |
| 174 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn0g16.png |
| 175 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c08.png |
| 176 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn2c16.png |
| 177 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p01.png |
| 178 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p02.png |
| 179 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p04.png |
| 180 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn3p08.png |
| 181 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a08.png |
| 182 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn4a16.png |
| 183 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a08.png |
| 184 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/basn6a16.png |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 185 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g01.png |
| 186 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g02.png |
| 187 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn0g04.png |
John Bowler | c4081f0 | 2011-12-08 09:53:00 -0600 | [diff] [blame] | 188 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn2c16.png |
| 189 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbbn3p08.png |
| 190 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn2c16.png |
| 191 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbgn3p08.png |
| 192 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbrn2c08.png |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 193 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn0g16.png |
John Bowler | c4081f0 | 2011-12-08 09:53:00 -0600 | [diff] [blame] | 194 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbwn3p08.png |
| 195 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftbyn3p08.png |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 196 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n0g08.png |
John Bowler | c4081f0 | 2011-12-08 09:53:00 -0600 | [diff] [blame] | 197 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n2c08.png |
| 198 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp0n3p08.png |
| 199 | ${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/ftp1n3p08.png |
| 200 | ) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 201 | endif() |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 202 | |
Glenn Randers-Pehrson | e61e403 | 2011-08-17 09:02:07 -0500 | [diff] [blame] | 203 | # Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set |
| 204 | IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 205 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib") |
Glenn Randers-Pehrson | e61e403 | 2011-08-17 09:02:07 -0500 | [diff] [blame] | 206 | ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) |
| 207 | |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 208 | # Set a variable with CMake code which: |
| 209 | # Creates a symlink from src to dest (if possible) or alternatively |
| 210 | # copies if different. |
Glenn Randers-Pehrson | b17c75b | 2011-07-27 20:47:13 -0500 | [diff] [blame] | 211 | macro(CREATE_SYMLINK SRC_FILE DEST_FILE) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 212 | FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 213 | if(WIN32 AND NOT CYGWIN AND NOT MSYS) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 214 | ADD_CUSTOM_COMMAND( |
| 215 | OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE} |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 216 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} |
| 217 | COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE} |
| 218 | DEPENDS ${PNG_LIB_TARGETS} |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 219 | ) |
| 220 | ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 221 | else(WIN32 AND NOT CYGWIN AND NOT MSYS) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 222 | get_filename_component(LINK_TARGET "${SRC_FILE}" NAME) |
| 223 | execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 224 | execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 225 | endif(WIN32 AND NOT CYGWIN AND NOT MSYS) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 226 | endmacro() |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 227 | |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 228 | # libpng is a library so default to 'lib' |
Glenn Randers-Pehrson | 8c03730 | 2010-08-23 17:07:32 -0500 | [diff] [blame] | 229 | if(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
Glenn Randers-Pehrson | d3edb3f | 2011-01-14 17:08:28 -0600 | [diff] [blame] | 230 | set(CMAKE_INSTALL_LIBDIR lib) |
Glenn Randers-Pehrson | 8c03730 | 2010-08-23 17:07:32 -0500 | [diff] [blame] | 231 | endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
Glenn Randers-Pehrson | e29c4b9 | 2011-09-27 19:01:58 -0500 | [diff] [blame] | 232 | |
| 233 | # CREATE PKGCONFIG FILES |
| 234 | # we use the same files like ./configure, so we have to set its vars |
| 235 | # Only do this on Windows for Cygwin - the files don't make much sense outside |
| 236 | # a UNIX look alike |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 237 | if(NOT WIN32 OR CYGWIN OR MINGW) |
| 238 | set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 239 | set(exec_prefix ${CMAKE_INSTALL_PREFIX}) |
| 240 | set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) |
| 241 | set(includedir ${CMAKE_INSTALL_PREFIX}/include) |
| 242 | set(LIBS "-lz -lm") |
| 243 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in |
| 244 | ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY) |
| 245 | CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 246 | |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 247 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in |
| 248 | ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY) |
| 249 | CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config) |
Glenn Randers-Pehrson | 8e83631 | 2011-11-21 12:37:13 -0600 | [diff] [blame] | 250 | endif(NOT WIN32 OR CYGWIN OR MINGW) |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 251 | |
| 252 | # SET UP LINKS |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 253 | if(PNG_SHARED) |
| 254 | set_target_properties(${PNG_LIB_NAME} PROPERTIES |
Glenn Randers-Pehrson | d5201df | 2014-04-20 20:16:56 -0500 | [diff] [blame^] | 255 | # VERSION 16.${PNGLIB_RELEASE}.1.6.11beta05 |
Glenn Randers-Pehrson | 7455cbf | 2011-11-24 14:40:36 -0600 | [diff] [blame] | 256 | VERSION 16.${PNGLIB_RELEASE}.0 |
| 257 | SOVERSION 16 |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 258 | CLEAN_DIRECT_OUTPUT 1) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 259 | endif() |
Glenn Randers-Pehrson glennrp@comcast.net | 7ecf7bd | 2009-05-02 15:36:08 -0500 | [diff] [blame] | 260 | if(PNG_STATIC) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 261 | # MSVC doesn't use a different file extension for shared vs. static |
| 262 | # libs. We are able to change OUTPUT_NAME to remove the _static |
| 263 | # for all other platforms. |
| 264 | if(NOT MSVC) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 265 | set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 266 | OUTPUT_NAME ${PNG_LIB_NAME} |
| 267 | CLEAN_DIRECT_OUTPUT 1) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 268 | endif() |
| 269 | endif() |
| 270 | |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 271 | # If CMake > 2.4.x, we set a variable used below to export |
| 272 | # targets to an export file. |
| 273 | # TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2 |
| 274 | if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4) |
| 275 | set(PNG_EXPORT_RULE EXPORT libpng) |
| 276 | elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof |
| 277 | set(PNG_EXPORT_RULE EXPORT libpng) |
| 278 | endif() |
| 279 | |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 280 | # INSTALL |
| 281 | if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 282 | install(TARGETS ${PNG_LIB_TARGETS} |
| 283 | ${PNG_EXPORT_RULE} |
| 284 | RUNTIME DESTINATION bin |
| 285 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 286 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 287 | |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 288 | if(PNG_SHARED) |
Glenn Randers-Pehrson | 7455cbf | 2011-11-24 14:40:36 -0600 | [diff] [blame] | 289 | # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin |
Glenn Randers-Pehrson | 8e83631 | 2011-11-21 12:37:13 -0600 | [diff] [blame] | 290 | if(CYGWIN OR MINGW) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 291 | get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 292 | CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 293 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX} |
| 294 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Glenn Randers-Pehrson | 8e83631 | 2011-11-21 12:37:13 -0600 | [diff] [blame] | 295 | endif(CYGWIN OR MINGW) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 296 | |
| 297 | if(NOT WIN32) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 298 | get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE}) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 299 | CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX}) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 300 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX} |
| 301 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Glenn Randers-Pehrson | b17c75b | 2011-07-27 20:47:13 -0500 | [diff] [blame] | 302 | endif(NOT WIN32) |
| 303 | endif(PNG_SHARED) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 304 | |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 305 | if(PNG_STATIC) |
Glenn Randers-Pehrson | 8e83631 | 2011-11-21 12:37:13 -0600 | [diff] [blame] | 306 | if(NOT WIN32 OR CYGWIN OR MINGW) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 307 | get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE}) |
Claudio Bley | 0281dee | 2013-03-07 11:17:17 -0600 | [diff] [blame] | 308 | CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX}) |
Glenn Randers-Pehrson | 0c03fc6 | 2011-08-17 09:46:29 -0500 | [diff] [blame] | 309 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX} |
| 310 | DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
Glenn Randers-Pehrson | 8e83631 | 2011-11-21 12:37:13 -0600 | [diff] [blame] | 311 | endif(NOT WIN32 OR CYGWIN OR MINGW) |
Glenn Randers-Pehrson | b17c75b | 2011-07-27 20:47:13 -0500 | [diff] [blame] | 312 | endif() |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 313 | endif() |
| 314 | |
| 315 | if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 316 | install(FILES ${libpng_public_hdrs} DESTINATION include) |
| 317 | install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME}) |
Glenn Randers-Pehrson | ee35abb | 2009-10-30 15:42:54 -0500 | [diff] [blame] | 318 | endif() |
| 319 | if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL ) |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 320 | if(NOT WIN32 OR CYGWIN OR MINGW) |
| 321 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin) |
| 322 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config |
| 323 | DESTINATION bin) |
| 324 | endif(NOT WIN32 OR CYGWIN OR MINGW) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 325 | endif() |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 326 | |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 327 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 328 | # Install man pages |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 329 | if(NOT PNG_MAN_DIR) |
| 330 | set(PNG_MAN_DIR "share/man") |
| 331 | endif() |
| 332 | install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3) |
| 333 | install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5) |
Glenn Randers-Pehrson | e3f3c4e | 2010-02-07 18:08:50 -0600 | [diff] [blame] | 334 | # Install pkg-config files |
Glenn Randers-Pehrson | 871b1d0 | 2013-03-02 14:58:22 -0600 | [diff] [blame] | 335 | if(NOT WIN32 OR CYGWIN OR MINGW) |
| 336 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc |
| 337 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 338 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config |
| 339 | DESTINATION bin) |
| 340 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc |
| 341 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
| 342 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config |
| 343 | DESTINATION bin) |
| 344 | endif(NOT WIN32 OR CYGWIN OR MINGW) |
Glenn Randers-Pehrson | 38e467e | 2009-08-27 15:59:40 -0500 | [diff] [blame] | 345 | endif() |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 346 | |
Glenn Randers-Pehrson | 0c3fea3 | 2010-10-02 21:25:01 -0500 | [diff] [blame] | 347 | # On versions of CMake that support it, create an export file CMake |
| 348 | # users can include() to import our targets |
| 349 | if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL ) |
| 350 | install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake) |
| 351 | endif() |
| 352 | |
Glenn Randers-Pehrson | d3edb3f | 2011-01-14 17:08:28 -0600 | [diff] [blame] | 353 | # what's with libpng-$VER%.txt and all the extra files? |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 354 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 355 | # UNINSTALL |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 356 | # do we need this? |
| 357 | |
Glenn Randers-Pehrson | a7dbcba | 2007-05-15 16:16:34 -0500 | [diff] [blame] | 358 | # DIST |
Glenn Randers-Pehrson | 7edd458 | 2006-12-07 19:16:44 -0600 | [diff] [blame] | 359 | # do we need this? |
| 360 | |
| 361 | # to create msvc import lib for mingw compiled shared lib |
| 362 | # pexports libpng.dll > libpng.def |
| 363 | # lib /def:libpng.def /machine:x86 |
Glenn Randers-Pehrson glennrp@comcast.net | 7ecf7bd | 2009-05-02 15:36:08 -0500 | [diff] [blame] | 364 | |