kstn
kstn

Reputation: 580

install TBB_IMPORTED_TARGETS with cmake

I compile TBB with tbb_build command. To allow searching for TBB libraries without adding to the loading path, I want to install the TBB libraries (libtbb.so, libtbbmalloc.so, libtbbmalloc_proxy.so) to a destination folder. I used the command

install(FILES ${TBB_IMPORTED_TARGETS} DESTINATION libs)

However, cmake produce an error at the installation process:

file INSTALL cannot find "${application_source_folder}/TBB::tbb". Call Stack (most recent call first): cmake_install.cmake:84 (include)

Makefile:73: recipe for target 'install' failed

What can be done to tell cmake to install those libraries? As of now I have to manually copy to the destination.

Upvotes: 0

Views: 556

Answers (1)

Alexey Veprev
Alexey Veprev

Reputation: 56

CMake treats target names as filenames in your case. Normally for installing targets you should use install(TARGETS ...) instead of install(FILES ...). But it does not work for IMPORTED targets (see Can I install shared imported library?).

You can use a workaround: get needed files using get_target_property and install using install(FILES ...):

# Collect IMPORTED_LOCATION_RELEASE values from all TBB targets
foreach(tbb_target ${TBB_IMPORTED_TARGETS})
    get_target_property(tbb_lib ${tbb_target} IMPORTED_LOCATION_RELEASE)
    list(APPEND tbb_libs_to_install ${tbb_lib})
endforeach()

# Install the collected values
install(FILES ${tbb_libs_to_install} DESTINATION libs)

You can use other properties to get other files, e.g. for debug versions of TBB libraries use IMPORTED_LOCATION_DEBUG property.

Upvotes: 1

Related Questions