CMake composite logical statement with AND and STREQUAL? - Stack Overflow

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

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745115774a4612117.html

相关推荐

  • CMake composite logical statement with AND and STREQUAL? - Stack Overflow

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

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信