[CMake] Strange behaviour of STREQUAL with a variable containing only "type"
Nils Gladitz
nilsgladitz at gmail.com
Fri Apr 17 07:43:14 EDT 2015
On 17.04.2015 13:09, Sylvain Doremus wrote:
> I have a strange output, related to the minimal CMakeLists.txt that I've provided with this email.
> My CMake version is 3.2.1, on Windows Seven SP1, the tested generators are Visual Studio 10 2010 and Visual Studio 10 2010 Win64.
>
> Here is the output I've got:
>
> TestFolder/type
>
> TestFolder
> TestFolder/type
> Configuring done
>
> Is it normal? Or is it a bug?If it is normal, can someone explain me why it is?
It is expected if "type" itself is a variable (set by some module
evaluated by project()).
e.g. given:
set(TEST_FOLDER type)
The following if():
if(${TEST_FOLDER} STREQUAL "")
After expansion:
if(test STREQUAL "")
If test is a variable set to "" this becomes equivalent to:
if("" STREQUAL "")
If test is not defined as a variable this is instead equivalent to:
if("test" STREQUAL "")
Quoting prevents cmake from dereferencing variables like this if CMP0054
[1] is set to NEW.
CMP0054 is set to NEW for you since you require a cmake version >= 3.1.
Nils
[1] http://www.cmake.org/cmake/help/v3.2/policy/CMP0054.html
More information about the CMake
mailing list