Starting New Apps

By now you probably realized that va uses the cmake build tool quite extensively. And you might have guessed that it also lends itself perfectly to setting up new application projects. While nothing stops you from adopting a more traditional setup there are several advantages to the approach that is described in the following. For one, you don't have to bother much about dependencies. For two, you can run multiple versions of va at the same time and for three, you are already set up for cross-platform development. Besides that, there is something beautiful about having all the build configuration in a clean text file ;)

Describing something in detail always risks making something new look way more complicated than it is. Be assured the following is pretty standard cmake stuff and usually becomes second nature quickly. Setting up new app projects comes down to:

  1. place app code in a directory analog to the examples
  2. add a ADD_SUBDIRECTORY call to the master CMakeList.txt
  3. create a project CMakeList.txt analog to the examples
  4. re-run cmake and generate project files

Where to Place the New Application?

Create a directory structure for your apps analogous to the examples directory. In the following myApps and myFirstApp are names of your choice:

VirtualAwesome/
  CMakeLists.txt
  apps/
    examples/
    addonExamples/
    myApps/
      myFirstApp/
        CMakeLists.txt
        bin/
        data/
        src/
          main.cpp
          MyApp.cpp
          MyApp.h

How to generate Project Files?

This is a three step process with the last being the re-running of cmake. Just like in the initial setup cmake uses a few CMakeLists.txt files to generate the project files of choice. The only difference this time is one additional CMakeLists.txt file for the new app project.

Step 1

In the master cmake config file add the subdirectory of your new application. You do this by adding the following to the end of VirtualAwesome/CMakeList.txt:

ADD_SUBDIRECTORY( apps/myApps/myFirstApp )

Step 2

Add a cmake config file to the directory of your app and define how to build the executable. You do this by saving the following content to VirtualAwesome/apps/myApps/myFirstApp/CMakeList.txt:

# Set the name and the root directory of this example.
# NOTE: Also make sure you add this subdirectory to the end
# of the master CMakeLists.txt in the root of VirtualAwesome
#
SET( EXAMPLE_NAME myFirstApp )
SET( EXAMPLE_ROOT ${PROJECT_SOURCE_DIR}/apps/myApps/${EXAMPLE_NAME} )
 
 
# List all the  files belonging to this example
#
ADD_EXECUTABLE( ${EXAMPLE_NAME}  ${EXECUTABLE_TYPE}  
    ${EXAMPLE_ROOT}/src/main.cpp 
    ${EXAMPLE_ROOT}/src/MyApp.h 
    ${EXAMPLE_ROOT}/src/MyApp.cpp
)
 
 
# List all the libraries to link against
# most core libs are already in VA_LINK_LIBRARIES
# otherwise simply list them afterwards separated by spaces
#
TARGET_LINK_LIBRARIES( ${EXAMPLE_NAME}  
	va  ${VA_LINK_LIBRARIES}
)
 
 
# Define the output path for the executable
# Please note that some IDEs add a "Release" or "Debug" to this
#
SET_TARGET_PROPERTIES( ${EXAMPLE_NAME} PROPERTIES 
	RUNTIME_OUTPUT_DIRECTORY  ${EXAMPLE_ROOT}/bin
)

Make sure you match your directory names in the first two lines. Also under ADD_EXECUTABLE you should list all the source files of your application. If you are using additional libraries you can add them to TARGET_LINK_LIBRARIES. You can specify the entire path or just the lib name in case they are in the search path.

Step 3

Run the cmake-gui again and re-generate the project file.

If you run into problems let us know on the Discussion List.