0

I want to pass a variable's value to a function as if I had directly written it. Here is what I have tried:

cmake_minimum_required (VERSION 3.5.1)
project(test)

message(WARNING "This is a warning")
# CMake Warning at CMakeLists.txt:4 (message):
#   This is a warning

set(variable "WARNING \"This is a warning\"")
message(${variable})
# WARNING "This is a warning"

Unfortunately, you can see that the second call to message doesn't behave like the first one. How to achieve this purpose?

2
  • Why not just make the warning message itself a variable and then print out with message(WARNING ${message_var})? Commented Mar 23, 2018 at 12:38
  • @DeveloperPaul Because this was just a minimal example for something more complex that I was trying to achieve. Commented Mar 23, 2018 at 18:21

1 Answer 1

1

Simply assign a list to the variable:

set(variable WARNING "This is a warning")

Alternatively, as elements in a list are actually separated with a semicolon:

set(variable "WARNING;This is a warning")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.