Premake4

以下の理由をでっちあげてPremake4を導入する。

  • 仕事で使う
  • そのうちマルチプラットホームに対応したい
  • VisualStudioでプロジェクト設定するのが面倒
  • Makefileをすみずみまで書くのも面倒

まず、ここからダウンロード。今回は"Windows + Visual C++ 2008 Express Edition"を対象ということでpremake-4.3-windows.zip。

展開したファイル(premake4.exe)をC:\premaketest\premake4.exeに配置。(パスの通ったところでもいい)

以下のファイルを作成。
[C:\premaketest\premake4.lua]

solution "HelloWorld"
configurations { "Debug", "Release" }

project "HelloWorld"
kind "ConsoleApp"
language "C++"
files { "hello.cpp" }

configuration "Debug"
defines { "_DEBUG" }
flags { "Symbols" }
targetname "hello_debug"

configuration "Release"
defines { "NDEBUG" }
flags { "Optimize" }
targetname "hello"

[C:\premaketest\hello.cpp]

#include 

int main()
{
printf("hello, world\n");
return 0;
}

コマンドプロンプトから

>premake4 vs2008

これで、HelloWorld.sln、HelloWorld.vcprojが生成される。

HelloWorld.slnをVisual C++ 2008 Express Editionで開いてビルドし,hello_debug.exeを作成。

コマンドプロンプトから

>hello_debug

hello, world

とりあえず動いた。

CygwinなどのMakefile環境向けには

>premake4 gmake

でとりあえずMakefileが生成されるみたい。