enable_png.cmake 1.3 KB
Newer Older
1
2
3
4
5
6
macro(enable_png _FLAGS_ _INC_DIRS_ _LIBS_)
    if (${ARGC} GREATER 3)
      set(LINK_EXECUTABLE ON)
    else ()
      set(LINK_EXECUTABLE OFF)
    endif ()
7

8
    find_file(_PNG_H png.h
9
10
11
      HINTS ENV CPATH /usr/include
      DOC "headerfile png.h for PNG-READER")

12
    if (NOT _PNG_H)
13
      message(FATAL_ERROR "Could not find the PNG header png.h.")
14
15
16
17
18
19
20
21
22
23
24
25
26
    else ()
      file(STRINGS ${_PNG_H} PNG_VERSION_LINE REGEX "#define PNG_LIBPNG_VER_STRING")
      string(REGEX MATCH "\"([0-9]+[.][0-9]+([.][0-9]+)?)\"" PNG_VERSION_LINE ${PNG_VERSION_LINE})
      set(PNG_VERSION ${CMAKE_MATCH_1})

      message(STATUS "Libpng version: ${PNG_VERSION}")
      if (NOT PNG_VERSION VERSION_LESS "1.6" OR NOT PNG_VERSION VERSION_GREATER "1.2")
        message(FATAL_ERROR "Incompatible libpng version. Requires 1.2.x")
      endif ()
    endif ()

    get_filename_component(PNG_PATH ${_PNG_H} PATH)
    list(APPEND ${_INC_DIRS_} ${PNG_PATH})
27

28
    if (LINK_EXECUTABLE)
29
30
31
32
33
34
35
36
37
38
39
40
      find_library(_PNG_LIB png
        HINTS ENV LIBRARY_PATH
        DOC "The PNG library")
      if (_PNG_LIB)
        list(APPEND ${_LIBS_} ${_PNG_LIB})
      else()
        message(FATAL_ERROR "Could not find the PNG library")
      endif()
    endif (LINK_EXECUTABLE)

    list(APPEND ${_FLAGS_} "-DHAVE_PNG=1")
endmacro(enable_png)