Building OsgQtQuick on Ubuntu 14.04

The following section in OsgQtQuick‘s CMakeLists.txt:

find_package(OpenSceneGraph 3.0 REQUIRED
  osg
  osgQt
  osgDB
  osgGA
  osgManipulator
  osgUtil
  osgViewer
  osgText)

results in CMake searching for FindOpenSceneGraph.cmake file:

strace cmake ../../osgqtquick/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install |& grep -i OpenSceneGraph
access("/home/dmitry/examples/osgqtquick/cmake/FindOpenSceneGraph.cmake", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake", R_OK) = 0
access("/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake", R_OK) = 0
stat("/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake", {st_mode=S_IFREG|0644, st_size=7438, ...}) = 0
open("/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake", O_RDONLY) = 3
read(3, "# - Find OpenSceneGraph\n# This m"..., 8192) = 7438
read(3, "/* -*-c++-*- OpenSceneGraph - Co"..., 4096) = 3495
read(3, "/* -*-c++-*- OpenSceneGraph - Co"..., 8191) = 3495
  Could NOT find OpenSceneGraph (missing: OPENSCENEGRAPH_LIBRARIES
  OPENSCENEGRAPH_INCLUDE_DIR OSG_FOUND OSGQT_FOUND OSGDB_FOUND OSGGA_FOUND
  /usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake:187 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
access("/usr/share/cmake-2.8/Modules/FindOpenSceneGraph.cmake", R_OK) = 0

It cannot find OpenSceneGraph libraries because there is a strange code in Findosg_functions.cmake included from FindOpenSceneGraph.cmake:

function(OSG_FIND_LIBRARY module library)
   string(TOUPPER ${module} module_uc)

   find_library(${module_uc}_LIBRARY
       NAMES ${library}
       HINTS
            ENV ${module_uc}_DIR
            ENV OSG_DIR
            ENV OSGDIR
            ENV OSG_ROOT
            ${${module_uc}_DIR}
            ${OSG_DIR}
       PATH_SUFFIXES lib
       PATHS
            /sw # Fink
            /opt/local # DarwinPorts
            /opt/csw # Blastwave
            /opt
            /usr/freeware
   )

   find_library(${module_uc}_LIBRARY_DEBUG
       NAMES ${library}d
       HINTS
            ENV ${module_uc}_DIR
            ENV OSG_DIR
            ENV OSGDIR
            ENV OSG_ROOT
            ${${module_uc}_DIR}
            ${OSG_DIR}
       PATH_SUFFIXES lib
       PATHS
            /sw # Fink
            /opt/local # DarwinPorts
            /opt/csw # Blastwave
            /opt
            /usr/freeware
   )

   if(NOT ${module_uc}_LIBRARY_DEBUG)
      # They don't have a debug library
      set(${module_uc}_LIBRARY_DEBUG ${${module_uc}_LIBRARY} PARENT_SCOPE)
      set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARY} PARENT_SCOPE)
   else()
      # They really have a FOO_LIBRARY_DEBUG
      set(${module_uc}_LIBRARIES
          optimized ${${module_uc}_LIBRARY}
          debug ${${module_uc}_LIBRARY_DEBUG}
          PARENT_SCOPE
      )
   endif()
endfunction()

it assigns OSGDB_LIBRARIES, for example, a value like ‘optimizedOSGDB_LIBRARY_NOTFOUNDdebugPathToTheLibd“. I replaced all the code above with the following:

function(OSG_FIND_LIBRARY module library)
   string(TOUPPER ${module} module_uc)

   find_library(${module_uc}_LIBRARY
       NAMES ${library} ${library}d
       HINTS
            ENV ${module_uc}_DIR
            ENV OSG_DIR
            ENV OSGDIR
            ENV OSG_ROOT
            ${${module_uc}_DIR}
            ${OSG_DIR}
       PATH_SUFFIXES lib64
       PATHS
            /sw # Fink
            /opt/local # DarwinPorts
            /opt/csw # Blastwave
            /opt
            /usr/freeware
   )

   set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARY} PARENT_SCOPE)

endfunction()

and did the same corrections in FindOpenThreads.cmake, note that I also replaced ‘lib’ with ‘lib64’. Probably there should be more complicated code that works differently for Debug and Release build types, but I need only Debug at the moment. And after that CMake succeeded:

cmake ../../osgqtquick/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install -DOpenSceneGraph_DEBUG=1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/dmitry/examples/install/lib64:/home/dmitry/examples/install/lib
-- The CXX compiler identification is GNU 4.7.3
-- 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
-- [ FindOpenSceneGraph.cmake:85 ] Components = osg;osgQt;osgDB;osgGA;osgManipulator;osgUtil;osgViewer;osgText;OpenThreads
-- [ FindOpenSceneGraph.cmake:100 ] Detected OSG_INCLUDE_DIR = /home/dmitry/examples/install/include
-- [ FindOpenSceneGraph.cmake:143 ] Detected version 3.4.0
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osg  )
-- Found osg: /home/dmitry/examples/install/lib/libosgd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgQt  )
-- Found osgQt: /home/dmitry/examples/install/lib/libosgQtd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgDB  )
-- Found osgDB: /home/dmitry/examples/install/lib/libosgDBd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgGA  )
-- Found osgGA: /home/dmitry/examples/install/lib/libosgGAd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgManipulator  )
-- Found osgManipulator: /home/dmitry/examples/install/lib/libosgManipulatord.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgUtil  )
-- Found osgUtil: /home/dmitry/examples/install/lib/libosgUtild.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgViewer  )
-- Found osgViewer: /home/dmitry/examples/install/lib/libosgViewerd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(osgText  )
-- Found osgText: /home/dmitry/examples/install/lib/libosgTextd.so  
-- [ FindOpenSceneGraph.cmake:157 ] Calling find_package(OpenThreads  )
-- Found OpenThreads: /home/dmitry/examples/install/lib/libOpenThreadsd.so  
-- Found OpenSceneGraph: /home/dmitry/examples/install/lib/libosgd.so;/home/dmitry/examples/install/lib/libosgQtd.so;/home/dmitry/examples/install/lib/libosgDBd.so;/home/dmitry/examples/install/lib/libosgGAd.so;/home/dmitry/examples/install/lib/libosgManipulatord.so;/home/dmitry/examples/install/lib/libosgUtild.so;/home/dmitry/examples/install/lib/libosgViewerd.so;/home/dmitry/examples/install/lib/libosgTextd.so;/home/dmitry/examples/install/lib/libOpenThreadsd.so (found suitable version "3.4.0", minimum required is "3.0") 
-- ***OSGDB_LIBRARY: /home/dmitry/examples/install/lib/libosgDBd.so
-- ***OSGDB_LIBRARY_DEBUG: 
-- ***OSGDB_LIBRARIES: /home/dmitry/examples/install/lib/libosgDBd.so
-- ***OPENTHREADS_LIBRARIES: /home/dmitry/examples/install/lib/libOpenThreadsd.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dmitry/examples/build/osgqtquick

The lines starting with *** are the debug output that I added to OsgQtQuick‘s CMakeLists.txt:

# OpenSceneGraph
find_package(OpenSceneGraph 3.0 REQUIRED
  osg
  osgQt
  osgDB
  osgGA
  osgManipulator
  osgUtil
  osgViewer
  osgText)

MESSAGE( STATUS "***OSGDB_LIBRARY: " ${OSGDB_LIBRARY} )
MESSAGE( STATUS "***OSGDB_LIBRARY_DEBUG: " ${OSGDB_LIBRARY_DEBUG} )
MESSAGE( STATUS "***OSGDB_LIBRARIES: " ${OSGDB_LIBRARIES} )
MESSAGE( STATUS "***OPENTHREADS_LIBRARIES: " ${OPENTHREADS_LIBRARIES} )

Finally all OpenSceneGraph libraries were linked successfully:

ldd libosgQtQmld.so | grep -i osg
libosgd.so.130 => /home/dmitry/examples/install/lib64/libosgd.so.130 (0x00007fd77a10d000)
libosgQtd.so.130 => /home/dmitry/examples/install/lib64/libosgQtd.so.130 (0x00007fd779ec6000)
libosgDBd.so.130 => /home/dmitry/examples/install/lib64/libosgDBd.so.130 (0x00007fd77997c000)
libosgGAd.so.130 => /home/dmitry/examples/install/lib64/libosgGAd.so.130 (0x00007fd779680000)
libosgManipulatord.so.130 => /home/dmitry/examples/install/lib64/libosgManipulatord.so.130 (0x00007fd7793e3000)
libosgTextd.so.130 => /home/dmitry/examples/install/lib64/libosgTextd.so.130 (0x00007fd77908d000)
libosgViewerd.so.130 => /home/dmitry/examples/install/lib64/libosgViewerd.so.130 (0x00007fd778c72000)
libosgUtild.so.130 => /home/dmitry/examples/install/lib64/libosgUtild.so.130 (0x00007fd775793000)

And I even was able to start my test QML application after adding ‘d’ suffix to all libraries in all qmldir files:

qml/osgGA/qmldir
qml/osgManipulator/qmldir
qml/osgViewer/qmldir
qml/osgText/qmldir
qml/osgDB/qmldir
qml/osg/qmldir

For example, qml/osg/qmldir should look like

module osg
plugin osgplugind

My QML application shows the rotating cube:

with the following QML:

import QtQuick 2.5
import QtQuick.Controls 1.4

// OpenSceneGraph
import osg       2.0 as OSG       // Core types
import osgGA     2.0 as OSGGA     // GUI Abstraction
import osgViewer 2.0 as OSGViewer // Viewer functionality

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: console.log("Open action triggered");
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }

    // Root item - 3D scene view
    OSGViewer.View {

        // Default view size
        width: 640; height: 480

        // Set favorite camera manipulator
        cameraManipulator: OSGGA.TrackballManipulator {}

        // Set scene for rendering
        sceneData: OSG.Geode {
            OSG.ShapeDrawable {
                color: Qt.rgba(1, 1, 0, 1)
                shape: OSG.Box {
                    halfLengths: Qt.vector3d(0.5, 0.5, 0.5)
                }
            }
        }
    }
}

I also did some experimentation with CMAKE_MODULE_PATH variable that can be defined from CMake command line, but it does not help in this situation. Setting CMAKE_MODULE_PATH environment variable does not take an effect:

export CMAKE_MODULE_PATH=$CMAKE_MODULE_PATH:/home/dmitry/examples/OpenSceneGraph/CMakeModules
echo $CMAKE_MODULE_PATH
cmake ../../osgqtquick/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install

To build OsgQtQuick with OsgEarth I used the following command (by default osgQtQuick_WITH_EARTH is OFF):

cmake ../../osgqtquick/ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/home/dmitry/examples/install -DOpenSceneGraph_DEBUG=1 -DosgQtQuick_WITH_EARTH=ON

that started to work after adding ‘d’ suffix to library name in osgqtquick/cmake/FindOsgEarth.cmake:

MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )

FIND_LIBRARY(${MYLIBRARY}
    NAMES
        ${MYLIBRARYNAME} ${MYLIBRARYNAME}d
    PATHS
        ${OSGEARTH_DIR}
        $ENV{OSGEARTH_BUILD_DIR}
        $ENV{OSGEARTH_DIR}
        $ENV{OSGEARTHDIR}
        $ENV{OSG_ROOT}
        ~/Library/Frameworks
        /Library/Frameworks
        /usr/local
        /usr
        /sw
        /opt/local
        /opt/csw
        /opt
        [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/lib
        /usr/freeware
    PATH_SUFFIXES
        /lib/
        /lib64/
        /build/lib/
        /build/lib64/
        /Build/lib/
        /Build/lib64/
     )

Leave a Reply

Your email address will not be published. Required fields are marked *