[CMake] target_sources vs. PUBLIC_HEADER for libraries

Innokentiy Alaytsev alaitsev at gmail.com
Fri Oct 11 19:13:52 EDT 2019


Hello!

After some look into target installation, I've devised  the following
abomination
<https://gitlab.com/UtilityToolKit/utk.cmake/blob/master/utk_cmake_install.cmake#L357> 
. It is ugly and not the way it should be done, but it works and only
requires some discipline at copying and pasting header files listing code.
The function expects the files that are to be installed to be listed with
BUILD_INTERFACE and INSTALL_INTERFACE generator expressions. 

I only use it for headers because I don't know how to separate file lists
into components (i.e. Dev for headers and Runtime for resource files
required at runtime). I use the following code for listing target header
files:

set (HEADERS
  # List of files here
  )

file(RELATIVE_PATH PREFIX
  ${PROJECT_SOURCE_DIR}
  ${CMAKE_CURRENT_LIST_DIR})


foreach (HEADER IN LISTS HEADERS)
  target_sources (my_target(s)
    PRIVATE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${HEADER}>
    $<INSTALL_INTERFACE:${PREFIX}/${HEADER}>)
endforeach (HEADER IN HEADERS)

Hope that will somewhat help and won't hurt anyone's fillings and mind.

Best regards,
Innokentiy Alaytsev




--
Sent from: http://cmake.3232098.n2.nabble.com/


More information about the CMake mailing list