cmakeを諦めない。
Custom commandを使ったファイル生成
- Adding a Custom Command and Generated File (Step 6)の内容
- 標準で用意されているlogやexpを使わない方法を考える
- 事前計算済みの値(
)を1~9までテーブルにしたものを利用する
- 事前計算済みの値(
- 標準で用意されているlogやexpを使わない方法を考える
cmakeをつかって以下のことをする
MakeTable.cxxでつくる平方根表(0<=x<=9)
double sqrtTable[] = {
0,
1,
1.41421,
1.73205,
2,
2.23607,
2.44949,
2.64575,
2.82843,
3,
0};
- 平方根表を使うsqrtのライブラリコード(要Table.hのinclude)
// use the table to help find an initial value
double result = x;
if (x >= 1 && x < 10) {
std::cout << "Use the table to help find an initial value " << std::endl;
result = sqrtTable[static_cast<int>(x)];
}
// do ten iterations
for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
double delta = x - (result * result);
result = result + 0.5 * delta / result;
std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
- stdの表示が変わり、無事ビルドできたことがわかる
$ ./Tutorial 4 Use the table to help find an initial value Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 Computing sqrt of 4 to be 2 The square root of 4 is 2
- 手元の糞デカCMakeLists.txtにgrepして使用状況を調べたところ
ADD_CUSTOM_COMMANDはビルド済みのバイナリファイルのような適当なファイルのコピーなんかに使われてるみたいだ。 まとめ&感想
- CMakeはソースコードの生成も可能
- ヘッダファイル生成とかはバグの温床になりそうでちょっと怖いな。
参考
パッケージインストーラーのビルド
- Building an Installer (Step 7)の内容。
- 流石にユーザーにcmakeを叩いてもらうことは避けたいので配布するものを事前ビルドしてパッケージにする
- CPackというCMakeのパッケージインストーラー生成ツールを使う
- 使い方としてはビルドディレクトリで
cpackコマンドを実行するだけ。
mkdir build && cd build cmake ../src cpack
- デフォルトで
tar.gzファイルが生成されたがオプションでzipとかに変えれる - 回答して確認すると以下のようなファイル内容になっていた
Tutorial-1.0-Linux
├── bin
│ └── Tutorial
├── include
│ ├── MathFunctions.h
│ └── TutorialConfig.h
└── lib
└── libMathFunctions.a
- Linuxでwindows用のinstaller作ろうと思うとクロスコンパイルに対応したコンパイラを入れる必要があるとか色々面倒っぽい。
- https://www.clear-code.com/blog/2016/12/26.html
- オプションでワンパンで行けると楽なんだけどな。
テスト結果をダッシュボードで表示する
- Adding Support for a Dashboard (Step 8)の内容
CTestを使い、結果をCDASH serverにアップロードする
CTestConfig.cmake
set(CTEST_PROJECT_NAME "CMakeTutorial") set(CTEST_NIGHTLY_START_TIME "00:00:00 EST") set(CTEST_DROP_METHOD "http") set(CTEST_DROP_SITE "my.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=CMakeTutorial") set(CTEST_DROP_SITE_CDASH TRUE)
- 実行するとmy.cdash.orgとかいうサイトにテスト結果をアップロードされるので注意
The results of your dashboard will be uploaded to Kitware’s public dashboard here: https://my.cdash.org/index.php?project=CMakeTutorial.
ローカルでダッシュボードを確認する方法や
実行コマンド
ctest [-VV] -D Experimental- なんだこの気持ち悪いオプションは
[-VV] - あんまり重要じゃないのでこのStepはスキップしても良かった気がする。
っていうかこのStepいる?