HPX - High Performance ParalleX


How to Use HPX with CMake

In Addition to the pkg-config support discussed on the previous pages, HPX comes with full CMake support. In order to integrate HPX into your existing, or new CMakeLists.txt you can include FindHPX.cmake. Following is the Hello World component example using CMake instead of pkg-config.

Let's revisit what we have. We have three files which compose our example application:

The basic structure to include HPX into your CMakeLists.txt is shown here:

# Require a recent version of cmake
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)

# This project is C++ based.
project(your_app CXX)

# This adds the HPX cmake configuration directory to the search path.

# Instruct cmake to find the HPX settings


This cmake script assumes that the location of the HPX installation is set as the value of HPX_ROOT which is best done by passing it on the command line while invoking cmake:

cmake -DHPX_ROOT=<HPX installations directory> ...

Alternatively, if you wish to require HPX for your project, replace the find_package(HPX) line with find_package(HPX REQUIRED).

The last two lines in the snippet above sets the appropriate include and link directories.

In order to add the HPX component we use the add_hpx_component macro and add it to the CMakeLists.txt file:

# build your application using HPX
    SOURCES hello_world_component.cpp
    HEADERS hello_world_component.hpp

The available options to add_hpx_component are:

After adding the component, the way you add the executable is as follows:

# build your application using HPX
    SOURCES hello_world_client.cpp
    COMPONENT_DEPENDENCIES hello_world_component)

When you configure your application, all you need to do is set the HPX_ROOT variable to point to the installation of HPX!

[Note] Note

FindHPX.cmake makes adjustments various cmake internal settings such as compiler and linker flags. This is needed to ensure maximal compatibility between your application and the HPX version you are using. The add_hpx_executable and add_hpx_component additionally add the proper libraries to link against.

If you do not use CMake, you can still build against HPX but you should refer to the section on How to Build HPX Components with pkg-config.