I have the following snippet of a CMakeLists.txt file:
set(MAIN_SOURCES
src/main.cpp
src/main.hpp
)
set(FEATURE_SOURCES
src/feature.cpp
src/feature.hpp
)
option(ENABLE_FEATURE "Enable feature in app" ON)
add_executable(app)
target_sources(app PRIVATE
${MAIN_SOURCES}
$<$<BOOL:${ENABLE_FEATURE}>:${FEATURE_SOURCES}>
)
When trying to configure, I an error like that:
CMake Error in CMakeLists.txt:
Cannot find source file:
src/feature.hpp>
Then I heard that when there are spaces inside the generator expression, the whole generator needs to be quoted. However according to CMake manual, FEATURE_SOURCES is a list (space-separated list?). I would assume the variable doesn't contain spaces when expanded.
Nonetheless I also tried quoting the whole thing:
target_sources(app PRIVATE
${MAIN_SOURCES}
"$<$<BOOL:${ENABLE_FEATURE}>:${FEATURE_SOURCES}>"
)
which yields again the same error.
Any suggestions how can I get this generator expression right?