configure_file: generate code dependant on an if clause ?

Id like to generate a .h file containing code dependent on an if clause set in the input file of the configure_file.

if (VAR)
 generate this line;
 generate that line;

As for now, Im getting in the .h code all of the above lines generated.

Is there a way to generate only specific lines, either of the if() or of the else() from the input file? Or is there any other way except for the configure_file to this?

configure_file does not support CMake code in the files. All it does is expand variable references. So what you probably want is closer to:

my configured file
if (special)
  set(dependent_line "is very special")
else ()
  set(dependent_line "is very boring")
endif ()
configure_file(input output)

Yes, I ended up with a similar solution.

Would be nice if this would have been done by the configure_file though.

The way that CMake code works, this would involve running the top-level command parser over the input file. That parser is not very robust to non-CMake code, so some way of encoding what is something that configure_file should look at and ignore is a tough problem. Consider:

if (bar)
if (foo)
else ()
endif ()
endif ()

Give this to configure_file. Is if (bar) something it should care about or something for configure_file? How about if (foo)? While it’d be nice, it’s just never going to be feasible, sorry.

This is basically a request for a templating engine built into configure_file(). Does not seem like a feasible idea.