Generator expression with multiple items does not evaluate cleanly with file(GENERATE ...)
Given the following setup:
CmakeLists.txt
:
cmake_minimum_required(VERSION 3.0)
project(foo)
add_executable(foo foo.c)
set(FLAG0 "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler -pthread>"
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")
set(FLAG1 "$<IF:$<COMPILE_LANGUAGE:CUDA>,:SHELL:-Xcompiler -pthread,-pthread>")
target_compile_options(foo PRIVATE ${FLAG0})
configure_file("${CMAKE_CURRENT_BINARY_DIR}/foo.txt" "${CMAKE_CURRENT_BINARY_DIR}/foo.cfg")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/foo.gen" INPUT "${CMAKE_CURRENT_BINARY_DIR}/foo.cfg")
foo.txt
:
@FLAG0@
@FLAG1@
foo.c
:
int main(void) { return 0; }
The compile command line will correctly end up as /usr/bin/cc -pthread -o CMakeFiles/foo.dir/foo.c.o -c <...>/foo.c
.
But the contents of the generated foo.gen
file ends up being:
;-pthread
-pthread
Where the excess semicolon is problematic in the case of the first expression.
Is the evaluation of the generator expression with the added semicolon an issue with the file(GENERATE ...)
command or is the expression malformed?
The first generator expression (FLAG0
) which causes the issue with file(GENERATE ...)
is the current expression used for the INTERFACE_COMPILE_OPTIONS
property of the Threads::Threads
import target produced by FindThreads.cmake
, added in !2092 (closed).