2 # Find the MySQL includes and client library
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.
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}
27 message(STATUS "Using mysql-config: ${MYSQL_CONFIG}")
29 exec_program(${MYSQL_CONFIG}
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)
38 exec_program(${MYSQL_CONFIG}
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})
59 set(MYSQL_ADD_LIBRARIES "")
60 list(APPEND MYSQL_ADD_LIBRARIES "mysqlclient")
64 set(MYSQL_ADD_LIBRARIES "")
65 list(APPEND MYSQL_ADD_LIBRARIES "mysql")
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)
71 find_path(MYSQL_INCLUDE_DIR mysql.h
73 /usr/local/include/mysql
74 /usr/local/mysql/include
75 /usr/local/mysql/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}
86 ${MYSQL_ADD_LIBRARY_PATH}
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)