summaryrefslogtreecommitdiff
path: root/CMake/Modules/FindGuichan.cmake
blob: 1623b00d5fd471c3c8b0f36ae2415668d1b55633 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# - Try to find Guichan
# Once done this will define
#
#  GUICHAN_FOUND - system has Guichan
#  GUICHAN_INCLUDE_DIR - the Guichan include directory
#  GUICHAN_LIBRARIES - the libraries needed to use Guichan
#
# Supported components: SDL OpenGL
#
# TODO: Clean up the components stuff and try to add all known
# components when none are specified. May not bail out for not found
# components then, set some var instead...

# Be quiet if Guichan was already found
# We need an extra variable to have the check per component

IF (Guichan_INCLUDE_DIR AND Guichan_LIBRARY)
    SET(Guichan_QUIET TRUE)
ENDIF ()

FIND_PATH(Guichan_INCLUDE_DIR
    NAMES guichan.hpp
    PATHS /usr/include /usr/local/include
    )

FIND_LIBRARY(Guichan_LIBRARY
    NAMES guichan
    PATHS /usr/lib /usr/local/lib
    )

MARK_AS_ADVANCED(Guichan_INCLUDE_DIR Guichan_LIBRARY)

IF (Guichan_INCLUDE_DIR AND Guichan_LIBRARY)
    SET(GUICHAN_FOUND TRUE)
    SET(GUICHAN_INCLUDE_DIR ${Guichan_INCLUDE_DIR})
    SET(GUICHAN_LIBRARIES ${Guichan_LIBRARY})

    IF (NOT Guichan_FIND_QUIETLY AND NOT Guichan_QUIET)
        MESSAGE(STATUS "Found Guichan: ${Guichan_LIBRARY}")
    ENDIF ()
ENDIF ()

# Bail out if Guichan is not found but required
IF (NOT GUICHAN_FOUND AND Guichan_FIND_REQUIRED)
    MESSAGE(FATAL_ERROR "Could NOT find Guichan library ${GUICHAN_INCLUDE_DIR}")
ENDIF ()

# Check for guichan components
FOREACH (COMPONENT ${Guichan_FIND_COMPONENTS})
    SET(COMPONENT_FOUND FALSE)

    IF (COMPONENT STREQUAL "SDL")
        SET(COMPONENT_FOUND TRUE)
        SET(Guichan_HEADER "guichan/sdl.hpp")
        SET(Guichan_LIBRARY "guichan_sdl")
    ENDIF ()

    IF (COMPONENT STREQUAL "OpenGL")
        SET(COMPONENT_FOUND TRUE)
        SET(Guichan_HEADER "guichan/opengl.hpp")
        SET(Guichan_LIBRARY "guichan_opengl")
    ENDIF ()

    IF (NOT COMPONENT_FOUND)
        MESSAGE(FATAL_ERROR "Invalid Guichan component: ${COMPONENT}")
    ENDIF (NOT COMPONENT_FOUND)

    # Check if we already found this component
    IF (Guichan_LIBRARY_${COMPONENT})
        SET(Guichan_QUIET TRUE)
    ELSE ()
        SET(Guichan_QUIET FALSE)
    ENDIF ()

    FIND_LIBRARY(Guichan_LIBRARY_${COMPONENT}
        NAMES ${Guichan_LIBRARY}
        PATHS /usr/lib /usr/local/lib
        )

    MARK_AS_ADVANCED(Guichan_LIBRARY_${COMPONENT})

    IF (NOT EXISTS ${Guichan_INCLUDE_DIR}/${Guichan_HEADER} OR
            NOT Guichan_LIBRARY_${COMPONENT})
        SET(GUICHAN_FOUND FALSE)
        MESSAGE(FATAL_ERROR "Could NOT find Guichan component ${COMPONENT}")
    ENDIF ()

    IF (NOT Guichan_FIND_QUIETLY AND NOT Guichan_QUIET)
        MESSAGE(STATUS "Found Guichan ${COMPONENT}: ${Guichan_LIBRARY_${COMPONENT}}")
    ENDIF ()

    SET(GUICHAN_LIBRARIES ${GUICHAN_LIBRARIES} ${Guichan_LIBRARY_${COMPONENT}})
ENDFOREACH()