Linux, OSX, WindowsをターゲットにしたC++のクロス開発をしようと思ったら,CMakeを使うのかなと思います.Windowsでは,MinGW + CMake という組み合わせになるかと思います.
異なる環境間でのソースコードの共有はちょっと手を抜いてDropboxを使っています.ソースコードはDropboxに載っていても,ビルドの中間生成物や環境に固有な実行可能形式でDropboxが汚れるのを嫌って,ビルドディレクトリはDropboxの外側でやっています.
すると,素朴な環境だと,ソースコードのディレクトリでcmakeを実行し,ビルドディレクトリでmakeを実行しと煩わしいことになります.そこで,すべての作業をソースディレクトリでやるための汎用的な方法はないものかと思い,基本的な環境設定をするためのラッパー群を作ってみました.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"c:\Program Files (x86)\CMake\bin\cmake.exe" -G"MinGW Makefiles" -H. -B%builddir% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set MINGW=c:\mingw\mingw64\bin | |
set CC=%MINGW%\gcc | |
set CXX=%MINGW%\g++ | |
:: set CMAKE_CXX_COMPILER=%CXX% | |
set srcdir=%CD% | |
set builddir=%HOME%\build\%srcdir:*Dropbox (smartnova)\=% | |
PATH %builddir%;%PATH% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mingw32-make -C %builddir% |
ソースディレクトリでcmake, makeを叩くだけでビルド作業ができるようになりました.今まで,うじゃうじゃして嫌だったのがこれで解消されます.
- 開発用のソースのディレクトリに移動して,まずは confdir コマンドを実行.これでさまざまな環境変数が設定されます.
- CMake の設定ができたら,cmake コマンドを実行.%HOME%\build 以下に適宜,ビルド用のディレクトリを作成します.
- make コマンドを実行してビルド.
- ビルドに成功したら,生成した実行ファイル名で実行できます.ビルドディレクトリを PATH に通してありますので.