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

**URL:** https://discourse.cmake.org/t/nitpicking-making-generator-expression-evaluates-to-null-nil-nothing-nada-zilch-rather-than-empty-blank/10627
**Category:** Code
**Created:** [April 10, 2024, 2:39pm UTC](https://discourse.cmake.org/t/nitpicking-making-generator-expression-evaluates-to-null-nil-nothing-nada-zilch-rather-than-empty-blank/10627 "2024-04-10T14:39:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [April 10, 2024, 2:39pm UTC](https://discourse.cmake.org/t/nitpicking-making-generator-expression-evaluates-to-null-nil-nothing-nada-zilch-rather-than-empty-blank/10627/1 "2024-04-10T14:39:24Z")

</div>

Hi,

Thanks to [this great post](https://discourse.cmake.org/t/configuring-a-file-that-has-both-substitution-and-generator-expressions/3064) and [SO answer](https://stackoverflow.com/a/69346359), 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:

```auto
include(CMakeFindDependencyMacro)

$<$<STREQUAL:$<TARGET_PROPERTY:Foo,TYPE>,STATIC_LIBRARY>:find_dependency(Bar REQUIRED)>

```

And project Foo’s CMakeLists.txt reads as:

```auto
include(CMakePackageConfigHelpers)

# Generate <package>Config.cmake
configure_package_config_file(
	${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
	${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
	INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

# Evaluate generator expression in generated <package>Config.cmake
file(
	GENERATE
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
	INPUT ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
)

```

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

```auto
include(CMakeFindDependencyMacro)

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…

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 11, 2024, 5:39pm UTC](https://discourse.cmake.org/t/nitpicking-making-generator-expression-evaluates-to-null-nil-nothing-nada-zilch-rather-than-empty-blank/10627/2 "2024-04-11T17:39:56Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![emaschino](https://discourse.cmake.org/user_avatar/discourse.cmake.org/emaschino/32/6126_2.png) [@emaschino](https://discourse.cmake.org/u/emaschino)
#### Post date: [April 12, 2024, 6:18pm UTC](https://discourse.cmake.org/t/nitpicking-making-generator-expression-evaluates-to-null-nil-nothing-nada-zilch-rather-than-empty-blank/10627/3 "2024-04-12T18:18:46Z")

</div>

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.
