Bracket arguments feature broken?

I’m reading the documentation and came across the bracket argument example here.

However, the example does not even work and I’m getting an error:

CMake Error at RGFramework/CMakeLists.txt:10:
Parse error.  Expected a command name, got unquoted argument with text “.”.

I also get an error with this simple usage:

message([[
Hello
]])

According to the documentation it’s should be valid.

An opening bracket is written [ followed by zero or more = followed by [ .

Do I miss something here?

Which CMake version are you using? What is the exact error you’re getting on the message example?

I using CMake 4.1.1

cmake version 4.1.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

The exact error I get with the simple message is this one:

CMake Error at RGFramework/CMakeLists.txt:772:
  Parse error.  Expected a command name, got right paren with text ")".

Interestingly both samples worked when I placed them in a simple top-level CMakeLists.txt
However, when I put them in my project; deep down some nested CMakeLists.txt and nested if()/else() branches and it fails.

I’ll try to create a very simple reproducible project and come back.

Nevermind!

I got the error when I placed the message in a multi-line comment:

#[[		
	message([[
		Hello
	]])
#]]

So the token #[[ conflicts with the first ]] found. I would expect it to not care until the next #]] though.

If you look at the Bracket Comment definition closely enough, you will see that it opens by #[[ and closes by ]] (optionally with same number of = signs between the brackets). So in your case, the comment was closed by the ]]) line, hence ) being reported as an error. There is no indication that #]] should close the comment.

If you want to comment out a block of code like this, use a unique number of = signs. This would have worked:

#[=[		
	message([[
		Hello
	]])
]=]

Indeed. I completely missed this.

Thank you for the support and the explanation!

Happy to help.