やりたいこと
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!")
エラーメッセージを出力して継続
message
にSEND_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