How to export target's properties when installing targets in CMake

Viewed 46

I have the following sample project which I would like to export PROTOCOLS_LIST properties.

cmake_minimum_required(VERSION 3.14.0)
project(exported_props LANGUAGES CXX)

add_library(protocols ...)
set_target_properties(protocols PROPERTIES PROTOCOLS_LIST "IP" "TCP" "UDP")

install(TARGETS protocols EXPORT protocol)
install(EXPORT protocol DESTINATION ${CMAKE_BINARY_DIR})

When installing the above sample code, the created protocol.cmake file will not contain my custom property PROTOCOLS_LIST.

Is it possible to pass some target's properties when installing TARGETS?

1 Answers

By default, CMake installs only specific set of target's properties.

For tell CMake to install additional properties you could list that properties in the EXPORT_PROPERTIES target's property:

# Tell CMake to install PROTOCOLS_LIST property for the target.
set_property(TARGET protocols APPEND PROPERTY EXPORT_PROPERTIES PROTOCOLS_LIST)
Related