Exporting Targets

BLT provides several built-in targets for commonly used libraries:

mpi

Available when ENABLE_MPI is ON

openmp

Available when ENABLE_OPENMP is ON

cuda and cuda_runtime

Available when ENABLE_CUDA is ON

blt_hip and blt_hip_runtime

Available when ENABLE_HIP is ON

These targets can be made exportable in order to make them available to users of your project via CMake’s install() command. Setting BLT’s BLT_EXPORT_THIRDPARTY option to ON will mark all active targets in the above list as EXPORTABLE (see the blt_import_library API documentation for more info).

Note

As with other EXPORTABLE targets created by blt_import_library, these targets should be prefixed with the name of the project. Either the EXPORT_NAME target property or the NAMESPACE option to CMake’s install command can be used to modify the name of an installed target.

Note

If a target in your project is added to an export set, any of its dependencies marked EXPORTABLE must be added to the same export set. Failure to add them will result in a CMake error in the exporting project.

Note

The recommended usage of the HIP targets is via the blt::hip and blt::hip_runtime aliases. Alias targets cannot be exported, so the blt_hip/blt_hip_runtime names can be used for this purpose.

Typical usage of the BLT_EXPORT_THIRDPARTY option is as follows:

# BLT configuration - enable MPI
set(ENABLE_MPI ON CACHE BOOL "")
# and mark the subsequently created MPI target as exportable
set(BLT_EXPORT_THIRDPARTY ON CACHE BOOL "")
# Both of the above must happen before SetupBLT.cmake is included
include(/path/to/SetupBLT.cmake)

# Later, a project might mark a target as dependent on MPI
blt_add_executable( NAME    example_1
                    SOURCES example_1.cpp
                    DEPENDS_ON blt::mpi )

# Add the example_1 target to the example-targets export set
install(TARGETS example_1 EXPORT example-targets)

# Add BLT's targets to the same export set - this is required
# because the mpi target was marked exportable
blt_export_tpl_targets(EXPORT example-targets)

To avoid collisions with projects that import “example-targets”, it is recommended to provide a namespace for the mpi target:

blt_export_tpl_targets(EXPORT example-targets NAMESPACE example)

With this approach the example_1 target’s exported name is unchanged - a project that imports the example-targets export set will have example_1 and example::mpi targets made available. The imported example_1 will depend on example::mpi.