summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindLibExpat.cmake
blob: a07c8de4c7b8231fd47e70a5a24590774dc25309 (plain)
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
# - Try to find LIBEXPAT
# Once done this will define
#
#  LIBEXPAT_FOUND - system has LIBEXPAT
#  LIBEXPAT_INCLUDE_DIR - the LIBEXPAT include directory
#  LIBEXPAT_LIBRARIES - the libraries needed to use LIBEXPAT
#  LIBEXPAT_DEFINITIONS - Compiler switches required for using LIBEXPAT

if (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)

    # in cache already
    SET(LIBEXPAT_FOUND TRUE)

else (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)

    IF (WIN32)
		file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _progFiles)
		find_FILE(LIBEXPAT_DIR expat Source/lib/expat.h
   			PATHS
   			"${_progFiles}"
		)
        if (LIBEXPAT_DIR)
            set (_LIBEXPATIncDir  ${LIBEXPAT_DIR}/Source/lib)
            set (_LIBEXPATLinkDir ${LIBEXPAT_DIR}/libs)
        endif (LIBEXPAT_DIR)
    ELSE (WIN32)
        # use pkg-config to get the directories and then use these values
        # in the FIND_PATH() and FIND_LIBRARY() calls
        INCLUDE(UsePkgConfig)
        PKGCONFIG(LIBEXPAT-2.0 _LIBEXPATIncDir _LIBEXPATLinkDir _LIBEXPATLinkFlags _LiIconvCflags)
        SET(LIBEXPAT_DEFINITIONS ${_LIBEXPATCflags})
    ENDIF (WIN32)

    FIND_PATH(LIBEXPAT_INCLUDE_DIR expat.h
      PATHS
     ${_LIBEXPATIncDir}
      PATH_SUFFIXES LIBEXPAT
    )

    FIND_LIBRARY(LIBEXPAT_LIBRARIES NAMES expat libexpat
      PATHS
      ${_LIBEXPATLinkDir}
    )

    if (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
       set(LIBEXPAT_FOUND TRUE)
    endif (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)

    if (LIBEXPAT_FOUND)
      if (NOT LIBEXPAT_FIND_QUIETLY)
        message(STATUS "Found libexpat: ${LIBEXPAT_LIBRARIES}")
      endif (NOT LIBEXPAT_FIND_QUIETLY)
    else (LIBEXPAT_FOUND)
      if (LIBEXPAT_FIND_REQUIRED)
        message(SEND_ERROR "Could NOT find libexpat")
      endif (LIBEXPAT_FIND_REQUIRED)
    endif (LIBEXPAT_FOUND)

    MARK_AS_ADVANCED(LIBEXPAT_INCLUDE_DIR LIBEXPAT_LIBRARIES)

endif (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)