How to use FFTW with cmake on windows? - build

I am building my project for Visual Studio with CMake. I used this lines in my CMakeList.txt to include FFTW3.
find_library(FFTW_LIBRARY
NAMES fftw3 fftw)
set(FFTW_LIBRARIES "${FFTW_LIBRARY}")
I got this error from CMake:
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:
FFTW_LIBRARY
linked by target "windows_SHT" in directory C:/...
I think I did not install fftw properly. I got .dll .lib and .h files in a folder but I don't know how to explain to CMake where is the library.

Specify additional paths for find_library to use.
See: http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_library
You will need to include the path to your custom FFTW installation.
A similar technique will need to be used when you use find_file to locate the headers
http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_file

Related

Visual Studio's CMake with vcpkg: Error gdal is not found

I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.
Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.
After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:
However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>
Where should I further investigate?
As others have said vcpkg integrate install and vcpkg.cmake don't work together the reason being:
set_target_properties(${name} PROPERTIES VS_USER_PROPS do_not_import_user.props)
set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
this deactivates the integration. The reason to deactivate the integration is so that you don't write an incomplete CMakeLists.txt (e.g. missing the include directory or not linking all required libraries).
As such replace find_library(GDAL gdal) with find_package(GDAL REQUIRED) and target_link_libraries against the target GDAL::GDAL (https://cmake.org/cmake/help/v3.17/module/FindGDAL.html)

CMake "find_package" command on a package that was not installed is unexpectedly successful

I am following chapter-02/recipe-06 in "CMake Cookbook". This particular example requires the Eigen C++ libraries.
I attempted to build the example and got the error that Eigen was not found.
CMake Error at CMakeLists.txt:9 (find_package):
Could not find a package configuration file provided by "Eigen3" (requested
version 3.3) with any of the following names:
Eigen3Config.cmake
eigen3-config.cmake
Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
"Eigen3_DIR" to a directory containing one of the above files. If "Eigen3"
provides a separate development package or SDK, be sure it has been
installed.
This was expected because the library was not installed on my system.
I then downloaded the ".zip" file for the Eigen libraries and unzipped it to an arbitrary location outside of my project. I created a "build" folder in the Eigen directory and ran cmake .. in the "build" folder. (I only ran cmake - I did NOT build or install the package.)
After running CMake on the Eigen build directory, I went back to the example code for "recipe-06" and it was magically able to find the Eigen library and built successfully even though Eigen was never built or installed.
Somehow just running CMake in the Eigen project made CMake aware of the Eigen libraries location. After doing this, any projects that do find_package to find Eigen3 somehow get the ${Eigen3_DIR} variable defined and are able to find it.
Looking at the CMake documentation for find_package I don't see any explanation of why this works. Eigen is not in any of the typical locations that find_package searches. According to the documentation it looks like it should NOT be found.
Even more interesting - it doesn't matter where I put Eigen on my system. I can put it literally anywhere and it will still find it.
According to everything I see in the documentation it should not be found... but it is found. So the question is how? Why does this work?
Additional info: I am using CMake version 3.13.3
There are 2 "origins" of XXXConfig.cmake files, used internally by find_package() call.
Usually, XXXConfig.cmake file is produced when the project is installed, and the file contains information about installed libraries and headers.
But CMake provides also an export() command, which allows to export build tree.
export(PACKAGE <name>)
Store the current build directory in the CMake user package registry for package <name>. The find_package command may consider the directory while searching for package <name>.
Eigen's CMakeLists.txt uses export() command, so the project becomes detectable with find_package just after running cmake for Eigen.

How to build tesseract4.0 from source code in windows using cmake?

I already tried the pre-compiled Leptonica binary link but I read here that I have to build this from source only. So I tried building Leptonica from source.
I downloaded the source code of Leptonica from this [link].(https://github.com/tesseract-ocr/tesseract) Then I tried to build this code using CMake. To build I used CMake GUI. In source-code path I gave where CMakeLists.txt is located and in cross compiling option I gave this scripts\buildsystems\vcpkg.cmake from this link.
But I am getting this error
CMake Error at C:/vcpkg/scripts/buildsystems/vcpkg.cmake:247 (_find_package):
Could not find a package configuration file provided by "Leptonica" (requested version 1.74) with any of the following names:
LeptonicaConfig.cmake
leptonica-config.cmake
Add the installation prefix of "Leptonica" to CMAKE_PREFIX_PATH or set
"Leptonica_DIR" to a directory containing one of the above files.
If "Leptonica" provides a separate development package or SDK,
be sure it has been installed.
For this I build leptonica separately and generated this LeptonicaConfig.cmake file as asked in this error. But now I have to change the CMakeLists.txt and set Leptonica_DIR to the directory where my this LeptonicaConfig.cmake located. I don't know how to do this I tried adding this line in cmakelists file set(Leptonica_DIR="C:\Leptonica"). But this doesn't work, may be this is wrong.
I am really stuck, I am using tesseract4.0 and Leptonica 17.6 and really new to this building process.

How to correctly include Dlib in Eclipse project?

I'm currently trying to use the Dlib c++ library in my own project. So I included the main folder of dlib to my project. I also added the dlib/all/source.cpp to my project. When I try to compile the code of the svm_c_ex.cpp example in my own test.cpp file, I only get:
fatal error: dlib/svm.h: No such file or directory
The section Dlib: How to compile didn't help me and I couldn't find further information online. Any help is appreciated!
You need to compile the DLib library first, using the instructions from the website.
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake is a famous tool to build software on multiple platforms. It generates required files first and then you can compile the library using those generated files later.
You need to add the "include" directories (the folders where the headers exist) in your project configuration. I'm quite not sure of where exactly to add in Eclipse CDT.
After that, your program gives linker error because the the header files only contain skeletons of your library code. Actual implementation need to be linked with "linker options" in project properties. You need to add your library's .lib/.a files with your program. I don't exactly remember where is linker options in CDT (I'm talking in Visual Studio context)
Basically for any library you want to use in any C++ project:
You need to include HEADERS in your project properties
You need to link to actual implementation of the library. You can read about
static and dynamic libraries (Someone on SO must have given an
awesome explanation)

Using GDCM via CMake

I downloaded source of GDCM 2.4.1 and used CMake 2.8.12.1 and Visual Studio 2010 to build the libraries. I want to use GDCM in my C++ project.
Unfortunately, it seems that after building the GDCM solution with VS, there are only the lib-files in the bin folder, but no typical "include" folder with the header files, what I usually expect. Thus, I can't integrate GDCM libaries in my own project (I tried to use FindPackage(GDCM) in my own CMakeproject, but header files can't be found).
I do not want to copy the header files manually or target the source directory of GDCM.
Does anybody know help?
I found out that the problem has something to do with VTK, I also use the this library in my project. So I need to enable "GDCM_USE_VTK" in CMake of GDCM. That option leads to a compiler error when I try to build the "INSTALL" subproject in the GDCM solution:
CMake Error at cmake_install.cmake:31 (FILE): file INSTALL cannot find "D:/Libs/VTK_5.6.0/BIN/bin/vtkCommon.dll".
I took a look in the VTK directory and found out that the path mentioned above does not exists. Instead the dll is located in:
D:\Libs\VTK_5.6.0\BIN\bin\Release\vtkCommon.dll or
D:\Libs\VTK_5.6.0\BIN\bin\Debug\vtkCommon.dll
That means GDCM solution does not know the dll is located in a special debug or release folder. If I disable "GDCM_USE_VTK" everything works fine and all files will be copied to the target folder. But I do need the VTK dll.
Any thoughts?
Michael
For anyone who ever touches the same problem, here's the final solution. Build "ALL_BUILD" in the GDCM solution, then integrate GDCM libs in your CMakeLists.txt the following way:
FIND_PACKAGE(GDCM REQUIRED)
IF(GDCM_FOUND)
INCLUDE(${GDCM_USE_FILE})
SET(GDCM_LIBRARIES
gdcmcharls
gdcmCommon
gdcmDICT
gdcmDSED
gdcmexpat
gdcmgetopt
gdcmIOD
gdcmjpeg12
gdcmjpeg16
gdcmjpeg8
gdcmMEXD
gdcmMSFF
gdcmopenjpeg
gdcmzlib
socketxx
vtkgdcm
Rpcrt4)
ELSE(GDCM_FOUND)
MESSAGE(FATAL_ERROR "Cannot find GDCM, did you set GDCM_DIR?")
ENDIF(GDCM_FOUND)