HPX - High Performance ParalleX

PrevUpHomeNext
Using HPX with CMake based projects

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 leverage the find_package command integrated into CMake. Following is a Hello World component example using CMake.

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)

# Instruct cmake to find the HPX settings
find_package(HPX)

In order to have CMake find HPX, it needs to be told. The easiest is to add the HPX_DIR cmake variable pointing to the directory containing the HPXConfig.cmake script which gets picked up by cmake and sets up all the necessary macros needed to use HPX in your project. Pass it on the command line while invoking cmake (where $HPX_LOCATION is the build directory or CMAKE_INSTALL_PREFIX you used while building HPX):

cmake -DHPX_DIR=$HPX_LOCATION/lib/cmake/hpx ...

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

You can check if HPX was succesfully found with the HPX_FOUND CMake variable.

The simplst way to add the HPX component is to use the add_hpx_component macro and add it to the CMakeLists.txt file:

# build your application using HPX
add_hpx_component(hello_world_component
    SOURCES hello_world_component.cpp
    HEADERS hello_world_component.hpp
    COMPONENT_DEPENDENCIES iostreams)

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
add_hpx_executable(hello_world
    ESSENTIAL
    SOURCES hello_world_client.cpp
    COMPONENT_DEPENDENCIES hello_world_component)

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

[Note] Note

All library targets built with HPX are exported and readily available to be used as arguments to target_link_libraries in your targets. The HPX include directories are available with the HPX_INCLUDE_DIRS CMake variable

CMake macros to integrate HPX into existing Applications

In addition to the add_hpx_component and add_hpx_executable you can use the hpx_setup_target macro to have an already exisiting target to be used with the HPX libraries.

hpx_setup_target(target)

Optional Parameters are:

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.


PrevUpHomeNext