sdbbs
sdbbs

Reputation: 5492

CMake composite logical statement with AND and STREQUAL?

I'm trying to detect MINGW64, however using CMake for Windows (in Program Files); so I wrote the following statement:

if (${CMAKE_HOST_WIN32} AND ("$ENV{MSYSTEM}" STREQUAL "MINGW64"))

Apparently, when running in MINGW64 on Windows, CMAKE_HOST_WIN32 is 1, and $ENV{MSYSTEM} is indeed "MINGW64", so this statement passes.

Running the same statement on Linux produces the error:

CMake Error at CMakeLists.txt:111 (if):
  if given arguments:

    "AND" "(" "" "STREQUAL" "MINGW64" ")"

  Unknown arguments specified

It seems to me CMAKE_HOST_WIN32 here is empty, not 0, and so CMake sees nothing on the left side of "AND", and errs.

Splitting this in two nested if statements:

if (${CMAKE_HOST_WIN32}) 
  if ("$ENV{MSYSTEM}" STREQUAL "MINGW64")
     # do something
  endif()
endif()

... does work as intended on both Linux and Windows - but I prefer having a single line if statement.

What would be the correct way to specify this composite logic statement on a single line in CMake, so it works across platforms?

Upvotes: 0

Views: 8

Answers (0)

Related Questions