vcpkg/ports/mysql-connector-cpp/FindMySQL.cmake
Li Xiaobin 79211d3e4a
[mysql-connector-cpp] Add new port (#25652)
* [mysql-connector-cpp] Add new port

* [mysql-connector-cpp] add version

* [mysql-connector-cpp] Fix code review suggestion

* [mysql-connector-cpp] Run x-add-version

* [mysql-connector-cpp] Quote cmake expressions; Add CMake targets

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* unofficial targets

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>

* [mysql-connector-cpp] Add unofficial targets and usage

* [mysql-connector-cpp] Run x-add-version

* [mysql-connector-cpp] Fix code review suggestion

* [mysql-connector-cpp] Run x-add-version

* Fix license and supports nitpick.

* Version DB

* Remove vcpkg-cmake-wrapper

* Version DB

Co-authored-by: JonLiu1993 <63675417+JonLiu1993@users.noreply.github.com>
Co-authored-by: Billy O'Neal <bion@microsoft.com>
2022-08-11 13:09:00 -07:00

43 lines
1.5 KiB
CMake

find_package(libmysql REQUIRED)
set(MYSQL_INCLUDE_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/mysql")
if(NOT EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h")
message(FATAL_ERROR "MYSQL_INCLUDE_DIR given, but no \"mysql.h\" in \"${MYSQL_INCLUDE_DIR}\"")
endif()
# Write the C source file that will include the MySQL headers
set(GETMYSQLVERSION_SOURCEFILE "${CMAKE_CURRENT_BINARY_DIR}/getmysqlversion.c")
file(WRITE "${GETMYSQLVERSION_SOURCEFILE}"
"#include <mysql.h>\n"
"#include <stdio.h>\n"
"int main() {\n"
" printf(\"%s\", MYSQL_SERVER_VERSION);\n"
"}\n"
)
# Compile and run the created executable, store output in MYSQL_VERSION
try_run(_run_result _compile_result
"${CMAKE_BINARY_DIR}"
"${GETMYSQLVERSION_SOURCEFILE}"
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${MYSQL_INCLUDE_DIR}"
RUN_OUTPUT_VARIABLE MYSQL_VERSION
)
if(NOT MYSQL_VERSION)
message(FATAL_ERROR "Could not determine the MySQL Server version")
endif()
# Clean up so only numeric, in case of "-alpha" or similar
string(REGEX MATCHALL "([0-9]+.[0-9]+.[0-9]+)" MYSQL_VERSION "${MYSQL_VERSION}")
# To create a fully numeric version, first normalize so N.NN.NN
string(REGEX REPLACE "[.]([0-9])[.]" ".0\\1." MYSQL_VERSION_ID "${MYSQL_VERSION}")
string(REGEX REPLACE "[.]([0-9])$" ".0\\1" MYSQL_VERSION_ID "${MYSQL_VERSION_ID}")
# Finally remove the dot
string(REGEX REPLACE "[.]" "" MYSQL_VERSION_ID "${MYSQL_VERSION_ID}")
set(MYSQL_NUM_VERSION ${MYSQL_VERSION_ID})
include_directories("${MYSQL_INCLUDE_DIR}")