Why some variables can't display by message in cmake?

Viewed 422

I am using cmake to build my project. When I want to check some variables, I use message(${}), however I find some vars can't display using message(), giving a error "message called with incorrect number of arguments". For example, I use "message(${CMAKE_MODULE_PATH})" to check the CMAKE_MODULE_PATH, but is gives an error "message called with incorrect number of arguments". So how do I correctly check these kinds of vars in cmake?

2 Answers

${VAR} expands the contents of the variable. If the variable contains spaces, it will count as multiple arguments. I think what you want is to print the value as a string by doing message("${VAR}").

As an example, my CMakeLists.txt is like this:

cmake_minimum_required(VERSION 3.17)
project(Trade)

set(CMAKE_CXX_STANDARD 11)

include_directories(/root/include)
message("${INCLUDE_DIRECTORIES}")

add_executable(Trade src/main.cpp)
Related