From c751f417dc21adea1594d8110839f695e0b0c788 Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 31 Jan 2013 01:44:08 +0000 Subject: [PATCH] Simplified the Premake build files. --- build/GenerateProjects.bat | 10 +---- build/Helpers.lua | 77 +++++++++++++++++++++++++++++++++++++ build/premake4.lua | 50 ++++++++++++------------ examples/Hello/premake4.lua | 71 ++++++++++++---------------------- src/Bridge/Bridge.lua | 16 +++----- src/Generator/Generator.lua | 19 ++++----- src/Parser/Parser.lua | 30 +++++++++------ 7 files changed, 160 insertions(+), 113 deletions(-) create mode 100644 build/Helpers.lua diff --git a/build/GenerateProjects.bat b/build/GenerateProjects.bat index 02cb8d1b..7a5d74f6 100644 --- a/build/GenerateProjects.bat +++ b/build/GenerateProjects.bat @@ -7,14 +7,12 @@ echo. echo [0] Clean echo [1] Visual C++ 2010 echo [2] Visual C++ 2012 -echo [3] CodeLite -echo [4] GNU Make +echo [3] GNU Make echo. :choice set /P C="Choice: " -if "%C%"=="4" goto gmake -if "%C%"=="3" goto codelite +if "%C%"=="3" goto gmake if "%C%"=="2" goto vs2012 if "%C%"=="1" goto vs2010 if "%C%"=="0" goto clean @@ -31,10 +29,6 @@ goto quit "premake4" --file=premake4.lua vs2012 goto quit -:codelite -"premake4" --file=premake4.lua codelite -goto quit - :gmake "premake4" --file=premake4.lua gmake goto quit diff --git a/build/Helpers.lua b/build/Helpers.lua new file mode 100644 index 00000000..997c628b --- /dev/null +++ b/build/Helpers.lua @@ -0,0 +1,77 @@ +-- This module checks for the all the project dependencies. + +action = _ACTION or "" + +depsdir = path.getabsolute("../deps"); +srcdir = path.getabsolute("../src"); +incdir = path.getabsolute("../inc"); +bindir = path.getabsolute("../bin"); +examplesdir = path.getabsolute("../examples"); +testsdir = path.getabsolute("../tests"); + +builddir = path.getabsolute("./" .. action); +libdir = path.join(builddir, "lib"); + +common_flags = { "Unicode", "Symbols" } +msvc_buildflags = { } -- "/wd4190", "/wd4996", "/wd4530" +gcc_buildflags = { "-std=gnu++11" } + +msvc_cpp_defines = { } + +function SetupNativeProject() + location (path.join(builddir, "projects")) + + c = configuration "Debug" + defines { "DEBUG" } + targetsuffix "_d" + + configuration "Release" + defines { "NDEBUG" } + + -- Compiler-specific options + + configuration "vs*" + buildoptions { msvc_buildflags } + defines { msvc_cpp_defines } + + configuration "gcc" + buildoptions { gcc_buildflags } + + -- OS-specific options + + configuration "Windows" + defines { "WIN32", "_WINDOWS" } + + configuration(c) +end + +function IncludeDir(dir) + local deps = os.matchdirs(dir .. "/*") + + for i,dep in ipairs(deps) do + local fp = path.join(dep, "premake4.lua") + fp = path.join(os.getcwd(), fp) + + if os.isfile(fp) then + print(string.format(" including %s", dep)) + include(dep) + end + end +end + +-- Examples helpers + +function SetupExampleProject() + SetupNativeProjects() + location (path.join(builddir, "deps")) +end + +function IncludeExamples() + print("Searching for examples...") + IncludeDir(examplesdir) +end + +function IncludeTests() + print("Searching for tests...") + IncludeDir(testsdir) +end \ No newline at end of file diff --git a/build/premake4.lua b/build/premake4.lua index d675ce0f..713188fa 100644 --- a/build/premake4.lua +++ b/build/premake4.lua @@ -2,38 +2,38 @@ -- It defines the common build settings that all the projects share -- and calls the build scripts of all the sub-projects. -action = _ACTION or "" -common_flags = { "Unicode", "Symbols" } - -common_msvc_copts = -{ - "/wd4146", "/wd4244", "/wd4800", "/wd4345", - "/wd4355", "/wd4996", "/wd4624", "/wd4291" -} +dofile "Helpers.lua" solution "Cxxi" - configurations - { - "Debug", - "Release" - } - + configurations { "Debug", "Release" } platforms { "x32" } + flags { common_flags } - objdir ( "obj/" .. action) - - targetdir ("../bin/") - debugdir ( "../bin/") - - configuration "Debug" - defines { "DEBUG" } + location (builddir) + objdir (builddir .. "/obj/") + targetdir (libdir) + libdirs { libdir } + debugdir (bindir) + + -- startproject "Generator" configuration "Release" - defines { "NDEBUG" } flags { "Optimize" } + + configuration "vs2012" + framework "4.5" + + configuration {} + + group "Examples" + IncludeExamples() + + group "Tests" + IncludeTests() - include "../src/Parser/Parser.lua" - include "../src/Bridge/Bridge.lua" - include "../src/Generator/Generator.lua" + group "Cxxi" + include (srcdir .. "/Bridge/Bridge.lua") + include (srcdir .. "/Generator/Generator.lua") + include (srcdir .. "/Parser/Parser.lua") diff --git a/examples/Hello/premake4.lua b/examples/Hello/premake4.lua index 147e5b3c..0cc81ab0 100644 --- a/examples/Hello/premake4.lua +++ b/examples/Hello/premake4.lua @@ -1,55 +1,34 @@ -common_flags = { } -- Otherwise /clr won't be enabled - bug ? - -solution "Hello" - platforms { "x32" } - configurations { "Debug", "Release" } - - objdir ( "./obj/" ) - targetdir ("./bin/") - debugdir ( "./bin/") - - configuration "Debug" - defines { "DEBUG", "WIN32" } - - configuration "Release" - defines { "NDEBUG", "WIN32" } - flags { "Optimize" } - project "Hello" - kind "SharedLib" - language "C++" - location "." - platforms { "x32" } - flags { common_flags, "Managed" } + SetupNativeProject() + kind "SharedLib" + language "C++" - configuration "*" - buildoptions { common_msvc_copts, "/clr" } + flags { common_flags, "Managed" } - files { "**.h", "**.cpp", "./*.lua" } + files { "**.h", "**.cpp", "./*.lua" } - -- Autogenerated files, so not available on first build - specify them manually - excludes { "CppCsBind/*.*" } - files { "CppCsBind/hello_wrapper.h", "CppCsBind/hello_wrapper.cpp" } - - configuration "hello.h" - buildrule { - description = "Compiling $(InputFile)...", - commands = { - '..\\..\\bin\\generator.exe -D=WIN32 -vs=10 -ns=CppCsBind -outdir=CppCsBind -I. hello.h', - }, - outputs = { "CppCsBind\\hello_wrapper.cpp" } - } - + -- Autogenerated files, so not available on first build - specify them manually + excludes { "CppCsBind/*.*" } + files { "CppCsBind/hello_wrapper.h", "CppCsBind/hello_wrapper.cpp" } + + configuration "hello.h" + buildrule { + description = "Compiling $(InputFile)...", + commands = { + '..\\..\\bin\\generator.exe -D=WIN32 -vs=10 -ns=CppCsBind -outdir=CppCsBind -I. hello.h', + }, + outputs = { "CppCsBind\\hello_wrapper.cpp" } + } project "SayHello" - kind "ConsoleApp" - language "C#" - location "." - platforms { "x32" } - files { "**.cs", "./*.lua" } + kind "ConsoleApp" + language "C#" + location "." + + files { "**.cs", "./*.lua" } + + links { "Hello" } + - links { "Hello" } - - diff --git a/src/Bridge/Bridge.lua b/src/Bridge/Bridge.lua index 5e1bc855..f474499b 100644 --- a/src/Bridge/Bridge.lua +++ b/src/Bridge/Bridge.lua @@ -1,18 +1,12 @@ project "Bridge" - kind "SharedLib" + kind "SharedLib" language "C#" - location "." - files { "*.cs" } - platforms { "x32" } - - configuration "Debug" - targetdir "../../bin" - - configuration "Release" - targetdir "../../bin" - + location "." + files { "*.cs" } + links { "System" } + if _ACTION == "clean" then os.rmdir("lib") end diff --git a/src/Generator/Generator.lua b/src/Generator/Generator.lua index 802c4602..19a6580d 100644 --- a/src/Generator/Generator.lua +++ b/src/Generator/Generator.lua @@ -1,15 +1,10 @@ project "Generator" - kind "ConsoleApp" - language "C#" - location "." - files { "**.cs", "**.bmp", "**.resx", "**.config" } - excludes { "Filter.cs" } - links { "Bridge", "System", "System.Core", "Parser" } - platforms { "x32" } - configuration "Debug" - targetdir "../../bin" - - configuration "Release" - targetdir "../../bin" + kind "ConsoleApp" + language "C#" + location "." + files { "**.cs", "**.bmp", "**.resx", "**.config" } + excludes { "Filter.cs" } + + links { "System", "System.Core", "Bridge", "Parser" } diff --git a/src/Parser/Parser.lua b/src/Parser/Parser.lua index 23071213..8774f45d 100644 --- a/src/Parser/Parser.lua +++ b/src/Parser/Parser.lua @@ -1,33 +1,41 @@ +clang_msvc_flags = +{ + "/wd4146", "/wd4244", "/wd4800", "/wd4345", + "/wd4355", "/wd4996", "/wd4624", "/wd4291" +} + project "Parser" kind "SharedLib" language "C++" - location "." - platforms { "x32" } - + SetupNativeProject() + + dependson "Bridge" flags { common_flags, "Managed" } - configuration "vs*" - buildoptions { common_msvc_copts } - -- usingdirs is only supported in per-file configs in our -- premake build. remove this once this support is added -- at the project level. - configuration { "Main.cpp" } + configuration { "*Main.cpp" } flags { "Managed" } - usingdirs { "../../bin/" } + usingdirs { libdir } - configuration { "Parser.cpp" } + configuration { "*Parser.cpp" } flags { "Managed" } - usingdirs { "../../bin/" } + usingdirs { libdir } + + configuration "vs*" + buildoptions { clang_msvc_flags } + files { "VSLookup.cpp" } configuration "*" files { "**.h", - "**.cpp", + "Main.cpp", + "Parser.cpp", "**.lua" }