[CMake] Are header-only targets supported?

Pedro d'Aquino budsbd at gmail.com
Mon Nov 1 08:54:39 EDT 2010


Hi,

I'd like to add some header-only targets to my build in order to aid
in project-browsing in IDEs such as Xcode.

If I do "add_library( Common ${header_list} )" the new target shows up
and compiles fine in Xcode, but when I try to compile it using make, I
get the following errors:

-------------------------

MacBook-Pro:build_mac pfranco$ cmake ../../myproject
...
-- Configuring done
CMake Error: Cannot determine link language for target "Common".
CMake Error: CMake can not determine linker language for target:Common
...
MacBook-Pro:build_mac pfranco$ make Common
Scanning dependencies of target Common
make[3]: *** No rule to make target `common/CMakeFiles/Common.dir/build'.  Stop.
make[2]: *** [common/CMakeFiles/Common.dir/all] Error 2
make[1]: *** [common/CMakeFiles/Common.dir/rule] Error 2
make: *** [Common] Error 2

-------------------------

I tried to work around this by adding "set_target_properties( Common
PROPERTIES LINKER_LANGUAGE CXX)", in which case CMake runs without
hiccups but make fails (still no problems in Xcode though):

-------------------------

MacBook-Pro:build_mac pfranco$ make Common
Linking CXX static library libCommon.a
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]
make[3]: *** [common/libCommon.a] Error 1
make[2]: *** [common/CMakeFiles/Common.dir/all] Error 2
make[1]: *** [common/CMakeFiles/Common.dir/rule] Error 2
make: *** [Common] Error 2

-------------------------

Adding a dummy source file works, but causes some ugly warnings I'd
really like to avoid (besides being a bit hackish):

-------------------------

MacBook-Pro:build_mac pfranco$ make Common
[100%] Building CXX object common/CMakeFiles/Common.dir/dummy.cpp.o
Linking CXX static library libCommon.a
/usr/bin/ranlib: for architecture: i386 file: libCommon.a(dummy.cpp.o)
has no symbols
/usr/bin/ranlib: for architecture: x86_64 file:
libCommon.a(dummy.cpp.o) has no symbols
/usr/bin/ranlib: warning for library: libCommon.a for architecture:
i386 the table of contents is empty (no object file members in the
library define global symbols)
/usr/bin/ranlib: warning for library: libCommon.a for architecture:
x86_64 the table of contents is empty (no object file members in the
library define global symbols)
[100%] Built target Common

-------------------------

I've looked up a 3 year old e-mail thread
(http://www.cmake.org/pipermail/cmake/2007-May/014238.html) from which
I gather this isn't really a supported scenario.

Has anything changed since then? What is the best way of doing this?

Thanks,

Pedro d'Aquino


More information about the CMake mailing list