Hi,
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:
include(CMakeFindDependencyMacro)
$<$<STREQUAL:$<TARGET_PROPERTY:Foo,TYPE>,STATIC_LIBRARY>:find_dependency(Bar REQUIRED)>
And project Foo’s CMakeLists.txt reads as:
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:
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…