How can I use cmake's find_packge(OpenCV) on gitlab - c++

I am using cmake to compile a c++ and OpenCV project. and I want to run my tests on Gitlab but got some errors. My question is: How can I use find_package(OpenCV REQUIRED) in CMakeLists.txt on gitlab? this is my CMakeLists.txt: (by the way, it works correct locally on my Linux machine .)
# cmake minimum requiredments
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
# project name
project(imageEnhancer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler specific extensions
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Catch2 QUIET)
if (NOT Catch2_FOUND)
message("Catch2 not found")
include(FetchContent)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.11.0
)
FetchContent_MakeAvailable(catch2)
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")
endif()
# search for OpenMP
find_package(OpenMP REQUIRED)
# search for OpenCV
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# add a library to the project using the specified source files
add_library(opencv STATIC include/opencvtest.h src/opencvtest.cpp)
# PUBLIC -> targets that link to this target get that include directory
target_include_directories(opencv PUBLIC include PRIVATE src)
# link to the imported target provided by the FindOpenMP moudule
target_link_libraries(opencv PUBLIC OpenMP::OpenMP_CXX)
# Create executable with name imageEnhancer
add_executable(imageEnhancer main.cpp)
# linke to the imported target provided by the FindOpenMP module
target_link_libraries(imageEnhancer PUBLIC OpenMP::OpenMP_CXX ${OpenCV_LIBS})
but I got the following error:
$ cd project
$ mkdir -p build
$ cd build
$ cmake ..
-- The CXX compiler identification is GNU 10.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Catch2 not found
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
CMake Error at CMakeLists.txt:31 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/builds/davood_hadiannejad/algorithm-engineering-lab/project/build/CMakeFiles/CMakeOutput.log".
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1
and I tried to solve it like, but it didn't work
if (NOT Catch2_FOUND)
message("Catch2 not found")
include(FetchContent)
FetchContent_Declare(
OpenCV
GIT_REPOSITORY https://github.com/opencv/opencv.git
)
FetchContent_MakeAvailable(OpenCV)
list(APPEND CMAKE_MODULE_PATH "${OpenCV_SOURCE_DIR}/contrib")
endif()
any suggestion? thanks in advance

Related

After `libigl` update to ver 2.4.0 I can't build anymore

My CMakeLists.txt file for my old libigl testing project contains the piece below:
project(libigl)
set(LIBIGL_HOME $ENV{HOME}/apps/libigl)
set(CMAKE_PREFIX_PATH ${LIBIGL_HOME})
set(CMAKE_MODULE_PATH ${LIBIGL_HOME}/cmake)
find_package(${PROJECT_NAME} CONFIGS libigl.cmake REQUIRED)
if(${PROJECT_NAME}_FOUND)
message("-- Found ${PROJECT_NAME}")
else()
message(FATAL_ERROR "${PROJECT_NAME} is not found")
endif()
I tried to build this project with the new version 2.4.0 of the libigl library and got this message:
CMake Error at /home/hekto/apps/libigl/cmake/libigl.cmake:5 (message):
You included libigl.cmake directly from your own project. This behavior is
not supported anymore. Please add libigl to your project via
add_subdirectory(<path_to_libigl>). See the libigl example project for
more information: https://github.com/libigl/libigl-example-project/
Call Stack (most recent call first):
CMakeLists.txt:43 (find_package)
So, they recommend to use the add_subdirectory command for client projects. I looked at the CMakeLists.txt file from the recommended GitHub example project and couldn't find the add_subdirectory command:
cmake_minimum_required(VERSION 3.16)
project(example)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Libigl
include(libigl)
# Enable the target igl::glfw
igl_include(glfw)
# Add your project files
file(GLOB SRC_FILES *.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC igl::glfw)
How should I build with the new version 2.4.0 of the libigl?
OS: Ubuntu 20.04.5 LTS
Compiler: g++ (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

Cmake: pkg_check_modules error: Package '...', required by 'virtual:world', not found

I am trying to build a c++ project with Netbeans in Windows but during the pre-built process an error relating to the CMakeLists I used comes out. Here is the error output:
cd 'E:\Yifan\Hiwi-FSD\FluCo1\Sourcecode\branch_HighLevelUmstrukturierung\High-Level\FCU-Interface\build-dev'
C:/msys64/mingw64/bin/cmake.exe -G Unix Makefiles -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=E:/Yifan/Hiwi-FSD/FluCo1/Sourcecode/branch_HighLevelUmstrukturierung/High-Level/FCU-Interface/nbproject/private/tools/localhost/MinGW_1/gcc.exe -DCMAKE_CXX_COMPILER=E:/Yifan/Hiwi-FSD/FluCo1/Sourcecode/branch_HighLevelUmstrukturierung/High-Level/FCU-Interface/nbproject/private/tools/localhost/MinGW_1/g++.exe -DCMAKE_C_FLAGS_DEBUG=-g3 -gdwarf-2 -DCMAKE_CXX_FLAGS_DEBUG=-g3 -gdwarf-2 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPROJECT_SUFFIX=-dev -DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=TRUE -DCMAKE_PREFIX_PATH=E:\Yifan\Hiwi-FSD\FluCo1\Libraries\fsd-libs\trunk\build-dev\install ..
-- SVN Revision Number is
-- FCU-Interface-dev PROJECT_SOURCE_DIR = E:/Yifan/Hiwi-FSD/FluCo1/Sourcecode/branch_HighLevelUmstrukturierung/High-Level/FCU-Interface
-- FCU-Interface-dev Build directory = E:/Yifan/Hiwi-FSD/FluCo1/Sourcecode/branch_HighLevelUmstrukturierung/High-Level/FCU-Interface/build-dev
-- Checking for module 'fsd-io-dev'
-- Package 'fsd-io-dev', required by 'virtual:world', not found
CMake Error at C:/msys64/mingw64/share/cmake-3.20/Modules/FindPkgConfig.cmake:561 (message):
A required package was not found
Call Stack (most recent call first):
C:/msys64/mingw64/share/cmake-3.20/Modules/FindPkgConfig.cmake:783 (_pkg_check_modules_internal)
CMakeLists.txt:17 (pkg_check_modules)
-- Configuring incomplete, errors occurred!
See also "E:/Yifan/Hiwi-FSD/FluCo1/Sourcecode/branch_HighLevelUmstrukturierung/High-Level/FCU-Interface/build-dev/CMakeFiles/CMakeOutput.log".
PRE-BUILD FAILED (exit value 1, total time: 5s)
And the CMakelists file is shown below:
cmake_minimum_required(VERSION 3.12)
SET(FSD_LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../Libraries)
include("${FSD_LIB_DIR}/CMakeSuffixBase.cmake")
project("FCU-Interface${PROJECT_SUFFIX}" VERSION 0.1)
SET(ENV{PKG_CONFIG_PATH} ${FSD_LIB_DIR}/fsd-libs/trunk/build${PROJECT_SUFFIX}/install/lib/pkgconfig)
include("${FSD_LIB_DIR}/CMakeBase.cmake")
include(FindPkgConfig)
Subversion_GET_REVISION(${CMAKE_SOURCE_DIR} SVN_REV)
message(STATUS "SVN Revision Number is ${SVN_REV}")
message(STATUS "${PROJECT_NAME} PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
message(STATUS "${PROJECT_NAME} Build directory = ${CMAKE_BINARY_DIR}")
find_package(PkgConfig REQUIRED)
pkg_check_modules(FSD_IO REQUIRED IMPORTED_TARGET fsd-io${PROJECT_SUFFIX})
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION "${PROJECT_VERSION}+${SVN_REV}"
)
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/>
)
target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../Framework_Seitz>
)
target_link_libraries(${PROJECT_NAME} PRIVATE
Threads::Threads
PkgConfig::FSD_IO)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
The PROJECT_SUFFIX is -dev. I reckon that the problem is, the file "fsd-io-dev.pc" cannot be found. But I already have it under the directory "E:\Yifan\Hiwi-FSD\FluCo1\Libraries\fsd-libs\trunk\build-dev\install\lib\pkgconfig". What should I do to let it be found? Thanks in advance!!!

cmake error for header-only library: `include could not find load file`

I've been trying to change a makefile c++ project into a cmake project, and I've been having som difficulty. cmake seems to be looking for stuff in /usr/local/lib/ instead of /usr/local/include/ and I'm not sure why that is.
This library is header-only, and so I've been following this tutorial My header-only library in include seems to "build" fine, but I keep getting the following error when I try to generate a makefile to build my example program:
me:~/pf/examples/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/lib/cmake/pf/pfConfig.cmake:27 (include):
include could not find load file:
/usr/local/lib/cmake/pf/pf_exampleTargets.cmake
Call Stack (most recent call first):
CMakeLists.txt:15 (find_package)
examples/CMakeLists.txt creates another fresh project:
project(pf_example)
cmake_minimum_required (VERSION 3.12)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 17)
# "install" pf
find_package(pf CONFIG REQUIRED)
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp})
message("${SOURCES}")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} pf::pf)
The root directory CMakeLists.txt file is more complicated. It's the one that was adapted from the tutorial I mentioned above:
cmake_minimum_required(VERSION 3.12)
project("pf" VERSION 1.0.1
DESCRIPTION "A header only c++ template library for fast particle filtering."
HOMEPAGE_URL "https://github.com/tbrown122387/pf")
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(
${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include)
To install this header only library, before I try to build the examples project, I typed the following commands into the command line:
cd ~/pf
mkdir build
cd build/
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/include
sudo cmake --build . --config Release --target install -- -j $(nproc)
I didn't post it, but there's also a file cmake/pfconfig.cmake.in that is verbatim copied from the tutorial above.
Your install prefix is specified as /usr/local/include so the files would be installed as:
headers into /usr/local/include/include
libraries into /usr/local/include/libs
cmake stuff into /usr/local/include/share/${PROJECT_NAME}/cmake
Those paths are just wrong. Just set CMAKE_INSTALL_PREFIX=/usr/local (ie. remove include) and install it inside /usr/local/ tree.
A few took care of this issue.
in CMakeLists.txt change install(DIRECTORY ${PROJECT_SOURCE_DIR}/include DESTINATION include) to install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/pf DESTINATION include) so the files don't clutter up the installation locations. This also requires creating pf/include/pf and moving all the files in pf/include to pf/include/pf.
Follow advice in #KamilCuk's answer.
In examples/CMakeLists.txt change file(GLOB SOURCES ${PROJECT_NAME}/*.{h,cpp}) to file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/*.h ${CMAKE_SOURCE_DIR}/*.cpp)
Also note that my /usr/local/lib and /usr/local/include were quite cluttered up due to my numerous earlier failed attempts, so I deleted a bunch of files in there and re-installed fresh.

Vcpkg Pango CMake build fails missing header file

I am trying to install Wt using vcpkg, and pango is one of the dependencies. However, I am having serious issues trying to make it build correctly. Here is what the terminal outputs:
Starting package 1/2: pango:x64-osx
Building package pango[core]:x64-osx...
-- Using cached /Users/jackhogan/Desktop/Code/Utilities/vcpkg/downloads/pango-1.40.11.tar.xz
-- Using source at /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/src/1.40.11-f997ae867d
-- Configuring x64-osx-dbg
-- Configuring x64-osx-rel
-- Building x64-osx-dbg
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:136 (message):
Command failed: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/downloads/tools/cmake-3.17.2-osx/cmake-3.17.2-Darwin-x86_64/CMake.app/Contents/bin/cmake --build . --config Debug --target install -- -v
Working Directory: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/x64-osx-dbg
See logs for more information:
/Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/install-x64-osx-dbg-out.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_build_cmake.cmake:91 (vcpkg_execute_build_process)
scripts/cmake/vcpkg_install_cmake.cmake:24 (vcpkg_build_cmake)
ports/pango/portfile.cmake:25 (vcpkg_install_cmake)
scripts/ports.cmake:76 (include)
Error: Building package pango:x64-osx failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `.\vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
Package: pango:x64-osx
Vcpkg version: 2020.02.04-unknownhash
Additionally, attach any relevant sections from the log files above.
Here is the out file the terminal references:
-- The C compiler identification is AppleClang 11.0.3.11030032
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Link-time dependencies:
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libintl.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libglib-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libgobject-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libgmodule-2.0.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libcairod.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libcairo-gobjectd.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libfreetyped.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libfontconfig.a
-- /Users/jackhogan/Desktop/Code/Utilities/vcpkg/installed/x64-osx/debug/lib/libharfbuzz.a
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jackhogan/Desktop/Code/Utilities/vcpkg/buildtrees/pango/x64-osx-dbg
Here is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(pango C)
set(PANGO_LIB_SUFFIX 1.0)
set(PANGO_DLL_SUFFIX 1)
set(GLIB_LIB_VERSION 2.0)
if(WIN32)
configure_file(./config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/config.h COPYONLY)
else()
configure_file(./config.h.unix ${CMAKE_CURRENT_BINARY_DIR}/config.h COPYONLY)
endif()
if (WIN32)
# Set utf-8 charset to avoid compile error C2001
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
endif()
add_definitions(-DHAVE_CONFIG_H)
include_directories(. ./pango ${CMAKE_CURRENT_BINARY_DIR})
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
# find libintl
find_path(LIBINTL_INCLUDE_DIR libintl.h)
find_library(LIBINTL_LIBRARY NAMES libintl intl)
endif()
# find glib
find_path(GLIB_INCLUDE_DIR glib.h)
find_library(GLIB_GLIB_LIBRARY glib-${GLIB_LIB_VERSION})
find_library(GLIB_GOBJECT_LIBRARY gobject-${GLIB_LIB_VERSION})
find_library(GLIB_GMODULE_LIBRARY gmodule-${GLIB_LIB_VERSION})
set(GLIB_LIBRARIES ${GLIB_GLIB_LIBRARY} ${GLIB_GOBJECT_LIBRARY} ${GLIB_GMODULE_LIBRARY})
# find cairo
find_path(CAIRO_INCLUDE_DIR cairo.h)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(CAIRO_SUFFIX d)
endif()
find_library(CAIRO_LIBRARY
NAMES
cairo${CAIRO_SUFFIX}
cairo-static${CAIRO_SUFFIX})
find_library(CAIRO_GOBJECT_LIBRARY cairo-gobject${CAIRO_SUFFIX})
set(CAIRO_LIBRARIES ${CAIRO_LIBRARY} ${CAIRO_GOBJECT_LIBRARY})
# find fontconfig
find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h)
find_library(FONTCONFIG_LIBRARY fontconfig)
# find freetype
find_path(FREETYPE_INCLUDE_DIR ft2build.h)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(FT_SUFFIX d)
endif()
find_library(FREETYPE_LIBRARY freetype${FT_SUFFIX})
# find harfbuzz
find_path(HARFBUZZ_INCLUDE_DIR harfbuzz/hb.h)
find_library(HARFBUZZ_LIBRARY harfbuzz)
if (APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
link_libraries(${COREFOUNDATION_LIBRARY})
endif()
set(FONT_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR} ${FONTCONFIG_INCLUDE_DIR} ${HARFBUZZ_INCLUDE_DIR}/harfbuzz)
set(FONT_LIBRARIES ${FREETYPE_LIBRARY} ${FONTCONFIG_LIBRARY} ${HARFBUZZ_LIBRARY})
macro(pango_add_module MODULE_NAME)
add_library(${MODULE_NAME} ${ARGN})
target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIR} ${LIBINTL_INCLUDE_DIR})
target_link_libraries(${MODULE_NAME} ${LIBINTL_LIBRARY} ${GLIB_LIBRARIES})
target_compile_definitions(${MODULE_NAME} PRIVATE
G_LOG_DOMAIN="Pango" PANGO_ENABLE_BACKEND PANGO_ENABLE_ENGINE
G_DISABLE_SINGLE_INCLUDES SYSCONFDIR="/dummy/etc" LIBDIR="/dummy/lib")
target_compile_definitions(${MODULE_NAME} PRIVATE HAVE_CAIRO_FREETYPE=1)
set_target_properties(${MODULE_NAME} PROPERTIES
DEFINE_SYMBOL PANGO_EXPORTS
OUTPUT_NAME ${MODULE_NAME}-${PANGO_DLL_SUFFIX}
ARCHIVE_OUTPUT_NAME ${MODULE_NAME}-${PANGO_LIB_SUFFIX})
install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
endmacro()
pango_add_module(pango
pango/break-arabic.c
pango/break-indic.c
pango/mini-fribidi/fribidi.c
pango/mini-fribidi/fribidi_char_type.c
pango/mini-fribidi/fribidi_types.c
pango/break.c
pango/ellipsize.c
pango/fonts.c
pango/glyphstring.c
pango/modules.c
pango/pango-attributes.c
pango/pango-bidi-type.c
pango/pango-color.c
pango/pango-context.c
pango/pango-coverage.c
pango/pango-emoji.c
pango/pango-engine.c
pango/pango-fontmap.c
pango/pango-fontset.c
pango/pango-glyph-item.c
pango/pango-gravity.c
pango/pango-item.c
pango/pango-language.c
pango/pango-layout.c
pango/pango-markup.c
pango/pango-matrix.c
pango/pango-renderer.c
pango/pango-script.c
pango/pango-tabs.c
pango/pango-utils.c
pango/reorder-items.c
pango/shape.c
pango/pango-enum-types.c)
if(WIN32)
pango_add_module(pangowin32
pango/pangowin32.c
pango/pangowin32-fontcache.c
pango/pangowin32-fontmap.c
pango/pangowin32-shape.c)
target_link_libraries(pangowin32 usp10 pango gdi32)
endif()
pango_add_module(pangoft2
pango/pangofc-font.c
pango/pangofc-fontmap.c
pango/pangofc-decoder.c
pango/pangofc-shape.c
pango/pangoft2.c
pango/pangoft2-fontmap.c
pango/pangoft2-render.c
pango/pango-ot-buffer.c
pango/pango-ot-info.c
pango/pango-ot-ruleset.c
pango/pango-ot-tag.c)
target_link_libraries(pangoft2 pango ${FONT_LIBRARIES})
target_include_directories(pangoft2 PRIVATE ${FONT_INCLUDE_DIRS})
list(APPEND PANGO_CAIRO_SOURCES
pango/pangocairo-fcfont.c
pango/pangocairo-fcfontmap.c
pango/pangocairo-context.c
pango/pangocairo-font.c
pango/pangocairo-fontmap.c
pango/pangocairo-render.c)
if(WIN32)
list(APPEND PANGO_CAIRO_SOURCES
pango/pangocairo-win32font.c
pango/pangocairo-win32fontmap.c)
endif()
pango_add_module(pangocairo ${PANGO_CAIRO_SOURCES})
list(APPEND PANGO_CAIRO_LIBRARIES ${CAIRO_LIBRARIES} pango pangoft2 ${FONT_LIBRARIES})
if (WIN32)
list(APPEND PANGO_CAIRO_LIBRARIES pangowin32)
endif()
target_link_libraries(pangocairo ${PANGO_CAIRO_LIBRARIES})
target_include_directories(pangocairo PRIVATE ${CAIRO_INCLUDE_DIR} ${FONT_INCLUDE_DIRS})
if(NOT PANGO_SKIP_HEADERS)
install(FILES
pango/pango.h
pango/pango-attributes.h
pango/pango-bidi-type.h
pango/pango-break.h
pango/pango-context.h
pango/pango-coverage.h
pango/pango-engine.h
pango/pango-font.h
pango/pango-fontmap.h
pango/pango-fontset.h
pango/pango-glyph.h
pango/pango-glyph-item.h
pango/pango-gravity.h
pango/pango-item.h
pango/pango-language.h
pango/pango-layout.h
pango/pango-matrix.h
pango/pango-modules.h
pango/pango-renderer.h
pango/pango-script.h
pango/pango-tabs.h
pango/pango-types.h
pango/pango-utils.h
pango/pango-version-macros.h
pango/pangocairo.h
pango/pangowin32.h
pango/pango-features.h
pango/pango-enum-types.h
pango/pangofc-decoder.h
pango/pangofc-font.h
pango/pangofc-fontmap.h
pango/pango-ot.h
pango/pangoft2.h
DESTINATION include/pango)
endif()
message(STATUS "Link-time dependencies:")
message(STATUS " " ${LIBINTL_LIBRARY})
foreach(GL ${GLIB_LIBRARIES})
message(STATUS " " ${GL})
endforeach()
foreach(CL ${CAIRO_LIBRARIES})
message(STATUS " " ${CL})
endforeach()
foreach(FL ${FONT_LIBRARIES})
message(STATUS " " ${FL})
endforeach()
What could the problem be and how could I solve it? Vcpkg uses Clang but I also have GCC installed, so I could switch to it if necessary.
UPDATE
I ran some commands and found out that it couldn't find hb-glib.h. However, I already have glib and harfbuzz installed. I am even able to find the missing header file. What could be the cause of this issue?
Well, contrary to my expectations, just copying hb-glib.h to the pango source folder and building worked.

Torch CMake Error at CMakeLists.txt:10 (find_package) in C++

I am trying to create a Eclipse C++ project by CMake which calls torch/torch.h . I run cmake -G "Eclipse CDT4 - Unix Makefiles" ./ to create a Eclipse project, but I get this error:
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
Could not find a package configuration file provided by "Torch" with any of
the following names:
TorchConfig.cmake
torch-config.cmake
Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
"Torch_DIR" to a directory containing one of the above files. If "Torch"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
In which CMakeLists.txt is located in the current directory that has:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)
find_package(Torch REQUIRED)
add_executable(test test.cpp)
target_link_libraries(test "${TORCH_LIBRARIES}")
set_property(TARGET test PROPERTY CXX_STANDARD 11)
Apparently, it cannot find TorchConfig.cmake and torch-config.cmake files; although, I have TorchConfig.cmake in /home/afshin/libtorch/share/cmake/Torch. I added the corresponding path into the CMakeLists.txt file by testing each of:
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake/Torch;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch/share/cmake;${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "/home/afshin/libtorch;${CMAKE_MODULE_PATH}")
set(Torch_DIR "/home/afshin/libtorch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake/Torch;${Torch_DIR}")
set(Torch_DIR "/home/afshin/libtorch/share/cmake;${Torch_DIR}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake/Torch;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake;${DCMAKE_PREFIX_PATH}")
set(DCMAKE_PREFIX_PATH "/home/afshin/libtorch;${DCMAKE_PREFIX_PATH}")
But, it did not help and I still get same error.
I appreciate any help or comments.
I also tried the cmake-gui and I get same error:
Thanks,
Afshin
I was able to solve the problem by editing the CMakeLists.txt as:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test_cmake)
set(CMAKE_PREFIX_PATH "/home/afshin/libtorch/share/cmake/Torch")
find_package(Torch REQUIRED)
add_executable(test_cmake ./src/test_cmake.cpp)
target_link_libraries(test_cmake "${TORCH_LIBRARIES}")
set_property(TARGET test_cmake PROPERTY CXX_STANDARD 11)
Alternatively, using the cmake-gui also I was able to solve the problem by the following setting:
by hitting configure, and then generate.
Finally, I imported this project into Eclipse by selecting Makefile Project With Existing Code. This code is compiled and built successfully.
The following modified CMakeLists.txt file works without the apparently missing TorchConfig.cmake (also missing in the vcpkg installation here). I recommend Microsoft's vcpkg for cross-platform packages (c++ libraries) management (usage here). But the code is vcpkg independent: one can set TORCH_BASE_PATH (or Torch_INCLUDE_DIR and Torch_LIBRARIES) to the proper paths.
#[[
tested with:
- CMake 3.13
- Visual Studio Community Edition 15.9.4
(CMake generator: "Visual Studio 15 2017 Win64")
- torch-th library installed with vcpkg
generic: vcpkg install torch-th
for macOS: vcpkg install torch-th:x64-osx-dynamic
x64-osx-dynamic triplet must be created: x64-osx + "set(VCPKG_LIBRARY_LINKAGE dynamic)"
for Windows: vcpkg install torch-th:x64-windows
- easy torch sample: https://apaszke.github.io/torch-internals.html
]]
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(test)
# cannot work without a "package configuration file" (TorchConfig.cmake)
# so we replace it with find_path and find_library
#find_package(Torch REQUIRED)
#[[
the environement variable VCPKG_ROOT used here, contains the path to vcpkg installation folder
replace the two paths with your paths to TH installation
usage: #include "TH/TH.h"
]]
set(TORCH_BASE_PATH "$ENV{VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}")
message(STATUS TORCH_BASE_PATH=${TORCH_BASE_PATH})
set(Torch_INCLUDE_DIR "${TORCH_BASE_PATH}/include")
set(Torch_LIBRARIES "${TORCH_BASE_PATH}/lib")
# target_link_libraries is to be preferred
#link_directories(${Torch_LIBRARIES})
find_library(LIBRARY_TORCH TH HINTS ${Torch_LIBRARIES})
#[[
even simpler
if you use the vcpkg toolchain file "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
find_path(Torch_INCLUDE_DIR TH/TH.h)
find_library(LIBRARY_TORCH TH)
]]
add_executable(test test.cpp)
target_include_directories(test PRIVATE ${Torch_INCLUDE_DIR})
target_link_libraries(test ${LIBRARY_TORCH})
set(CMAKE_CXX_STANDARD 11)
#set_property(TARGET test PROPERTY CXX_STANDARD 11)