Using GPGME in Debian for C++ Application

2019-09-19 11:12发布

I would like to use GPGME for key generation and encryption in my C++ application. However, while trying to get started, I got stuck with a problems:

I dowloaded the dev package for my debian system. Now I would like to tell my compiler (gcc in Qt Creator) where to find the library with cmake using the tool mentioned in the documentation. But I don't know how to add gpgme-config --cflags --libs to my compiler flags. This didn't work:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} `gpgme-config --cflags --libs` ")

When I try to build the app the compiler can't find gpgme-config:

c++: error: $(gpgme-config: File or Directory not found
c++: error: unrecognized command line option ‘--cflags’
c++: error: unrecognized command line option ‘--libs)’

Anyway executing gpgme-config --cflags --libs on command line DOES give me a result:

-L/usr/lib/x86_64-linux-gnu -lgpgme -lassuan -lgpg-error

I know the documentation also mentions Automake and libtool to make this process easier. But I neither used Automake or libtool before.


UPDATE:

I also tried to use a FindGpgme.cmake file for GPGME. But the first file I used required several other cmake files, which I also downloaded. I put them in the same directory as FindGpgme.cmake. The main cmake file (FindGpgme.cmake) was found, but MacroEnsureVersion and MacroBoolTo01 not. My change to my CMakeLists.txt was the following:

include(cmake_modules/FindGpgme.cmake)
find_package(Gpgme)

I tried relative and absolute path to the other files in FindGpgme.cmake. Same problem - cmake can't find them. My second try was with the file I found on gitweb. The error was:

CMake Error at cmake_modules/FindGpgme.cmake:376 (set_package_properties):
  Unknown CMake command "set_package_properties".
Call Stack (most recent call first):
  CMakeLists.txt:7 (include)

I have absolutely no glue how to fix that set_package_properties problem.


UPDATE 2

I added

include(FeatureSummary)

to my CMakeLists.txt as proposed by kfunk. Now I get the following error:

CMake Warning at CMakeLists.txt:9 (find_package): By not providing "FindGpgme.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Gpgme", but CMake did not find one.

Could not find a package configuration file provided by "Gpgme" with any of the following names:

GpgmeConfig.cmake
gpgme-config.cmake

Add the installation prefix of "Gpgme" to CMAKE_PREFIX_PATH or set
"Gpgme_DIR" to a directory containing one of the above files. If "Gpgme" provides a separate development package or SDK, be sure it has been installed.

Even the message description seams pretty detailed I don't know how to add the FindGpgme.cmake to CMAKE_MODULE_PATH or how to add the requested prefix to CMAKE_PREFIX_PATH. The dev package however is definitely installed (using package manager)

标签: c++ cmake gpgme
1条回答
迷人小祖宗
2楼-- · 2019-09-19 11:19

I'd suggest to use a proper CMake find script to look up the GPGME installation:

Example here: https://quickgit.kde.org/?p=kwallet.git&a=blob&h=7a092104ba0604b0606c4662750b8b32c5c3e2c6&f=cmake%2FFindGpgme.cmake&o=plain

Then something like this in your CMake code (untested):

find_package(Gpgme)
include_directories(${GPGME_INCLUDES})
target_link_libraries(YOURTARGET ${GPGME_VANILLA_LIBRARIES)
查看更多
登录 后发表回答