CMake version: 3.20.5 (and older)
I’m not sure if my observation is intended behavior or a bug. I noticed that configure_file()
- does not check for C (multiline) comments
- removes all text in a line before #cmakedefine…
- expands #cmakedefine… inside C/C++ comments
Example: ‘#cmakedefine HAVE_JPEG 1’ inside a multiline C comment triggers a compilation error if HAVE_JPEG is false. After expansion the terminating ‘*/’ ends the existing multiline comment which leads to a compilation error in the following line(s).
This was a real case; I was trying to document CMake syntax in the input file.
All examples in the docs show ‘#’ at the beginning of the line. There’s no clue what will happen if it is inside a comment block and whether it is expanded if ‘#’ is not the first character or maybe after optional whitespace.
Please see more details in the attached complete project in text form:
configure_file_breaks_comments.txt (1.7 KB)
(1) Is this behavior intended?
(2) If yes (or no) could (should) this be documented?
Thanks for reading and for any clues.
PS: I mitigated this in my project by replacing ‘#’ with ‘[#]’, hence there’s no problem for me anymore. Please consider this as an attempt to report a bug or trigger improvement of the documentation.