MantisBT - CMake
View Issue Details
0014494CMakeCMakepublic2013-10-20 03:272014-03-05 09:58
icando 
Stephen Kelly 
highmajoralways
closedfixed 
Visual Studio 2012Windows
CMake 2.8.12 
CMake 3.0 
0014494: Doesn't create .lib for header only targets on Windows.
Not sure if it should be a bug report or a feature request. Basically the support for header-only library on Windows is missing.

I've tested under Linux and the feature IS actually supported. A header-only library will generate minimum .a file that has nothing in it. However, on Windows, it passes no source file to the 'lib' tool and the tool doesn't generate any files in this case.

It would be better to handle it in CMake side as opposed to the CMakeLists.txt side.

The simplest fix would be generating an empty source file for windows platform if it is header only. A more complicated fix is when CMake generates Makefile, it doesn't generate dependencies on the .a or .lib if it is header-only target, but generates dependencies on child targets.
Unzip the attached file, and under Windows, run
cmake -G "NMake Makefiles"
nmake

It will produce:
NMAKE : fatal error U1073: don't know how to make 'B.lib'
No tags attached.
zip tests.zip (856) 2013-10-20 03:27
https://public.kitware.com/Bug/file/4909/tests.zip
Issue History
2013-10-20 03:27icandoNew Issue
2013-10-20 03:27icandoFile Added: tests.zip
2013-10-20 11:19icandoNote Added: 0034174
2013-10-21 08:47Brad KingAssigned To => Stephen Kelly
2013-10-21 08:47Brad KingStatusnew => assigned
2013-10-21 08:48Brad KingNote Added: 0034180
2013-10-21 09:40Stephen KellyNote Added: 0034186
2013-10-21 09:40Stephen KellyStatusassigned => resolved
2013-10-21 09:40Stephen KellyFixed in Version => CMake 3.0
2013-10-21 09:40Stephen KellyResolutionopen => fixed
2014-03-05 09:58Robert MaynardNote Added: 0035291
2014-03-05 09:58Robert MaynardStatusresolved => closed

Notes
(0034174)
icando   
2013-10-20 11:19   
I tested on windows, looks like empty source file will generate ugly warning about 'no symbol in object file'. So it would be great it can be handled in CMake side gracely.
(0034180)
Brad King   
2013-10-21 08:48   
IIUC the new INTERFACE library target type covers this use case.
(0034186)
Stephen Kelly   
2013-10-21 09:40   
Yep, what you seem to want is something like this:

 add_library(B INTERFACE)
 target_include_directories(B INTERFACE b.h)
 target_link_libraries(B INTERFACE A)

Please try it with cmake master.

Thanks,
(0035291)
Robert Maynard   
2014-03-05 09:58   
Closing resolved issues that have not been updated in more than 4 months