Point CMake project to specific include file - build

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.

Related

Crow microframework - CMake Error: The following variables are used in this project, but they are set to NOTFOUND

Here is the full error message:
Error CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1/CROW_INCLUDE_DIRS
used as include directory in directory C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1 C:\Users\DELL\source\repos\CMakeProject1\ used as include directory in directory C
I am trying to use the Crow microframework but can't seem to make it work. I have downloaded the Crow package off of Github : https://github.com/ipkn/crow and used CMake to run a hello world from the Crow port. This is what I got in my .txt file
cmake_minimum_required (VERSION 3.8)
find_path(CROW_INCLUDE_DIRS "crow.h")
add_executable (CMakeProject1 "example_with_all.cpp" "crow_all.h")
target_include_directories(CMakeProject1 PRIVATE ${CROW_INCLUDE_DIRS})
My header file is crow_all.h which contains all the libraries and this is where the error is located. The compiler does not recognize all the "#include" used in this header file. I believed it would work because I had downloaded the entire Github repo and included it in my files.
My cpp file just includes the header file and does a Hello World.
I am a beginner at CMake, thank you for the help!
You should check out https://github.com/CrowCpp/Crow. It's an actively maintained version of the framework with a new build system (you should be able to just link it via CMake)
P.S. I suggest you use the master branch since it has quite a few improvements over the latest release.
Wow, crow's build is so broken that its own instructions fail on my system... it also hasn't been updated since 2017 (five years...). Assuming you still want to use it, I would just copy their amalgamated header, crow_all.h, into my source tree under, say, third_party/crow/crow_all.h and then write:
cmake_minimum_required(VERSION 3.22)
project(example)
add_executable(app "example_with_all.cpp")
target_include_directories(app PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/third_party/crow")

cmake + cpp: No such file or directory

I've I'm trying to build this "Hello World" wxWidgets example on Linux, using the following cmake script:
cmake_minimum_required (VERSION 2.6)
project (wxL)
find_package(wxWidgets 3.0.0 REQUIRED
COMPONENTS base core net xml html adv qa richtext
)
file(GLOB SOURCES "src/*.cpp")
add_executable(wxL ${SOURCES})
Building the project yields this error:
src/wxL.cpp:3:10: fatal error: wx/wxprec.h: No such file or directory
The file specified in the include, wx/wxprec.h can be found on disk at this location:
/usr/include/wx-3.0/wx/wxprec.h
Furthermore, another program that I have built from source includes the same file (also using cmake) and builds just fine.
So, how do I use cmake to tell the compiler that the file should be included from somewhere in the system directories?
I know I'm missing something basic, but I can't figure out what.
Although you've found the package, your executable does not know anything about it.
For the executable to compile correctly, it needs to find header files for your package together with the .so / .a files. Following example should get you started:
include_directories(${wxWidgets_INCLUDE_DIRS})
add_executable(wxL <add-source-files-here>)
target_link_libraries(wxL ${wxWidgets_LIBRARIES}) // links wxWidgets libraries to your executable
Please note that using glob is not a recommended way of adding source files to your project.

cmake: You have called ADD_LIBRARY for library cryptopp without any source files

Windows 64bit using cmake to compile c++ project: github.com/iHateInventNames/synergy-through-usb
I fixed a previous issue in this post: Compile issues: LIBUSB_1 with cmake project on Windows
So when I hit cmake now I get the following error:
> cmake .
-- Found libusb-1.0:
-- - Includes: C:/local/libs/libusbx
-- - Libraries: C:/local/libs/libusbx/libusb-1.0.lib
You have called ADD_LIBRARY for library cryptopp without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
-- Generating done
-- Build files have been written to: C:/local/projects/synergy-usb/synergy-through-usb-master
What does this mean? how can I solve it / move on?
Links to the install instructions
both goto 404 errors...
http://synergy-project.org/projects/synergy/wiki/Readme/?hl=pm
http://synergy-project.org/projects/synergy/wiki/Compiling/?hl=pm
Based on a quick browse through the project's CMakeLists, it would seem you're supposed to unpack tools/cryptopp562.zip into a directory called tools/cryptopp562 before running CMake. This should definitely have been mentioned in the projects' installation instructions, if any.
More precisely, the file tools/CMakeLists.txt contains this code:
set(cpp_dir cryptopp562)
file(GLOB cpp_src ${cpp_dir}/*.cpp)
# ...
add_library(cryptopp STATIC ${cpp_src})
This means that the variable cpp_src is filled with source files taken from directory cryptopp562 (relative to the CMakeList's directory, i.e. tools), and is then used to define the source files of library cryptopp. However, the project's distribution only contains tools/cryptopp562.zip. Unpacking that into directory tools/cryptopp562 should provide the missing files.

Using GPGME in Debian for C++ Application

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)

C++ cmake throwing error

I am running sample programs in g2o graph library in linux using cmake. I am getting the following error. The file i am running has the following code
#include <Eigen/Core>
which is causing the error.
[ 3%] Building CXX object data_fitting/CMakeFiles/circle_fit.dir/circle_fit.o g2o/trunk/g2o/examples/data_fitting/circle_fit.cpp:27:2 3: fatal error: Eigen/Core: No such file or directory
compilation terminated.
make[2]: *** [data_fitting/CMakeFiles/circle_fit.dir/circle_fit.o] Error 1
make[1]: *** [data_fitting/CMakeFiles/circle_fit.dir/all] Error 2
I am new to using cmake. Is this because of an error in the CMakeLists.txt file?
INCLUDE_DIRECTORIES(${CSPARSE_INCLUDE_DIR})
ADD_EXECUTABLE(circle_fit
circle_fit.cpp
)
SET_TARGET_PROPERTIES(circle_fit PROPERTIES OUTPUT_NAME circle_fit${EXE_POSTFIX})
TARGET_LINK_LIBRARIES(circle_fit core solver_csparse)
ADD_EXECUTABLE(curve_fit
curve_fit.cpp
)
SET_TARGET_PROPERTIES(curve_fit PROPERTIES OUTPUT_NAME curve_fit${EXE_POSTFIX})
TARGET_LINK_LIBRARIES(curve_fit core)
I am struggling with this for a day now. The tutorials available for cmake are also not helping much. How can I fix this error?
I tried adding include statement for /usr/include/eigen3 as the first answer suggested. But I cannot find any file named eigen3 in the /usr/include directory.
Is there any other possible path? How can I find it in linux?
Try to include the eigen include folder in cmake.
INCLUDE_DIRECTORIES( /usr/include/eigen3 )
It worked for me on the same error.
The readme says that you need to install libeigen3-dev (https://svn.openslam.org/data/svn/g2o/trunk/README)
If you are on Ubuntu user install it using apt-get or synaptic.
And for Windows :
"If you are compiling on Windows, please download Eigen3 and extract it.
Within cmake-gui set the variable G2O_EIGEN3_INCLUDE to that directory"
Do read the 'readme' :)