Skip to content
Alessandro Febretti edited this page Oct 10, 2014 · 14 revisions

Last revision: ver. 4.0.5 - 30 August 2013

This page explains how to set up the build environment for an empty omegalib application. When using omegaSource on this page, we refer to the root directory of your source copy of omegalib. omegaBuild will be the root directory of your build.

When creating a new omegalib application, you have three options:

  • Solution 1: Create an external application using CMake: This the preferred solution. You would create a cmake file for your own application (this assumes you have basic knowledge of cmake) and use the find_package CMake command to link your application to your local omegalib build.

  • Solution 2: Add it to the omegalib build: This is a good solution if you want to add an application to the actual omegalib distribution. Your application would be under omegaSource/src/apps. Building omegalib will automatically build your application and place it in the output binary directory with the rest of the omegalib libraries and executables.

  • Solution Don't Do This Please: Create an external application using a native build system directly (make, Visual Studio, etc.): Altough doable, this solution is not officially supported. You should really use CMake, and save yourself a few headaches. If you must choose this path the basic steps would be:

  • add omegaSource/include, omegaSource/ext/include and omegaBuild/include, omegaBuild/omicron/omicron/include to your compiler include paths

  • depending on build type and platform, link against libraries under omegaBuild/lib, omegaBuild/bin, omegaSource/ext/lib32, omegaSource/ext/lib64

This page only covers solutions 1 and 2.


Solution 1: Building an external application

This solution assumes you have minimal knowledge of the CMake build system. This guide follows steps similar to the Mixing Python and C++ Guide. Check that page as well for some additional information.

Step 1: Create the source and cmake file

Create a new folder named as your application (we will be calling it myapp from now on). Create a source file myapp.cpp with the following code:

	#include <omega.h>
	#include <omegaGl.h>

	using namespace omega;

	class HelloApplication: public EngineModule
	{
	public:
		HelloApplication() {}
		virtual ~HelloApplication() {}
	};

	int main(int argc, char** argv)
	{
		Application<HelloApplication> app("myapp");
		return omain(app, argc, argv);
	}

NOTE: the Application object created in main takes one string parameter. This string parameter must be the same as the application name. If you specify anything different, your application won't work when run in cluster mode.

The code above is the most basic omegalib application possible. It will do nothing more than initializing the various omegalib subsystems and open an empty render window. Creating an application that actually does something is covered in other wiki pages.

Also create a CMakeLists.txt file in the same directory, with the following content:

	cmake_minimum_required(VERSION 2.8.1) 
	project(myapp)

	find_package(Omegalib)

	include_directories(${OMEGA_INCLUDE_DIRS})
	add_executable(myapp myapp.cpp)
	target_link_libraries(myapp ${OMEGA_LIB})

The last line, target_link_libraries(myapp ${OMEGA_LIB}), links your application against the omegalib libraries. You can add {OMEGA_TOOLKIT_LIB}, {OMEGA_OSG_LIB}, {CYCLOPS_LIB}, {OMEGA_VTK_LIB}, depending on what you need.

Step 2: Configure your build

Now run cmake using myapp as your source directory. During configuration, CMake will ask you to set the Omegalib_DIR variable. Set this to the path of your omegalib build directory (i.e, on Windows the directory containing OmegaLib.sln). Configure, generate, exit. You should now have a build environment ready for your application. Note: In windows when you run your application, you should have the binary folder from the omegalib install containing the omegalib dlls in your PATH, otherwise the application will fail to launch due to missing dlls.

You can download a prepackaged external application example here: http://uic-evl.github.io/omegalib/omegalib-external-app.tar.gz


Solution 2: Adding an application to the omegalib build

Step 1: Create the application directory and CMake file

In a new directory under omegaSource/src/apps, create a source file myapp.cpp with the same contents as shown in solution 1 step 1. Create a cmake build file, CMakeList.txt. Put the following in the CMake file:

	add_executable(myapp myapp.cpp)
	set_target_properties(ohello PROPERTIES FOLDER apps)
	target_link_libraries(ohello omega)

add_executable defines a new executable target with myapp.cpp as the only source file. set_target_properties is optional: it is only used when generating visual studio solutions, to put the executable in the apps solution folder. target_link_libraries specifies link targets for the executable. For this basic example we are only linking agains omega Depending on the application you are developing, you may want to link against additional libraries, i.e. omegaToolkit, omegaOsg, omegaVtk.

Step 2: Adding the application to the omegalib build

Now you need to make the main omegalib build aware of our new application. Go to omegaSource/src and open the CMakeLists.txt file you find there. you should add a line like the following:

	add_subdirectory(apps/myapp)

if your application just uses openGL functionality, you can simply add this line at the end of the file. If you are using OSG/cyclops or Vtk, you should add the line inside the OMEGA_BUILD_OSG_LIB and OMEGA_BUILD_VTK_LIB if blocks, respectively.

Step 3: Done!

You should be all set now. Just reopen the omegalib solution and build (or run make on linux). Your application binary should be created in the default omegalib bin directory.

Clone this wiki locally