FetchContent with mariadb-connector-cpp

I’m using FetchContent to satisfy the mariadb-connector-cpp dependency for poco. I’m cross-compiling, so I don’t want the library to be installed on my normal system place.

include(FetchContent)
FetchContent_Declare(
    mariadb-connector-cpp
    GIT_REPOSITORY https://github.com/mariadb-corporation/mariadb-connector-cpp.git
    GIT_TAG 1.0.2
)

FetchContent_MakeAvailable(mariadb-connector-cpp)

During the build, I get this error:

CMake Error: File /home/dfr/m9kapps/src/maconncpp.rc.in does not exist.

because of this line in the mariadb-connector-cpp CMakeLists.txt file:

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/Version.h.in

It looks like the mariadb-connector-cpp CMakeLists.txt file wants you to cd into the root of their cmake project and do the normal; mkdir build; cd build; cmake …

I’m still trying to come up to speed with cmake. Is this telling me that this library is not compatible with FetchContent? Is there something I need to do so that CMAKE_SOURCE_DIR in the mariadb-connector-cpp project will point to the correct location?

Thanks!
Todd

Their use of ${CMAKE_SOURCE_DIR} is a typical symptom of a project that doesn’t support being added directly to another parent project. You won’t be able to use FetchContent with that project until they replace their use of CMAKE_SOURCE_DIR with a variable that is relative to the top of their source tree, not the top of the whole build. That usually means CMAKE_CURRENT_SOURCE_DIR, or sometimes a project-specific variable like PROJECT_SOURCE_DIR or <projectName>_SOURCE_DIR.

Thanks for your quick response! Can you suggest an alternative approach? I need Marian-connector-cpp to be found by FetchContent while it’s building poco.

I would first submit the patch upstream. You can then use that PR branch as your source until a release is made with that fix (and any others that might be relevant).

1 Like