wrong character in the GSM 03.38 table (ç for Ç)
[gammu.git] / cmake / FindMySQL.cmake
blobdd1e7069dacf4aad4b377b06976405e3deb73798
1 # - Find MySQL
2 # Find the MySQL includes and client library
3 # This module defines
4 #  MYSQL_INCLUDE_DIR, where to find mysql.h
5 #  MYSQL_LIBRARIES, the libraries needed to use MySQL.
6 #  MYSQL_FOUND, If false, do not try to use MySQL.
8 # Copyright (c) 2006, Jaroslaw Staniek, <js@iidea.pl>
9 # Lot of adustmens by Michal Cihar <michal@cihar.com>
11 # vim: expandtab sw=4 ts=4 sts=4:
13 # Redistribution and use is allowed according to the terms of the BSD license.
16 if(UNIX) 
17     set(MYSQL_CONFIG_PREFER_PATH "$ENV{MYSQL_HOME}/bin" CACHE FILEPATH
18         "preferred path to MySQL (mysql_config)")
19     find_program(MYSQL_CONFIG mysql_config
20         ${MYSQL_CONFIG_PREFER_PATH}
21         /usr/local/mysql/bin/
22         /usr/local/bin/
23         /usr/bin/
24         )
25     
26     if(MYSQL_CONFIG) 
27         message(STATUS "Using mysql-config: ${MYSQL_CONFIG}")
28         # set INCLUDE_DIR
29         exec_program(${MYSQL_CONFIG}
30             ARGS --include
31             OUTPUT_VARIABLE MY_TMP)
33         string(REGEX REPLACE "-I([^ ]+)( .*)?" "\\1" MY_TMP "${MY_TMP}")
35         set(MYSQL_ADD_INCLUDE_DIR ${MY_TMP} CACHE FILEPATH INTERNAL)
37         # set LIBRARY_DIR
38         exec_program(${MYSQL_CONFIG}
39             ARGS --libs
40             OUTPUT_VARIABLE MY_TMP)
42         set(MYSQL_ADD_LIBRARIES "")
44         string(REGEX MATCHALL "(^| )-l[^ ]+" MYSQL_LIB_LIST "${MY_TMP}")
45         foreach(LIB ${MYSQL_LIB_LIST})
46             string(REGEX REPLACE "[ ]*-l([^ ]*)" "\\1" LIB "${LIB}")
47             list(APPEND MYSQL_ADD_LIBRARIES "${LIB}")
48         endforeach(LIB ${MYSQL_LIBS})
50         set(MYSQL_ADD_LIBRARY_PATH "")
52         string(REGEX MATCHALL "-L[^ ]+" MYSQL_LIBDIR_LIST "${MY_TMP}")
53         foreach(LIB ${MYSQL_LIBDIR_LIST})
54             string(REGEX REPLACE "[ ]*-L([^ ]*)" "\\1" LIB "${LIB}")
55             list(APPEND MYSQL_ADD_LIBRARY_PATH "${LIB}")
56         endforeach(LIB ${MYSQL_LIBS})
58     else(MYSQL_CONFIG)
59         set(MYSQL_ADD_LIBRARIES "")
60         list(APPEND MYSQL_ADD_LIBRARIES "mysqlclient")
61     endif(MYSQL_CONFIG)
62 else(UNIX)
63     if (WIN32)
64         set(MYSQL_ADD_LIBRARIES "")
65         list(APPEND MYSQL_ADD_LIBRARIES "mysql")
66     endif (WIN32)
67     set(MYSQL_ADD_INCLUDE_DIR "c:/msys/local/include" CACHE FILEPATH INTERNAL)
68     set(MYSQL_ADD_LIBRARY_PATH "c:/msys/local/lib" CACHE FILEPATH INTERNAL)
69 ENDIF(UNIX)
71 find_path(MYSQL_INCLUDE_DIR mysql.h
72     /usr/local/include
73     /usr/local/include/mysql 
74     /usr/local/mysql/include
75     /usr/local/mysql/include/mysql
76     /usr/include 
77     /usr/include/mysql
78     ${MYSQL_ADD_INCLUDE_DIR}
81 set(TMP_MYSQL_LIBRARIES "")
83 foreach(LIB ${MYSQL_ADD_LIBRARIES})
84     find_library("MYSQL_LIBRARIES_${LIB}" NAMES ${LIB}
85         PATHS
86         ${MYSQL_ADD_LIBRARY_PATH}
87         /usr/lib/mysql
88         /usr/local/lib
89         /usr/local/lib/mysql
90         /usr/local/mysql/lib
91     )
92     list(APPEND TMP_MYSQL_LIBRARIES "${MYSQL_LIBRARIES_${LIB}}")
93 endforeach(LIB ${MYSQL_ADD_LIBRARIES})
95 if (TMP_MYSQL_LIBRARIES)
96     set(MYSQL_LIBRARIES ${TMP_MYSQL_LIBRARIES} CACHE FILEPATH "MySQL Libraries" FORCE)
97 else (TMP_MYSQL_LIBRARIES)
98     set(MYSQL_LIBRARIES ${TMP_MYSQL_LIBRARIES} CACHE FILEPATH "MySQL Libraries")
99 endif (TMP_MYSQL_LIBRARIES)
101 if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
102     set(MYSQL_FOUND TRUE CACHE INTERNAL "MySQL found")
103     message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}")
104 else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
105     set(MYSQL_FOUND FALSE CACHE INTERNAL "MySQL found")
106     message(STATUS "MySQL not found.")
107 endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
109 mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES)