Build libmariadb with Yocto - cmake

I am trying to make a recipe for a C++ app that uses libmariadb. While developing I was using vcpkg but now I want to use Yocto.
Here is the application_1.0.0.bb file:
# Metadata
SUMMARY = "Customer API Backend"
DESCRIPTION = "Customer API in C++ using gRPC"
# License is closed, no checksum to avoid warnings
LICENSE = "CLOSED"
LIC_FILE_CHKSUM = ""
DEPENDS = "protobuf protobuf-c protobuf-native grpc grpc-native openssl mariadb poco"
SRCREV = "${AUTOREV}"
SRC_URI = "git://git#gitlab.com/software/projects/embedded/application.git;protocol=ssh;branch=master;"
S = "${WORKDIR}/git"
inherit pkgconfig cmake
Here is the CMake part that poses problem with Yocto:
find_package(unofficial-libmariadb CONFIG REQUIRED)
find_package(Poco REQUIRED COMPONENTS Data DataMySQL)
target_link_libraries(database_api
PRIVATE
unofficial::libmariadb
Poco::DataMySQL
)
I get this error message during the configure step (CMake):
CMake Error at src/libraries/external_interfaces/database_api/CMakeLists.txt:20 (find_package):
Could not find a package configuration file probided by
"unofficial-libmariadb" with any of the following names:
unofficial-libmariadbConfig.cmake
unofficial-libmariadb-config.cmake
Add the installation prefix of "unofficial-libmariadb" to CMAKE_PREFIX_PATH
or set "unofficial-libmariadb_DIR" to a directory containing one of the
above files. If "unofficial-libmariadb" provides a separate development
package or SDK, be sure it has been installed.
I tried adding mariadb-native to the DEPENDS on the bitbake recipe but then I get this error messagewhen configuring mariadb-native`:
CMake Error at /home/oe-core/build/tmp/work/x86_64-linux/mariadb-native/10.7.5-r0/recipe-sysroot-native/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find GnuTLS (missing: GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR)
(Required is at least version "3.3.24")
Call Stack (most recent call first):
(...)
-- Configuring incomplete, errors occurred!

Ok I figured it out by using more recent versions of the mariadb recipes + vcpkg mariadb port patches:
For the mariadb-native build:
Add a mariadb-native_%.bbappend in a recipes-dbs/mysql/ folder in your layer:
DEPENDS:append = " gnutls-native fmt-native"
Alternative is to have the more recent mariadb-native_%.bb recipe as it is already included. If, like me, you have 10.7.4 or something, the bbappend is required.
For the unofficial-mariadb target:
Using Yocto's devtool on mariadb recipe, I just reproduced the patches that vcpkg port of libmariadb has (found here: https://github.com/microsoft/vcpkg/tree/master/ports/libmariadb). The one that matters is the modification to libmariadb/CMakeLists.txt (but from mariadb recipe this is libmariadb/libmariadb/CMakeLists.txt since this is a higher repo layer). This patch export unofficial-libmariadb and also uses the unofficial:: namespace. This makes my project compatible.

Related

Missing protobuf configuration when installing via ue4-conan

I'm trying to get gRPC running in Unreal Engine 4, using the conan-ue4cli tool. I use the provided grpc-ue4 recipe linked here: https://github.com/adamrehn/ue4-conan-recipes/tree/master/grpc-ue4
While running ue4 conan build "grpc-ue4" an error is thrown "Could not find a package configuration file provided by "Protobuf""
Output:
...
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Found c-ares: C:/Users/Redux Gamer/.conan/data/cares-ue4/1.16.1/adamrehn/4.27/package/7333dc905312a2df09e78e1a60d59e628a5f0321/lib/cmake/c-ares/c-ares-config.cmake (found suitable version "1.16.1", minimum required is "1.13.0")
CMake Error at cmake/protobuf.cmake:58 (find_package):
Could not find a package configuration file provided by "Protobuf" with any
of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
"Protobuf_DIR" to a directory containing one of the above files. If
"Protobuf" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:224 (include)
-- Configuring incomplete, errors occurred!
See also "C:/.conan/9d531a/1/CMakeFiles/CMakeOutput.log".
See also "C:/.conan/9d531a/1/CMakeFiles/CMakeError.log".
grpc-ue4/1.30.2#adamrehn/4.27:
grpc-ue4/1.30.2#adamrehn/4.27: ERROR: Package 'bf9f4e336e64d98ce96ba6aaac093ac1ff3705d4' build failed
grpc-ue4/1.30.2#adamrehn/4.27: WARN: Build folder C:\.conan\9d531a\1
ERROR: grpc-ue4/1.30.2#adamrehn/4.27: Error in build() method, line 98
cmake.configure(source_folder="grpc", args=self.cmake_flags())
ConanException: Error 1 while executing cd C:\.conan\9d531a\1 && ...
I'm running Windows 10, UE4.27, python 3.7.8, cmake 3.21.3. I tried searching for the missing protobuf-config.cmake but it also can't be found in the conan or project folder.
Any suggestions or pointers where to look would be greatly appreciated.
The responsible conan-file is here: https://github.com/adamrehn/ue4-conan-recipes/tree/master/grpc-ue4/1.30.2
This got broken with commit 865c38e99f694e63fd109ae06423472ebb7885a3 (see: https://github.com/adamrehn/ue4-conan-recipes/pull/8)
Reverting this change solved it for me.
To manually fix this:
Go to C:\Users\USERNAME.conan\data\grpc-ue4\1.30.2\adamrehn\4.27\export\conanfile.py and in line 51 change:
"-DProtobuf_DIR=" + os.path.join(protobuf.rootpath, "lib/cmake/protobuf"),
to
"-DProtobuf_DIR=" + os.path.join(protobuf.rootpath, "cmake"),
Then you need to run the command with the --no-cache parameter (otherwise the recipe will be replaced again by the original)
ue4 conan build grpc-ue4 --no-cache

Snakemake wrappers fails to open environment file: HTTP Error 404: Not Found

When using snakemake wrappers with snakemake version 5.5.2 like this:
rule bcf_to_vcf:
input:
"{prefix}.bcf"
output:
"{prefix}.vcf"
params:
"" # optional parameters for bcftools view (except -o)
wrapper:
"0.38.1/bio/bcftools/view"
I get the following error:
Building DAG of jobs...
WorkflowError:
Failed to open environment file https://bitbucket.org/snakemake/snakemake-wrappers/raw/0.38.1/bio/bcftools/view/environment.yaml:
HTTPError: HTTP Error 404: Not Found
Apparently, the wrapper files are no longer available on bitbucket.
TL/DR:
To use snakemake-wrappers version 0.38.1 and above, you need to use snakemake version 5.7.0 or higher.
What is going on:
Snakemake (and snakemake-wrappers) recently migrated from bitbucket to Github. This causes some minor inconvenience with the paths to the snakemake-wrappers repository used internally by snakemake. The easiest way to solve this is to update snakemake to version 5.7.0 or newer. These version already use the new paths to the Github version.
While the bitbucket repo of snakemake wrappers is still online, it only contains the snakemake-wrapper versions 0.38.0 and lower. To use a higher version of snakemake-wrappers (as 0.38.1 in the code above), you need a newer version of snakemake, which pulls workflow data from the Github version of snakemake-wrappers repo.

Yocto - Can't build library for host SDK

I've made a custom recipe for a third-party library.
It contains:
BBCLASSEXTEND =+ "native nativesdk"
The recipe builds a static library, depends on virtual/kernel and copies some headers - relatively simple.
I'm trying to install this into the host SDK for cross-compilation, but I'm having some issues.
When I try adding:
TOOLCHAIN_HOST_TASK_append = " nativesdk-<recipe>"
... to local.conf and run bitbake core-image-weston -c populate_sdk, BitBake completes, but the headers and library are absent from the host SDK (for my host's architecture).
When I try adding:
TOOLCHAIN_HOST_TASK_append = " <package>-staticdev"
... I get the following error:
package <package>-staticdev-1.11.0-r0.aarch64 does not have a compatible architecture
Any help would be appreciated.
As you don't need native part of recipe to run something on host (build machine) but target part, you should add the following line to add it to SDK:
TOOLCHAIN_TARGET_TASK_append = " <package>-staticdev <package>-dev"

How can I determine MAGICKCORE_QUANTUM_DEPTH and MAGICKCORE_HDRI_ENABLE during compilation?

I have a library that interfaces against ImageMagick 6. During compilation I get the below compilation warnings (promoted to errors by me).
I am aware that explicitly defining these values during compilation using -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0 will solve the issue (on my specific installation), however, as I am writing my CMake configuration files to be as portable as I can make them, this feels way to brittle and I really hope there is a better way.
Which brings me back to my question: Is there a way to determine MAGICKCORE_HDRI_ENABLE and MAGICKCORE_QUANTUM_DEPTH using cmake, bash or similar for the specific version of the library I am linking against?
/usr/include/ImageMagick-6/magick/magick-config.h:29:3: error: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Werror=cpp]
# warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default"
^
/usr/include/ImageMagick-6/magick/magick-config.h:30:3: error: #warning "this is an obsolete behavior please fix your makefile" [-Werror=cpp]
# warning "this is an obsolete behavior please fix your makefile"
^
/usr/include/ImageMagick-6/magick/magick-config.h:52:3: error: #warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-Werror=cpp]
# warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default"
^
/usr/include/ImageMagick-6/magick/magick-config.h:53:3: error: #warning "this is an obsolete behavior please fix yours makefile" [-Werror=cpp]
# warning "this is an obsolete behavior please fix yours makefile"
^
cc1plus: all warnings being treated as errors
While writing the question I came across an answer to this. I'll summarize it here as the other questions regarding this angle it slightly differently.
Imagemagick ships with an utility called Magick++-config on my installation (Ubuntu 16.04) I found this utility under /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick++-config. Below is the cmake code snipped I ended up using to extract the relevant build options.
find_package(ImageMagick 6.7 COMPONENTS Magick++ MagickCore)
if(ImageMagick_FOUND)
# Find Imagemagick Library directory
get_filename_component(MAGICK_LIB_DIR ${ImageMagick_MagickCore_LIBRARY} DIRECTORY)
# Find where Magick++-config lives
file(GLOB_RECURSE MAGICK_CONFIG FOLLOW_SYMLINKS ${MAGICK_LIB_DIR}/Magick++-config)
# Ask about CXX and lib flags/locations
set(MAGICK_CONFIG ${MAGICK_CONFIG} CACHE string "Path to Magick++-config utility")
execute_process(COMMAND "${MAGICK_CONFIG}" "--cxxflags" OUTPUT_VARIABLE MAGICK_CXX_FLAGS)
execute_process(COMMAND "${MAGICK_CONFIG}" "--libs" OUTPUT_VARIABLE MAGICK_LD_FLAGS)
# Add these to cache
set(MAGICK_CXX_FLAGS "${MAGICK_CXX_FLAGS}" CACHE string "ImageMagick configuration specific compilation flags." )
set(MAGICK_LD_FLAGS "${MAGICK_LD_FLAGS}" CACHE string "ImageMagick configuration specific linking flags.")
# Split into list:
string(REGEX MATCHALL "([^\ ]+)" MAGICK_CXX_FLAGS "${MAGICK_CXX_FLAGS}")
string(REGEX MATCHALL "([^\ ]+)" MAGICK_LD_FLAGS "${MAGICK_LD_FLAGS}")
# Remove trailing whitespace (CMAKE warns about this)
string(STRIP "${MAGICK_CXX_FLAGS}" MAGICK_CXX_FLAGS)
string(STRIP "${MAGICK_LD_FLAGS}" MAGICK_LD_FLAGS)
target_compile_options(<project> ${MAGICK_CXX_FLAGS})
target_link_libraries(<project> ${MAGICK_LD_FLAGS})
endif(ImageMagick_FOUND)
Source

FindPostgreSQL.cmake won't work on ubuntu

Ubuntu 12.04
CMake 2.8.9
Postgresql 9.2.2
I'm trying to get the FindPostgreSQL module to find /usr/include/postgresql/libpq-fe.h.
Here's what I have in my CMakeLists.txt:
find_package(PostgreSQL REQUIRED)
This is the error I get:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find PostgreSQL (missing: PostgreSQL_TYPE_INCLUDE_DIR) (found
version "9.2.2")
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPostgreSQL.cmake:155 (find_package_handle_standard_args)
CMakeLists.txt:7 (find_package)
I added the following lines before calling find_package but it didn't seem to have any effect.
set(PostgreSQL_ADDITIONAL_VERSIONS "9.2.2")
set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "/usr/include/postgresql")
I also tried googling for PostgreSQL_TYPE_INCLUDE_DIR but didn't find anything. What else can I try?
Make sure you've installed both libpq-dev\ and postgresql-server-dev-all (or specific version e.g. postgresql-server-dev-9.4)
$ dpkg --get-selections | grep -e "libpq-dev\|postgresql-server-dev"
in case you're missing some package
apt-get install libpq-dev postgresql-server-dev-all
should fix it.
After a bit more debugging I figured out that it's getting stuck trying to find pg_type.h
This file is located in /usr/include/postgresql/catalog/pg_types.h but the module is expecting to find it in /usr/include/postgresql/server/catalog/pg_types.h
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)
It works if I add postgresql to the PATH_SUFFIXES
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
postgresql
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)
On Ubuntu you can also work around that issue by calling cmake with having PostgreSQL_TYPE_INCLUDE_DIR defined like this:
cmake -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql/
See the bug report [1] for this issue and a potential fix [2]. Álso see the discussion about the reasoning behind the move on the debian mailinglist at [3].
On Ubuntu/Debian, starting with PostgreSQL 9.3 the header file pg_type.h
is moved to a separate package (from libpq-dev to postgresql-server-dev)
and consequently the file pg_type.h is moved to a new location
[1] https://gitlab.kitware.com/cmake/cmake/issues/17223
[2] https://gitlab.kitware.com/cmake/cmake/commit/d4fd30d8d8f5b9c4b5a110b4676cad2a19d7c314
[3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=314427
From Linux Mint 17.3 ("Rosa") with PostgreSQL 9.3, I had to adjust ilia choly's solution (interestingly, the suggested postgres entry in the list was already present in the file, but wasn't enough to fix things).
I had to edit /usr/share/cmake-2.8/Modules/FindPostgreSQL.cmake around line 114 and add postgresql/9.3 so that the find_path call looks like
find_path(PostgreSQL_TYPE_INCLUDE_DIR
NAMES catalog/pg_type.h
PATHS
# Look in other places.
${PostgreSQL_ROOT_DIRECTORIES}
PATH_SUFFIXES
postgresql/9.3
postgresql
pgsql/server
postgresql/server
include/server
# Help the user find it if we cannot.
DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
)