Translation update done using Pootle.
[gammu.git] / cmake / FindPostgres.cmake
blob753f4188fd113a347e66e9b49defe90763c3988d
1 # CMake module to search for PostgreSQL library
3 # pg_config is searched for in POSTGRES_CONFIG dir,
4 # default /usr/bin
6 # If it's found it sets POSTGRES_FOUND to TRUE
7 # and following variables are set:
8 #    POSTGRES_INCLUDE_DIR
9 #    POSTGRES_LIBRARY
11 IF(WIN32)
12   IF (NOT POSTGRES_INCLUDE_DIR)
13     FIND_PATH(POSTGRES_INCLUDE_DIR libpq-fe.h /usr/local/include /usr/include c:/msys/local/include)
14   ENDIF (NOT POSTGRES_INCLUDE_DIR)
16   IF (NOT POSTGRES_LIBRARY)
17     FIND_LIBRARY(POSTGRES_LIBRARY NAMES pq PATH /usr/local/lib /usr/lib c:/msys/local/lib)
18   ENDIF (NOT POSTGRES_LIBRARY)
20 ELSE(WIN32)
21   IF(UNIX) 
23     SET(POSTGRES_CONFIG_PREFER_PATH "$ENV{POSTGRES_HOME}/bin" CACHE FILEPATH "preferred path to PG (pg_config)")
24     FIND_PROGRAM(POSTGRES_CONFIG pg_config
25       ${POSTGRES_CONFIG_PREFER_PATH}
26       /usr/bin/
27       )
28     # MESSAGE("DBG POSTGRES_CONFIG ${POSTGRES_CONFIG}")
29     
30     IF (POSTGRES_CONFIG) 
31       # set INCLUDE_DIR
32       EXEC_PROGRAM(${POSTGRES_CONFIG}
33         ARGS --includedir
34         OUTPUT_VARIABLE PG_TMP)
35       find_path(POSTGRES_INCLUDE_DIR libpq-fe.h
36             /usr/local/include
37             /usr/local/include/postgresql 
38             /usr/local/postgresql/include
39             /usr/local/postgresql/include/postgresql
40             /usr/include 
41             /usr/include/postgresql
42             ${PG_TMP}
43       )
45       # set LIBRARY_DIR
46       EXEC_PROGRAM(${POSTGRES_CONFIG}
47         ARGS --libdir
48         OUTPUT_VARIABLE PG_TMP)
49       find_library(POSTGRES_LIBRARY pq
50         PATHS
51         ${PG_TMP}
52         /usr/lib/postgresql
53         /usr/local/lib
54         /usr/local/lib/postgresql
55         /usr/local/postgresql/lib
56       )
57     ENDIF(POSTGRES_CONFIG)
59   ENDIF(UNIX)
60 ENDIF(WIN32)
62 IF (POSTGRES_INCLUDE_DIR AND POSTGRES_LIBRARY)
63    SET(POSTGRES_FOUND TRUE CACHE INTERNAL "PostgreSQL found")
64 ENDIF (POSTGRES_INCLUDE_DIR AND POSTGRES_LIBRARY)
67 IF (POSTGRES_FOUND)
69    IF (NOT POSTGRES_FIND_QUIETLY)
70       MESSAGE(STATUS "Found PostgreSQL: ${POSTGRES_INCLUDE_DIR}, ${POSTGRES_LIBRARY}")
71    ENDIF (NOT POSTGRES_FIND_QUIETLY)
73    check_library_exists("${POSTGRES_LIBRARY}" PQescapeStringConn "" HAVE_PQESCAPESTRINGCONN)
75 ELSE (POSTGRES_FOUND)
77    #SET (POSTGRES_INCLUDE_DIR "")
78    #SET (POSTGRES_LIBRARY "")
80    IF (POSTGRES_FIND_REQUIRED)
81       MESSAGE(FATAL_ERROR "Could not find PostgreSQL")
82    ELSE (POSTGRES_FIND_REQUIRED)
83       MESSAGE(STATUS "Could not find PostgreSQL")
84    ENDIF (POSTGRES_FIND_REQUIRED)
86 ENDIF (POSTGRES_FOUND)