cmake で bcc582 と vc141 一気にビルド

1本の CMakeLists.txt と数本の短いバッチフィルで、2つのコンパイラ bcc582 と vc141 をそれぞれ使って、さらにそれぞれの debug バージョンと release バージョンを一気にビルドするためのメモです。

今後付け足していく予定です。

ディレクトリ構造

. ; ソース, CMakeLists.txt, バッチファイル, 改名したEXEファイルをコピーしてくる
|
+-- build ; ビルド ディレクトリ
     |
     +-- bcc582d ; bcc582 debug バージョン用 ビルド ディレクトリ
     |
     +-- bcc582 ; bcc582 release バージョン用 ビルド ディレクトリ
     |
     +-- vc141 ; vc141用 ビルド ディレクトリ

環境変数

コンパイラのインストールディレクトリを設定しておく

BCC582=C:\PROGRA~1\Borland\BDS\4.0
VC141=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build

バッチファイル

build.bat

@echo off
cmd /c build_bcc582.bat
cmd /c build_vc141.bat
cp --update --no-target-directory build/bcc582d/foo.exe       ./foo_bcc582d.exe
cp --update --no-target-directory build/bcc582/foo.exe        ./foo_bcc582.exe
cp --update --no-target-directory build/vc141/release/foo.exe ./foo_vc141.exe
cp --update --no-target-directory build/vc141/debug/foo.exe   ./foo_vc141d.exe

build_bcc582.bat

@echo off
PATH=%BCC582%\Bin;%PATH%
mkdir build\bcc582d
cd build\bcc582d
cmake -DCMAKE_BUILD_TYPE=Debug -G "Borland Makefiles" ../..
make
cd ..\..
mkdir build\bcc582
cd build\bcc582
cmake -DCMAKE_BUILD_TYPE=Release -G "Borland Makefiles" ../..
make -DNDEBUG
cd ..\..

build_vc141.bat

@echo off
call "%VC141%\vcvarsall.bat" x86
mkdir build\vc141
cd build\vc141
cmake ../..
for %%a in (*.vcxproj) do msbuild %%a /m /p:Configuration=Debug
for %%a in (*.vcxproj) do msbuild %%a /m /p:Configuration=Release
cd ..\..

CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
project(foo CXX)
add_executable(foo main.cpp)

main.cpp テスト用サンプル

#include <iostream>
int main()
{
    using namespace std;
#ifdef NDEBUG
    cout << "Release(NDEBUG defined)" << endl;
#else
    cout << "DEBUG(NDEBUG not defined)" << endl;
#endif
#ifdef __BORLANDC__
    cout << "BORLANDC: " << hex << __BORLANDC__ << endl;
#endif    
#ifdef _MSC_VER
    cout << "MSC: " << _MSC_VER << endl;
#endif    
    return 0;
}