Build: Fixed finding mysql binary on first cmake run

Closes #28133
This commit is contained in:
Shauren
2022-07-19 00:33:07 +02:00
parent 763c758969
commit e9152679d7
3 changed files with 21 additions and 6 deletions

View File

@@ -78,6 +78,9 @@ if(NOT WITHOUT_GIT)
find_package(Git 1.7)
endif()
# find mysql client binary (needed by genrev)
find_package(MySQL OPTIONAL_COMPONENTS binary)
# Find revision ID and hash of the sourcetree
include(cmake/genrev.cmake)

View File

@@ -260,14 +260,26 @@ if(WIN32)
)
endif(WIN32)
unset(MySQL_lib_WANTED)
unset(MySQL_binary_WANTED)
set(MYSQL_REQUIRED_VARS "")
foreach(_comp IN LISTS MySQL_FIND_COMPONENTS)
if(_comp STREQUAL "lib")
set(MySQL_${_comp}_WANTED TRUE)
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_LIBRARY")
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_INCLUDE_DIR")
endif()
if(EXISTS "${MYSQL_LIBRARY}" AND EXISTS "${MYSQL_INCLUDE_DIR}")
set(MySQL_${_comp}_FOUND TRUE)
else()
set(MySQL_${_comp}_FOUND FALSE)
endif()
elseif(_comp STREQUAL "binary")
set(MySQL_${_comp}_WANTED TRUE)
if(MySQL_FIND_REQUIRED_${_comp})
list(APPEND MYSQL_REQUIRED_VARS "MYSQL_EXECUTABLE")
endif()
if(EXISTS "${MYSQL_EXECUTABLE}" )
set(MySQL_${_comp}_FOUND TRUE)
else()
@@ -283,24 +295,24 @@ unset(_comp)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MySQL
REQUIRED_VARS
MYSQL_LIBRARY
MYSQL_INCLUDE_DIR
${MYSQL_REQUIRED_VARS}
HANDLE_COMPONENTS
FAIL_MESSAGE
"Could not find the MySQL libraries! Please install the development libraries and headers"
)
unset(MYSQL_REQUIRED_VARS)
if(MYSQL_FOUND)
if(MySQL_lib_FOUND)
if(MySQL_lib_WANTED AND MySQL_lib_FOUND)
message(STATUS "Found MySQL library: ${MYSQL_LIBRARY}")
message(STATUS "Found MySQL headers: ${MYSQL_INCLUDE_DIR}")
endif()
if(MySQL_binary_FOUND)
if(MySQL_binary_WANTED AND MySQL_binary_FOUND)
message(STATUS "Found MySQL executable: ${MYSQL_EXECUTABLE}")
endif()
mark_as_advanced(MYSQL_FOUND MYSQL_LIBRARY MYSQL_EXTRA_LIBRARIES MYSQL_INCLUDE_DIR MYSQL_EXECUTABLE)
if(NOT TARGET MySQL::MySQL AND MySQL_lib_FOUND)
if(NOT TARGET MySQL::MySQL AND MySQL_lib_WANTED AND MySQL_lib_FOUND)
add_library(MySQL::MySQL UNKNOWN IMPORTED)
set_target_properties(MySQL::MySQL
PROPERTIES

View File

@@ -8,7 +8,7 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
find_package(MySQL REQUIRED COMPONENTS lib OPTIONAL_COMPONENTS binary)
find_package(MySQL REQUIRED COMPONENTS lib)
add_library(mysql INTERFACE)