14

CMake emits an error in from the following line

if(NOT ($ENV{TnCfg} STREQUAL Linux_Build_Speech))

The error is

CMake Error at CMakeLists.txt:37 (if):

    if given arguments:

"NOT" "(" "STREQUAL" "Linux_Build_Speech" ")"

Unknown arguments specified

What's the problem? The line is valid code.

jww
  • 97,681
  • 90
  • 411
  • 885
Michael
  • 161
  • 1
  • 1
  • 3
  • Please include line 37 of your CMakeLists.txt file in your question. – DLRdave Sep 26 '16 at 16:38
  • 1
    Probably you try to check an empty variable. For example if(${var} STREQUAL "foo") leads to such an error for empty `var`. Changing to if("${var}" STREQUAL "foo") fixes the problem, because then CMake sees the empty variable and is no longer confused. – usr1234567 Sep 26 '16 at 16:51
  • line 37: if(NOT ($ENV{TnCfg} STREQUAL Linux_Build_Speech)). – Michael Sep 26 '16 at 17:43
  • So should I change it to if(NOT ("$ENV{TnCfg}" STREQUAL Linux_Build_Speech))? – Michael Sep 26 '16 at 17:47
  • Welcome to StackOverflow. And yes, it maybe should be `if(NOT "$ENV{TnCfg}" STREQUAL "Linux_Build_Speech")`. Depending on if `Linux_Build_Speech` is a variable containing a string or - as I assumed - a string itself. Please add a [mcve] to your question. For more on the quoting topic in CMake please see [here](http://stackoverflow.com/questions/35847655/cmake-when-to-quote-variables). – Florian Sep 26 '16 at 18:08
  • Thank you. Still the issue is not fixed. The failed build message I receive is build.py: Building for osx. Specify --platform to override build.py: WARNING: svn:executable property is not set on your build.py. You may want to run 'svn propset svn:executable ON build.py' command and commit the change. build.py: TnGuidanceTextGenerator has no dependencies build.py: Generating project for TnGuidanceTextGenerator – Michael Sep 27 '16 at 16:23
  • CMake Error: Error: generator : Xcode Does not match the generator used previously: Unix Makefiles Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory. build.py: ERROR: Command 'cmake -G "Xcode" -DCMAKE_PLATFORM:STRING="osx" -DCMAKE_TOOLCHAIN_FILE="/Users/micheles/Documents/TnGuidanceTextGenerator/build/TnGuidanceTextGenerator-osx/osx-debug-toolchain.cmake" -DCMAKE_CONFIGURATION_TYPES:STRING="Release;Debug" "/Users/micheles/Documents/TnGuidanceTextGenerator"' failed with exit code 256! FAILED – Michael Sep 27 '16 at 16:26
  • Include appropriate information. Could you post your full CMakeLists code and indicate what are you trying to accomplish and what have you tried so far? Also please format your question appropriately. – tambre Sep 27 '16 at 17:50
  • @Michael: That's another issue, your original issue is fixed by my comment. Please ask a new question. – usr1234567 Sep 27 '16 at 19:39
  • 1
    For other folks finding this from Google, be advised typos in keywords will give the same error message. – cxw Aug 16 '18 at 17:44

1 Answers1

23

Probably you try to check an empty variable. The problem is $ENV{TnCfg} because it is empty. CMake replaces the value of the variable names by their values, leading to

if (NOT (STREQUAL Linux_Build_Speech))

That's not valid and CMake wants an argument left of STREQUAL.

Putting quotation-marks around the variable

if(NOT ("$ENV{TnCfg}" STREQUAL Linux_Build_Speech))

fixes the problem, because it gets replaced by "" leading to

if(NOT ("" STREQUAL Linux_Build_Speech))

and the empty string is a valid argument.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • 1
    Thank you for your answers that unfortunately did not do the trick as probably there were other hidden issues. So I simply checked out a new fresh version of the repository after I deleted the previous one. Now it builds correctly. – Michael Sep 28 '16 at 14:33
  • 2
    Nevermind, I think the current question will be useful for other people, too. Please accept the answer, then it is clear that you no longer seek an answer. – usr1234567 Sep 28 '16 at 14:54
  • 1
    *"Putting quotation-marks around the variable..."* - It also causes a policy violation in CMake. The message is *"Policy CMP0054 is not set: Only interpret if() arguments as variables or keywords when unquoted."* – jww Aug 26 '17 at 22:02
  • @jww: Add `${}` around the variable name instead of quotation marks. – usr1234567 Apr 04 '18 at 15:02
  • using the quotation would solve the problem if the variable was user-defined variable – Mazen Ak Aug 09 '21 at 07:44