Soprano  2.8.0
Soprano Howto

Soprano includes

Using Soprano in your own project is pretty straight forward. Soprano provides includes for all classes and enumerations. Using a Soprano class like Statement is as simple as including

 #include <Soprano/Statement>

For an easy start one can simply include the Soprano header which pulls in all classes. The following code shows a simple example of a Soprano application which creates a new Model, adds a Statement, and lists it.

 #include <Soprano/Soprano>
 #include <QDebug>

 int main( int argc, char** argv )
     Soprano::Model* model = Soprano::createModel();
     model->addStatement( QUrl( ""),
                          Soprano::LiteralValue( "A test resource" ) );
     Soprano::StatementIterator it = model->listStatements();
     while( )
         qDebug() << *it;

Soprano in the Build System

Integrating Soprano into your own build system is rather simple. Soprano provides a set of libraries and one include path. The libraries are:

A PkgConfig description is provided for the core library and can be used as described in the following.

Using qmake with Soprano

Soprano provides pkg-config integration which allows to build the above example using qmake. The following pro file looks for Soprano includes and libs via pkg-config and builds the application sopranotest.

 SOURCES += main.cpp
 TARGET = sopranotest
 CONFIG += qt link_pkgconfig
 PKGCONFIG += soprano

Using CMake with Soprano

Using cmake is simple. Find required packages Qt4 and PkgConfig, look for Soprano via PkgConfig and link to both Soprano and QtCore:

 find_package(PkgConfig REQUIRED)
 find_package(Qt4 REQUIRED)
 pkg_search_module(Soprano REQUIRED soprano)
 include_directories(${Soprano_INCLUDE_DIRS} ${QT_INCLUDE_DIR})
 add_executable(sopranotest main.cpp)
 target_link_libraries(sopranotest ${Soprano_LIBRARIES} ${QT_QTCORE_LIBRARY})
PkgConfig is not available on Windows. For platform independent development use a typical cmake module like KDE's FindSoprano.cmake.

Some CMake Magic

Soprano provides the simple onto2vocabularyclass tool which can generate convenience namespaces such as Soprano::Vocabulary::RDF from ontology files. With CMake it is very simple to generate these namespaces on-the-fly instead of packaging the generated files by using the SopranoAddOntology macro provided by Soprano:

                      [VISIBLITY VISIBILITY_NAME])

Imagine one's code contains an ontology description in rdf+xml format named Foo (Foo Object Ontology) and you want to make its classes and properties accessible in the MyStuff::Foo namespace. One simply includes the cmake macro provided by Soprano:


And then uses it to add the generated files to the sources:

 soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs "FOO" "Vocabulary" "rdfxml")

This will add a command to generate files foo.h and foo.cpp at build time and add the latter to the sources foo_SOURCES. The generated namespace will be named Vocabulary::FOO. It is optionally possible to make the namespace public API and export it by adding the VISIBILITY keyword:

 soprano_add_ontology(foo_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/foo.rdfs "FOO" "Vocabulary" "rdfxml" VISIBILITY "foo")