Using GDCM via CMake - c++

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)

Related

Compiling and Linking to Visual Studio 2022 using OpenCV source code built as Win32 from CMake C++

I'm trying to use OpenCV with Dear ImGui in Visual Studio 2022. I'm new to C/C++ libraries and building in general, so I'm unsure if I'm doing anything right. ImGui uses 32-bit architecture and I've used Cmake gui to compile the source code as Win32. I think I have the compiled source code, but it seems to be different than downloading the pre-built libraries. File Explorer Screenshot. I've added the bin to PATH environmental variable, and in Visual Studio tried adding \include to Include Directories, \lib or \lib\Debug to Library Directories, and opencv_world460d.lib to Additional Dependencies. The program still runs, but it doesn't seem to include anything related to OpenCV in the #include files. I found a few .dll files in bin\Debug, but I'm not sure if I should bother with that. I think I could move the source code into the project, but I'm fairly certain that isn't the proper way to do it. Any help would be appreciated.
I needed to run the install target:
You may have built the project, but probably you didn't run the install target. Try running cmake --build <build_dir> --config Release and then cmake --install <build_dir> --config Release, where <build_dir> is a placeholder for the path to the build dir shown in the screenshot. The latter command probably requires admin privileges. Probably best to check the docs of the lib, if there's a step by step instruction for building & installing the whole thing. –
fabian

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)

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 use FFTW with cmake on windows?

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

Integrate ITK (Insight Toolkit) into own project

i am having problems integrating ITK - Insight Toolkit into another image processing pipeline. ITK itself is a medical image processing toolkit and uses cmake as build system. My image pipeline project uses cmake as well. According to the user manual of ITK it is favorable to use the "UseITK.cmake" file in the build (out of source) directory of ITK. You can do that by adding the following lines the CMakeList.txt of your own project.
# 'SET(ITK_DIR ...)' if 'FIND_PACKAGE(ITK REQUIRED)' fails
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
My problem is, this approach points to the current installtion of ITK, but i have to integrate itk completly into my project, without dependencies outside my project.
Is there a build option in the cmake build system of itk, which dumps/delivers all the header and lib files into a build directory, so i can place them into my project on my own.
I have a lib and header include structure i do not want to break. I already tried to to manually copy the lib and header files into my project but it didn't work out.
I am new to itk and cmake so this question might sound vague. I hope you guys can help me anyway.
Thanks in advance!
Best regards,
zhengtonic
I don't know if you're still having the problem, but here's an easy way:
Build the ITK project, and then "make install" (or build the INSTALL.vcproj project in VS), and it will write to a directory you pass as CMAKE_INSTALL_PREFIX while configuring your project. This directory will contain /bin, /lib and /include. You can import those into your project directly.
Using CMAKE_INSTALL_PREFIX to point to you base directory is the best solution.
When you issue "make install" all the headers/configurationfiles/libraries will be copied over.
C:/Program Files (x86)/ITK is value of CMAKE_INSTALL_PREFIX for ITK and set automatically.