0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Hello World から始める CMake (1)

Posted at

 何はともあれ、まずは CMake を軽く動かしてみる。
 一番最初にすべきは、当然 "Hello, world!" の表示だろう!(断言)

CMakeLists.txt
# 文字を表示するには message() を使う。
message("Hello, world!")

 上記内容の CMakeLists.txt を用意し、cmake を実行してみる。

実行
$ cmake -P CMakeLists.txt
Hello, world!

解説

 コマンド引数 -P は、指定したファイルを実行する指示だが、まあ、普段はあまり使わないかも? デバッグのときとか?

 それでも、初めて(もしくは初めてに等しい)の場合は、そこから得られる情報がいくつかあると思う。

1. ファイル名は CMakeLists.txt

 cmake では、まず用意すべきは CMakeLists.txt である。
 上記ではコマンド引数で指定したが、通常はこのファイル名がデフォルトで使用される。

2. コメントは # で始まる。

 コメントとは、実行に何も影響を与えない文字列のこと。

 上記の例で、 # から始まる行は、cmake 実行には何も影響しない。
あくまでユーザ向けの情報にすぎない。

 なお、cmake でのコメントには複数行可能な Bracket comment と一行だけの Line comment がある。上記の例は Line comment になる。詳細は以下の参考リンク 4. を参照。

3. message 文

 メッセージを表示する。
 なお、たんにメッセージを表示するだけでなく、ステータスに応じて表示・非表示を切り替えるなど、多彩な機能がある。詳細は以下の参考リンク 5. を参照。

参考リンク:

  1. CMake
  2. CMake Documentation and Community
  3. cmake(1) — CMake Documentation
  4. cmake-language(7) — CMake Documentation
  5. message — CMake Documentation
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?