Cause CMAKE to generate an error

后端 未结 1 1759
轻奢々
轻奢々 2020-12-23 08:45

How can I get CMAKE to generate an error on a particular condition. That is, I want something like this:

if( SOME_COND )
  error( \"You can\'t do that\" )
e         


        
相关标签:
1条回答
  • 2020-12-23 09:09

    The message() method has an optional argument for the mode, allowing STATUS, WARNING, AUTHOR_WARNING, SEND_ERROR, and FATAL_ERROR. STATUS messages go to stdout. Every other mode of message, including none, goes to stderr.

    You want SEND_ERROR if you want to output an error, but continue processing. You want FATAL_ERROR if you want to exit CMake processing.

    Something like:

    if( SOME_COND )
      message( SEND_ERROR "You can't do that" )
    elseif( SOME_CRITICAL_COND )
      message( FATAL_ERROR "You can not do this at all, CMake will exit." )
    endif()
    
    0 讨论(0)
提交回复
热议问题