Hello,

How should I properly setup a header-only library in cmake such that:
1. The headers appear in the Visual Studio solution.
2. In an executable i can use target_link_libraries(<TARGET> 
<HEADER_ONLY_LIBRARY>) to specify that I want to use (the headers of) this 
library.

So far I have considered two options:
a) create a INTERFACE library using add_library(<HEADER_ONLY_LIBRARY> 
INTERFACE), this fulfills property 2. from above but not 1.
b) create a usual library and set LINKER_LANGUAGE to CXX. In this way 1. works 
but 2. doesn't work unfortunately because the executable will try to link to a 
library that does not exist.

Notes:
- A not so nice workaround is to go with b) and add an empty source file to it.
- Another option would be to not link the executable with the 
HEADER_ONLY_LIBRARY. However one thing that I like about target_link_libraries 
is that all the "usage requirements" from the HEADER_ONLY_LIBRARY (such as 
include directories and compile options) are applied to the executable 
automatic. So if I don't use target_link_libraries I would have to set these 
options manually (unless there is another alternative?).

I would be very happy for some suggestions :)

Raffael

P.S.: See also the (a bit outdated) discussion 
http://stackoverflow.com/a/11583676/2796908.http://stackoverflow.com/a/11583676/2796908.

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to