Skip to content

Commit

Permalink
fix(cmake): Add Homebrew path detection for mariadb-connector-c to …
Browse files Browse the repository at this point in the history
…fix macOS build failure. (#582)

Co-authored-by: kirkrodrigues <[email protected]>
  • Loading branch information
LinZhihao-723 and kirkrodrigues authored Nov 10, 2024
1 parent 7ea3941 commit 4446eb5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions components/core/cmake/Modules/FindMariaDBClient.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ include(cmake/Modules/FindLibraryDependencies.cmake)
find_package(PkgConfig)
pkg_check_modules(mariadbclient_PKGCONF QUIET "lib${mariadbclient_LIBNAME}")

if(NOT mariadbclient_PKGCONF_FOUND AND APPLE)
execute_process(
COMMAND brew --prefix mariadb-connector-c
RESULT_VARIABLE mariadbclient_BREW_RESULT
OUTPUT_VARIABLE mariadbclient_MACOS_PREFIX
)
if(NOT mariadbclient_BREW_RESULT EQUAL 0)
message(
FATAL_ERROR
"pkg-config cannot find ${mariadbclient_LIBNAME} and mariadb-connector-c isn't"
" installed via Homebrew"
)
endif()
string(STRIP "${mariadbclient_MACOS_PREFIX}" mariadbclient_MACOS_PREFIX)
list(PREPEND CMAKE_PREFIX_PATH ${mariadbclient_MACOS_PREFIX})
pkg_check_modules(mariadbclient_PKGCONF QUIET "lib${mariadbclient_LIBNAME}")
endif()

if(NOT mariadbclient_PKGCONF_FOUND)
message(FATAL_ERROR "pkg-config cannot find ${mariadbclient_LIBNAME}")
endif()

# Set include directory
find_path(MariaDBClient_INCLUDE_DIR mysql.h
HINTS ${mariadbclient_PKGCONF_INCLUDEDIR}
Expand Down

0 comments on commit 4446eb5

Please sign in to comment.