Search code examples
c++testingcompilationpremake

Premake5 compiling additional executables


I am a bit stuck with premake atm. I want to add multiple test files, that, well, run tests. These executables are completely independent from each other and from the main.cpp file that actually generates the final executable.

I am not 100% sure how to indicate to premake to assemble build commands for the tests. I have read on modules and actions but I am not entirely sure they do what I need.

The documentation on modules doesn't seem to imply that this is their intended purpose.

Assume this is the test I want to run:

#include "gtest/gtest.h"

TEST(DummyTest, Negative) {

  EXPECT_EQ(1, 0);
  EXPECT_EQ(1, 1);
  EXPECT_GT(93, 0);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

How can I tell premake to compile and link this file independently to create a stand alone executable?


Solution

  • You'll need to create one project per executable you want to build.

    workspace "MyWorkspace"
       -- settings
    
    project "MyProject"
       -- settings
    
    project "DummyTest"
       -- settings
    
    -- repeat as needed
    

    You find it useful to create a function that can set up these test projects for you.

    function testProject(name)
        project(name)
        kind "ConsoleExe"
        -- etc.
    end
    
    testProject("DummyTest1")
    testProject("DummyTest2")
    

    If you're using Visual Studio, you may want to use a workspace group to organize these test projects within your workspace.