Using GPGME in Debian for C++ Application - c++

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)

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)

Related

Could not find a package configuration file provided by "boost_atomic"

I am compiling C/C++ to wasm with emscripten. And need boost library as well. Pretty new to emscripten and wasm
After installing emscripten and boost. I ran the following command
emconfigure cmake -DBoost_DEBUG=1
-Dboost_headers_DIR=../boost_1_71_0/build/lib/cmake/boost_headers-1.71.0
-DBoost_DIR=../boost_1_71_0/build/lib/cmake/Boost-1.71.0 -Dboost_program_options_DIR=../boost_1_71_0/build/lib/cmake/boost_program_options-1.71.0
-Dboost_system_DIR=../boost_1_71_0/build/lib/cmake/boost_system-1.71.0 -Dboost_thread_DIR=../boost_1_71_0/build/lib/cmake/boost_thread-1.71.0 -Dboost_unit_test_framework_DIR=../boost_1_71_0/build/lib/cmake/boost_unit_test_framework-1.71.0
-DZLIB_INCLUDE_DIR=${HOME}/.emscripten_ports/zlib/zlib-version_1 -DZLIB_LIBRARY=${HOME}/.emscripten_cache/asmjs -DBUILD_TESTING=0 -DBoost_USE_STATIC_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBUILD_EXEC=OFF -DBUILD_TESTING=OFF ..
I get the following error
CMake Error at /home/../boost_1_71_0/build/lib/cmake/boost_thread-1.71.0/boost_thread-config.cmake:91 (find_package):
Could not find a package configuration file provided by "boost_atomic"
(requested version 1.71.0) with any of the following names:
boost_atomicConfig.cmake
boost_atomic-config.cmake
Add the installation prefix of "boost_atomic" to CMAKE_PREFIX_PATH or set
"boost_atomic_DIR" to a directory containing one of the above files. If
"boost_atomic" provides a separate development package or SDK, be sure it
has been installed.
The boost_atomic-config.cmake is at /home/../boost_1_71_0/build/lib/cmake/boost_atomic-1.71.0/boost_atomic-config.cmake. How should I set the boost_atomic_DIR path to this file, as required above?
I added a flag -Dboost_atomic_DIR=/path/to/.cmake/file in the above command and it worked.

Private Headers issue compiling QtWebKit 5.212 against Qt 5.10.1

On Windows 10, Visual Studio 2015, I'm building QtWebKit (5.212) against Qt 5.10.1, and I'm running into an error during the configuration part of the build.
Here is the command line I use:
perl Tools\Scripts\build-webkit --qt --release --only-webkit --no-ninja --cmakeargs="-Thost=x64 -DCMAKE_GENERATOR_PLATFORM=x64" -G \"Visual Studio 14 2015 Win64\" --prefix=E:\Qt-5.10.1\QtWebKitBin -v
Here is the error:
-- Performing Test Qt5Gui_PRIVATE_HEADER_FOUND
-- Performing Test Qt5Gui_PRIVATE_HEADER_FOUND - Failed
CMake Error at Source/cmake/OptionsQt.cmake:75 (message):
Header private/qhexstring_p.h is not found. Please make sure that:
1. Private headers of Qt5Gui are installed
2. Qt5Gui_PRIVATE_INCLUDE_DIRS is correctly defined in Qt5GuiConfig.cmake
Call Stack (most recent call first):
Source/cmake/OptionsQt.cmake:612 (CHECK_QT5_PRIVATE_INCLUDE_DIRS)
Source/cmake/WebKitCommon.cmake:50 (include)
CMakeLists.txt:139 (include)
-- Configuring incomplete, errors occurred!
The private header that it's using to do the test does exist in the Qt5 include directory, as one would expect, in this location:
E:\Qt-5.10.1\QtBin\include\QtGui\5.10.1\QtGui\private\qhexstring_p.h
The Qt5GuiConfig.cmake file exists only in the E:\Qt-5.10.1\QtBin\lib\cmake\Qt5Gui directory of the Qt installation (not in the QtWebKit source installation). I don't know if it's making use of this in any way.
What do I need to do to make the build find this directory as desired? Adding 'include\QtGui\5.10.1\QtGui\' to the INCLUDE env var doesn't work, but I don't believe that's the correct solution anyway.
Here are the parts of my environment related to the Qt directories:
INCLUDE = ...;E:\Qt-5.10.1\QtBin\include;E:\Qt-5.10.1\qt-everywhere-src-5.10.1\include
LIB = ...;E:\Qt-5.10.1\QtBin\lib;E:\Qt-5.10.1\qt-everywhere-src-5.10.1\lib
PATH = E:\Qt-5.10.1\qt-everywhere-src-5.10.1\qtbase\bin;E:\Qt-5.10.1\qt-everywhere-src-5.10.1\gnuwin32\bin;E:\Qt-5.10.1\QtBin\bin;...
QtBin is the directory with my compiled Qt 5.10.1.
qt-everywhere-src-5.10.1 is the Qt 5.10.1 source package
Thanks in advance for any help. I couldn't find any answers searching Google or StackOverflow.
According to the wiki, you should try to define CMAKE_PREFIX_PATH to point to your Qt installation
For example :
perl Tools\Scripts\build-webkit --qt --release --only-webkit --no-ninja --cmakeargs="-Thost=x64 -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_PREFIX_PATH=c:\Qt\Qt5.6.0\5.6\msvc2015" -G \"Visual Studio 14 2015 Win64\" --prefix=E:\Qt-5.10.1\QtWebKitBin -v
Build on Windows using build-webkit fails because it was unable to find the location for this header file qhexstring_p.h. How to fix this error and although is not a standard way but it works.
Located the file qhexstring_p.h in your prefix directory, or your
preferred Qt Installation SDK
Go to this file Source\cmake\OptionsQt.cmake and change this
From this CHECK_QT5_PRIVATE_INCLUDE_DIRS(Gui private/qhexstring_p.h)
to this below
CHECK_QT5_PRIVATE_INCLUDE_DIRS(Gui
C:/SDK/qt5-5.7.0-vs2015/qt5-x86-static-release/include/QtGui/5.7.0/QtGui/private/qhexstring_p.h)
The path here must match the path to your Qt installation and to the exact location the missing file is located. This ensures the test to look for the private director for the Qt installation is successful.
Then locate the file Qt5GuiConfig.cmake in your Qt installation directory and set the variable Qt5Gui_PRIVATE_INCLUDE_DIRS to the location were you private headers are found with this below.
set(Qt5Gui_PRIVATE_INCLUDE_DIRS "${_qt5Gui_install_prefix}/include/QtGui/${Qt5Gui_VERSION_STRING}/QtGui" "${_qt5Gui_install_prefix}/include/QtCore/${Qt5Gui_VERSION_STRING}/QtCore")
And note this version QtWebKit (5.212) of is known to have several
bugs, so its best you go for those stable ones.
The Save and run
perl Tools\Scripts\build-webkit --qt --release --only-webkit --no-ninja --cmakeargs="-Thost=x64 -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_PREFIX_PATH=c:\Qt\Qt5.6.0\5.6\msvc2015" -G \"Visual Studio 14 2015 Win64\" --prefix=E:\Qt-5.10.1\QtWebKitBin -v
As you wanted, that should be able to run as expected.

Adding LLVM to my Cmake Project: Why are there hardcoded paths in LLVM's Cmake file?

I'm using LLVM/Clang in my C++ project. I can build and run everything fine with a Makefile.
I'm now trying to move to Cmake and I can't get things to work. Let me explain what I've done.
I'm following this tutorial:
http://llvm.org/docs/CMake.html#embedding
A relevant snippet from that webpage is:
From LLVM 3.5 onwards both the CMake and autoconf/Makefile build
systems export LLVM libraries as importable CMake targets.
Great! I'll go download LLVM 3.5 and I should be good to go. I went to the download page:
http://llvm.org/releases/download.html
and downloaded the pre-built binaries for Clang for Ubuntu 14.04 Linux.
Then, I added the following to my CMakeLists.txt file:
find_path (LLVM_DIR LLVM-Config.cmake
/home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
)
message(STATUS "LLVM_DIR = ${LLVM_DIR}")
find_package(LLVM REQUIRED CONFIG)
(This is the same as the tutorial, except I set LLVM_DIR since it is currently in a non-standard location.)
When I run cmake, I get the following error:
[dev#beauty:/path/to/project/build (develop)] $ cmake ..
-- LLVM_DIR = /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:50 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVMExports.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:53 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVM-Config.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
So Cmake seems to be finding LLVM's Cmake file, but Cmake is complaining about some path starting with /home/ben/.
Indeed, it appears that LLVM's LLVMConfig.cmake file has some absolute paths in it that are not relevant for my machine. For example:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ head ./share/llvm/cmake/LLVMConfig.cmake
# This file provides information and services to the final user.
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 5)
set(LLVM_VERSION_PATCH 0)
set(LLVM_PACKAGE_VERSION 3.5.0)
set(LLVM_COMMON_DEPENDS )
Who's ben and what's he doing in this file? He shows up in a few more places:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ grep ben ./share/llvm/cmake/LLVMConfig.cmake
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_INCLUDE_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/include")
set(LLVM_LIBRARY_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/lib")
set(LLVM_CMAKE_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake")
set(LLVM_TOOLS_BINARY_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/bin")
Needless to say, those paths do not exist on my machine. I'm confused as to why these files have these paths in them? Am I supposed to run a tool or something to change these paths for my machine? Or do I need to change them all manually?
EDIT: Out of curiosity, I manually changed all those paths to point to paths on my machine:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake ] $ sed -i -e's/.home.ben.development.llvm.3.5.final.Phase3.Release.llvmCore-3.5.0-final.install/\/home\/dev\/Downloads\/clang+llvm-3.5.0-x86_64-linux-gnu/g' *
After that, Cmake no longer complained and my build proceeded.
I'd still like to know why I needed to do that.
Sounds like a LLVM bug. Feel free to enter it: http://llvm.org/bugs
We just have to build with 'Ninja' instead of 'Unix Makefiles' and that's all

CMake FIND_PACKAGE succeeds but returns wrong path

I'm trying to have CMake 2.8.6 link to boost::program_options using the following code in my CMakeLists.txt
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES (${Boost_INCLUDE_DIR})
ADD_EXECUTABLE (segment segment.cpp)
TARGET_LINK_LIBRARIES (segment ${Boost_LIBRARIES})
The find command seems to succeed but passes the wrong directory to the linker. The package is actually in:
`/usr/lib64/libboost_program_options-mt.so.5`
but CMakeFiles/segment.dir/link.txt lists the following:
/cm/shared/apps/gcc/4.4.6/bin/c++ CMakeFiles/segment.dir/segment.cpp.o -o segment -rdynamic /usr/lib64/lib64/libboost_program_options-mt.so.5 -lpthread -lrt -Wl,-rpath,/usr/lib64/lib64
Note the extra lib64 in the path. Also, the -l flag in front of the path seems to be missing.
When running CMake it reports that it correctly finds the package, and the {$Boost_LIBRARIES} variable seems to list the correct libs:
Boost found.
Found Boost components:
program_options
${Boost_LIBRARIES} - optimized;boost_program_options-mt-shared;debug;boost_program_options-mt-shared-debug
The generated CMakeCache.txt file starts with:
//The directory containing a CMake configuration file for Boost.
Boost_DIR:PATH=/usr/lib64/boost
//Boost include directory
Boost_INCLUDE_DIR:FILEPATH=/usr/include
Which seems to be correct. But when running make it uses the path in link.txt above and I get the error:
make[2]: *** No rule to make target `/usr/lib64/lib64/libboost_program_options-mt.so.5', needed by `segment'. Stop.
make[1]: *** [CMakeFiles/segment.dir/all] Error 2
make: *** [all] Error 2
What might cause this extra injection of a subdir into the path? What might cause link.txt to be generated in this way? And how do I fix it (or work around it)?
This problem occurs when using some older versions of boost with cmake-2.8.6-rc2 or later, where the boost package finding code was changed.
The problem can be worked around by specifying -DBoost_NO_BOOST_CMAKE=ON on the cmake command line.
The actual commit where this problem is introduced is 7da796d1fdd7cca07df733d010cd343f6f8787a9, and can be viewed here.
The problem is with the boost-devel distributed file: /usr/lib64/boost/Boost-relwithdebinfo.cmake
The cmake-2.6 package does not use this file at all, because the FindBoost.cmake file returns (correct) full-paths to boost libraries. The cmake28-2.8.8 FindBoost.cmake file returns library strings like "boost_date_time-mt-shared", which are targets defined in /usr/lib64/boost/Boost-relwithdebinfo.cmake.
At the very top of /usr/lib64/boost/Boost-relwithdebinfo.cmake, a variable named _IMPORT_PREFIX is defined from the location of the cmake file itself, and then used like so:
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RelWithDebInfo".
#----------------------------------------------------------------
# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)
# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# Import target "boost_date_time-static" for configuration "RelWithDebInfo"
SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
)
This sets _IMPORT_PREFIX to "/usr/lib64", which is concatenated with another string that has /lib64/ in it as well. I found that if I simply change the file to include a 3rd GET_FILENAME_COMPONENT call, it works fine. Like so:
#----------------------------------------------------------------
# Generated CMake target import file for configuration "RelWithDebInfo".
#----------------------------------------------------------------
# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)
# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# Import target "boost_date_time-static" for configuration "RelWithDebInfo"
SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
)
This seems to be an issue with CMake 2.8.6 on CentOS. When doing the same with 2.6.4 or 2.8.3 it works correctly. Also with 2.8.7 on OS X it also works correctly.
I also see the problem on the pre-compiled cmake version 2.8.8 using CentOS 64-bit 6.2
I noticed this issue on cmake version 2.8.11.2 with boost-1.41.0-18.el6.x86_64
The approved answer does not seem satisfactory because appending this define to the cmake runtime I get:
CMake Warning:
Manually-specified variables were not used by the project:
Boost_NO_BOOST_CMAKE
I can't seem to comment or downvote due to not participating in stackoverflow enough. That is a chicken and egg problem!
I also can't seem to upvote the explanation by Kai Meyer. However, I think this really explains the problem.
From what I am gathering it seems that in summary, FindBoost.cmake provided by CMake seems to all of a sudden fail to find Boost, so the find code is now searching via the boost provided script for cmake, which in turn has a bug and seems to not return the correct path.
while building package from AUR following prefix helped to find Boost:
BOOST_ROOT=/usr
example:
BOOST_ROOT=/usr makepkg -si

Point CMake project to specific include file

I am trying to build OpenCV 2.3.0 with FFMPEG enabled. Since Ubuntu 11.10 only supplies libavcodec/format with version 0.7 and the ticket #1020(link below) indicates that it should work with 0.8.
If I try to compile I get the following error:
[ 18%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
In file included from /home/chris/src/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/foo/src/OpenCV-2.3.0/modules/highgui/src/cap_ffmpeg_impl.hpp:103:36: fatal error: libavformat/avformat.h: No such file or directory
compilation terminated.
This file lives in /opt/linux64-debug/include/ffmpeg/libavformat/avformat.h. I tried pointing make at that with CMAKE_INCLUDE_{DIRECTORY,PATH}, CMAKE_PREFIX_PATH and CMAKE_LIBRARY_PATH. None of that worked. ( I always used the path /opt/linux64-debug/include/ffmpeg.)
https://code.ros.org/trac/opencv/ticket/1020
Try the include_directories() command. In my CMakeLists.txt file, I use it like this:
include_directories(. /opt/special/headers/in/here)
add_executable(helloworld helloworld.c)
I have never had any problems with it.