pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.26k stars 2.14k forks source link

PocoDataMySQL CMake configuration file fails to find MySQL client library #3028

Open fishnet37222 opened 4 years ago

fishnet37222 commented 4 years ago

When using the following CMakeLists.txt file, CMake gives the error shown below.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(sqltest VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)

find_package(Poco REQUIRED DataMySQL)
include_directories(${Poco_INCLUDE_DIRECTORIES})

add_executable(sqltest main.cpp)
target_link_libraries(sqltest ${Poco_LIBRARIES})

CMake error message:

[cmake] CMake Error at CMakeLists.txt:9 (add_executable):
[cmake]   Target "sqltest" links to target "MySQL::client" but the target was not
[cmake]   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
[cmake]   an ALIAS target is missing?

I am able to work around the issue by modifying the PocoDataMySQLTargets.cmake file so the block starting at line 53 appears as follows:

# Create imported target Poco::DataMySQL
find_package(PkgConfig QUIET REQUIRED)
pkg_check_modules(MYSQL REQUIRED QUIET mysqlclient)
add_library(Poco::DataMySQL STATIC IMPORTED)

set_target_properties(Poco::DataMySQL PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "THREADSAFE;NO_TCL"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/include;${MYSQL_INCLUDE_DIRS}"
  INTERFACE_LINK_LIBRARIES "Poco::Data;${MYSQL_LIBRARIES}"
)
Bjoe commented 3 years ago

In https://github.com/pocoproject/poco/blob/f810bd0b4129b2330e4a23ccf4d304be6ba36583/Data/MySQL/cmake/PocoDataMySQLConfig.cmake#L2 it should be add:

find_dependency(MySQL)

But cmake doesn't provide a FindMySQL.cmake, so poco should installd it. But what happens when there is a FindMySQL.cmake installed from the MySQL project ....

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 60 days since being marked as stale.

LockDragonBorn commented 1 month ago

find your Poco sources dir,it has a dir named cmake,copy FindMySQL.cmake to /usr/share/cmake-/Modules。 then find_package(MySQL REQUIRED) before find_package(Poco).