[cmake-developers] Is this warning really needed: "You have called ADD_LIBRARY for library foobar without any source files."?

Erik Sjölund erik.sjolund at gmail.com
Wed Jul 22 08:25:26 EDT 2015


Hi,

I think this warning could be removed: "You have called ADD_LIBRARY
for library foobar without any source files. This typically indicates
a problem with your CMakeLists.txt file "

If you have a function that populates sources to a target, let us say
something like this:

function(activate_feature target_name)
    target_sources(${target_name} PRIVATE feature.cc)
endfunction()

you would like to be able to do

add_library(foobar SHARED)
activate_feature(foobar)

without any CMake warning.
I've started using that design scheme more and more. That is, to have
a function setting up a target where the target name is given as an
input parameter. The nice thing about it is that I can pass both an
executable target and a shared library target as input to such a
function.
cheers,
Erik Sjölund


More information about the cmake-developers mailing list