[Nitpicking] Making generator expression evaluates to null/nil/nothing/nada/zilch rather than empty/blank/""?


Thanks to this great post and SO answer, I have CMake writes FooConfig.cmake file whose content varies depending on target type (STATIC, SHARED) evaluated by generator expression.

To this end, FooConfig.cmake.in reads as:



And project Foo’s CMakeLists.txt reads as:


# Generate <package>Config.cmake

# Evaluate generator expression in generated <package>Config.cmake

When Foo target is created as a static library, the resulting FooConfig.cmake file reads as expected as:


find_dependency(Bar REQUIRED)

Great! And when Foo target is generated as shared library, rather than evaluating to nothing in place of find_dependency(Bar REQUIRED), an empty/blank/new line is inserted to the file. Is there a way not to insert this empty line, as if the generator expression evaluates to nothing rather than empty?

In the advent multiple dependencies would be required, I would like to prevent multiple empty lines being inserted in the generated FooConfig.cmake file.

I know, just nitpicking…

The newline comes from the newline after the closing >. You could move this inside of the genex, but then you have a file without a newline at the end which isn’t always acceptable (Git marks it as a “whitespace problem” at least).

Thanks for the explanation, I’ll try your suggestion. There are other lines following the genex in fact, so the file will nevertheless ends with a new line.