Now, I’m well aware that CMake offers multiple ways to skin this cat. The above feels Mostly Modern; however, copying the INTERFACE_SOURCES property value to the PUBLIC_HEADER property feels awkward. (Why doesn’t target_sources..PUBLIC set this property?)
What is considered the Modern way to do something as straightforward as installing a library and its headers these days?
target_sources(PUBLIC) adds those files to the source list for any consuming target. It’s not quite the same thing. That said, I still use install(FILES) myself out of habit, so I don’t have much input to the question itself.
I understand it’s not quite the same thing; but, as a practical matter, if I’m providing an install target, is there a scenario in which I would not want INTERFACE_SOURCES to be installed?
@Braden: Does the way you described work for you? Also when exporting / installing the targets? Which CMake Version are you using?
I am either getting
CMake Error in CMakeLists.txt:
Target "mylib" INTERFACE_SOURCES property contains path:
"D:/Some/path/include/mypbulic.h"
which is prefixed in the source directory.
Thanks for the quick reply. I totally ended up doing what you described in your second approach. I also feels that this is way to verbose.
Most of the time I just install folders instead of the header files.