LoginSignup
4
7

More than 5 years have passed since last update.

cmakeを途中で終了させる方法

Posted at

やりたいこと

cmakeスクリプト中で問題があった時点で停止させたい。

結論

message関数の引数にFATAL_ERRORを指定すると、
message出力して停止する。

Example

CMakeLists.txt
cmake_minimum_required(VERSION 2.8)

project(error_test CXX)

option(FATAL "error test" OFF)

if(NOT FATAL)
    message(SEND_ERROR "SEND_ERROR!")
else(FATAL)
    message(FATAL_ERROR "FATAL_ERROR!")
endif()

message("end of file!")

 エラーメッセージを出力して継続

messageSEND_ERRORを指定すると、エラーメッセージを出力して動作を継続する。
以下の実行例ではmessage(FATAL_ERROR "FATAL_ERROR!")を実行後に、
最終行のmessage("end of file!")まで到達して終わる。

SEND_ERROR
>cmake .
CMake Error at CMakeLists.txt:8 (message):
  SEND_ERROR!


end of file!
-- Configuring incomplete, errors occurred!

エラーメッセージを出力して停止

以下の実行例では、message(FATAL_ERROR "FATAL_ERROR!")を実行した時点で終了する。

FATAL_ERROR
>cmake . -DFATAL=ON
CMake Error at CMakeLists.txt:10 (message):
  FATAL_ERROR!


-- Configuring incomplete, errors occurred!

参考

Cause CMAKE to generate an error - Stack Overflow
http://stackoverflow.com/questions/5403636/cause-cmake-to-generate-an-error

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7