Setting Up a CMake Project

CMake is the most flexible solution if you want to quickly test Exchange. In a matter of seconds, you will have a working code that will compile against our header files.

Requirements

Make sure you downloaded and installed CMake for your environment. Also, check Supported Platforms and Compiler Information to see which CMake generator is available according to your build system and that you installed the development tools you need.

Project

Make a folder for your new project, and create a file called CMakeLists.txt with the following content:

cmake_minimum_required(VERSION 3.18)
project(ExchangeApplication C)

set(EXCHANGE_INSTALL_DIR "" CACHE PATH "Path to Exchange directory")

add_executable(ExchangeApplication main.c)
target_include_directories(ExchangeApplication PRIVATE "${EXCHANGE_INSTALL_DIR}/include")

Add another file called main.c with the following code:

#include <stdio.h>

#include <A3DSDKLoader.h>

int main(int argc, char* argv[])
{
    if(A3DSDKLoadLibraryA(EXCHANGE_BINARY_DIR)) {
        A3DInt32 major, minor;
        A3DDllGetVersion(&major, &minor);
        printf("HOOPS Exchange %d.%d loaded\n", major, minor);
        A3DSDKUnloadLibrary();
    }

    return 0;
}

Generate with CMake GUI

Open the CMake application.

Configure the source directory to your project folder and the build directory to any folder of your choice (preferably empty).

Run Configure. A pop-up dialog asks for your build environment. Choose the one that fits your compiler and validate.

Once the configuration is done, configuration variable appears in the center table. Look for EXCHANGE_BINARY_DIR and set it to the installation folder of Exchange. The path must correspond to the folder containing include/.

Run Generate and open your newly generated project. It is located in the folder you previously set as the build directory. If you use an IDE, such as Visual Studio, chances are that you can directly open it from CMake using the Open Project button.

Compile and run your program. You should see Exchange version appearing in the standard output.

You’re ready to jump to our next tutorial: Initializing HOOPS Exchange.

Generate with CMake CLI

From your command line interface, change to any directory you want to generate the project build files (preferably empty) and run the following command:

cmake path/to/project -DEXCHANGE_INSTALL_DIR=path/to/exchange
  • path/to/projet is the folder path to your project root (the folder containing your CMakeLists.txt file and

  • path/to/exchange is the folder path to your Exchange installation directory (the folder containing include/).

You can also select your development environment with the -G option. If not set, the most relevant is choosen according to your operating system.

Once generated, your project is available in your current directory.

Compile and run your program. You should see Exchange version appearing in the standard output.

You’re ready to jump to our next tutorial: Initializing HOOPS Exchange.