3
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 5 years have passed since last update.

Qtプロジェクトファイルの変数の値をコマンドラインで取得する

Last updated at Posted at 2019-07-25

何らかの解析でQtプロジェクトファイルの変数の値を知りたいとします。

しかし、Qtプロジェクトファイルはそれなりに複雑であり、正規表現などで変数の値を取り出すのは難しいです。
(書式が整っていれば可能な場合もある)

qmakeにプロジェクトファイルを実行させ、実際に変数に入っている値を出力させましょう。

このようなプロジェクトファイルを作ります。

inspect.pro
TEMPLATE = aux
CONFIG(release, debug|release):log($$fromfile($$TARGET_PRO, $$VARIABLE))

そして、qmakeのコマンドラインで対象のプロジェクトファイルと変数名を渡すと、変数の値が出力されます。

qmake "TARGET_PRO=path/to/target/target.pro" "VARIABLE=TARGET" -nodepend -nomoc -nocache

target.pro
FOO=bar
> qmake inspect.pro "TARGET_PRO=target.pro" "VARIABLE=FOO" -nodepend -nomoc -nocache
bar
3
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
3
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?