Premake
I learned premake since libraries I use in my new project requires it. I found these.
- To change C/C++ compiler, use premake.gcc.cc/cxx or CC/CXX env vars.
- You can have ‘test’ configuration in a project, but you can’t change ‘files’ per configuration for now (will be supported in premake 4.5). -> I created ‘Test’ project.
- OSX has a problem in -Wl,-x handling. -> I added ‘Symbols’ in all build targets.
My sample premake.
-- premake4.lua solution "HogeSolution" configurations { "debug", "release" } -- switch gcc / clang --premake.gcc.cc = "gcc-5" --premake.gcc.cxx = "g++-5" premake.gcc.cc = "clang-3.6" premake.gcc.cxx = "clang++-3.6" -- per configuration file list is not supported as of 2015.8 -- will be supported in premake 4.5 -- http://stackoverflow.com/questions/9158151/premake-different-excludes-command-for-each-configuration -- A project defines one build target project "Hoge" kind "ConsoleApp" language "C++" buildoptions { "-std=c++11", "-Wall" } linkoptions { "-stdlib=libc++" } pchheader "pre.h" files { "**.h", "**.hpp", "**.cpp" } excludes { "*_test.cpp" } includedirs { } libdirs { "/usr/local/opt/llvm36/lib/llvm-3.6/lib" } links { } configuration "debug" defines { "DEBUG" } flags { "Symbols" } targetname "hoge-d" configuration "release" -- linker fails if you don't have "Symbols" on osx with -Wl,-x flags { "Symbols", "Optimize" } targetname "hoge" project "HogeTest" -- assume you have the following gmake setup -- 1. export REPO=your-local-repo-home -- 2. cd $REPO -- 3. git clone https://github.com/google/googletest -- 4. cd $REPO/googletest -- 5. cmake . -- 6. make -- env vars local repo = os.getenv("REPO") local gtest = repo .. "/googletest" kind "ConsoleApp" language "C++" buildoptions { "-std=c++11", "-Wall" } linkoptions { "-stdlib=libc++" } pchheader "pre.h" files { "**.h", "**.hpp", "**.cpp" } excludes { "main.cpp" } includedirs { gtest .. "/include" } libdirs { "/usr/local/opt/llvm36/lib/llvm-3.6/lib", gtest } links { "gtest_main", "gtest" } flags { "Symbols" } targetname "hoge-test"
How to run.
premake4 gmake make Hoge config=debug make Hoge config=release make HogeTest ./hoge-test Running main() from gtest_main.cc [==========] Running 2 tests from 1 test case. [----------] Global test environment set-up. [----------] 2 tests from HogeTest [ RUN ] HogeTest.Hoge1 [ OK ] HogeTest.Hoge1 (0 ms) [ RUN ] HogeTest.Hoge2 [ OK ] HogeTest.Hoge2 (0 ms) [----------] 2 tests from HogeTest (0 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (1 ms total) [ PASSED ] 2 tests. sample test: #include "hoge.hpp" #include "gtest/gtest.h" class HogeTest : public ::testing::Test { virtual void SetUp() {} }; TEST_F(HogeTest, Hoge1) { EXPECT_EQ(3, 3); } TEST_F(HogeTest, Hoge2) { Hoge h; int result = h.add(-2, 2); EXPECT_EQ(0, result); }