![]() |
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:
hello_world_component.hpp
hello_world_component.cpp
hello_world_client.hpp
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:
SOURCES
: The source files for that component
HEADERS
: The header files for that component
DEPENDENCIES
: Other libraries or targets this component
depends on
COMPONENT_DEPENDENCIES
: The components this component
depends on
PLUGIN
: Treat this component as a plugin-able library
COMPILE_FLAGS
: Additional compiler flags
LINK_FLAGS
: Additional linker flags
FOLDER
: Add the headers and source files to this Source
Group folder
EXCLUDE_FROM_ALL
: Do not build this component as part
of the all
target
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 |
---|---|
All library targets built with HPX are exported
and readily available to be used as arguments to |
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:
EXPORT
: Adds it to the CMake export list HPXTargets
INSTALL
: Generates a install rule for the target
PLUGIN
: Treat this component as a plugin-able library
TYPE
: The type can be: EXECUTABLE, LIBRARY or COMPONENT
DEPENDENCIES
: Other libraries or targets this component
depends on
COMPONENT_DEPENDENCIES
: The components this component
depends on
COMPILE_FLAGS
: Additional compiler flags
LINK_FLAGS
: Additional linker flags
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.