1

I am setting CMAKE to include QGLViewer for a Qt5 project. However as soon as I try to compile the project CMAKE stops with the following 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: QGLVIEWER_LIBRARY linked by target "sfm" in directory /home/emanuele/sfm

QGLViewer is present on the following path: usr/include/QGLViewer as it is possible to see from this print screen:

Print Screen of the File Path This is the file path

And here is how I set the path on CMAKE:

CMAKE File Path This is the file path in CMAKE

Additionally I found this source that was helpful for understanding how to declare the lib. Also this post was useful to point me in the correct route, but still not working.

Below the most important CMAKE part that is causing the issue:

cmake_minimum_required(VERSION 3.11)
project(sfm)

########### options ###############
SET(USE_QT TRUE CACHE BOOL)
########### END options ###########

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
set(CMAKE_INCLUDE_CURRENT_DIR ON)

########### OpenMP ################
find_package(OpenMP)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
########### END OpenMP ############

########### OpenCV ################
set (OpenCV_DIR /home/emanuele/opencv/build)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
list(APPEND LINK_LIBRARIES ${OpenCV_LIBS})
########### END OpenCV ############

########### Qt 5 ##################
IF (USE_QT)
  ADD_DEFINITIONS("-DUSE_QT")
  find_package(Qt5Widgets REQUIRED)
  find_package(Qt5Xml REQUIRED)
  find_package(Qt5OpenGL REQUIRED)

  include_directories(${Qt5Widgets_INCLUDE_DIRS}
      ${Qt5Xml_INCLUDE_DIRS}
      ${Qt5OpenGL_INCLUDE_DIRS}
  )
  list(APPEND LINK_LIBRARIES Qt5::Widgets Qt5::Xml Qt5::OpenGL)
  set(CMAKE_AUTOMOC ON)
  set(CMAKE_AUTOUIC ON)

  include_directories(src/ui/mainwindow src/ui/widgets)

  find_package(OpenGL REQUIRED)
  find_library(QGLVIEWER_LIBRARY
      NAMES qglviewer-qt5 qglviewer QGLViewer QGLViewer2)
  list(APPEND LINK_LIBRARIES ${QGLVIEWER_LIBRARY}  ${OPENGL_LIBRARIES})
ENDIF (USE_QT)
########### END Qt 5 ##############

########### sources ###############
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
add_executable(sfm ${SOURCE_FILES})
########### END sources ###########

########### headers ###############
include_directories(src)
########### END headers ###########

########### link libraries ########
target_link_libraries(sfm ${LINK_LIBRARIES})
########### END link libraries ####

I expect CMAKE to compile but the actual result I have is shown in the print screen below keeping me from moving ahead:

Print Screen of the Error This is the file path

Emanuele
  • 2,194
  • 6
  • 32
  • 71

1 Answers1

2

You should set the path of qglviewer library in CMAKE_PREFIX_PATH variable

or you may integrate it as a new target , using qglviewer tar gz archive as input :

set(QGLVIEWER_FILES ${CMAKE_BINARY_DIR}/libQGLViewer-2.7.1/QGLViewer/qglviewer.h)

get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)

add_custom_command(OUTPUT ${QGLVIEWER_FILES}
  COMMAND  tar xzf "${CMAKE_CURRENT_SOURCE_DIR}/libQGLViewer-2.7.1.tar.gz" --strip 1
  COMMAND ${QT_QMAKE_EXECUTABLE} -o QMakefile 
  COMMAND make -f QMakefile 
#  COMMAND ${CMAKE_COMMAND} -E touch ${LIBFOO_TAR_HEADERS}
  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/libQGLViewer-2.7.1"
  DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/libQGLViewer-2.7.1.tar.gz"
  COMMENT "Unpacking libQGLViewer-2.7.1.tar.gz"
  VERBATIM
)

add_custom_target(qglviewer_untar DEPENDS ${QGLVIEWER_FILES})

add_library(qglviewer SHARED IMPORTED)
add_dependencies(qglviewer qglviewer_untar)

# link qglviewer
set_target_properties(qglviewer PROPERTIES
                      IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libQGLViewer-2.7.1/QGLViewer/libQGLViewer-qt5.so"
                      INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/libQGLViewer-2.7.1")
sancelot
  • 1,905
  • 12
  • 31