This article is aimed at doing all the preparation work before coding. It includes the construction of the project structure, the configuration of the project, and the introduction to third-party libraries.
Creating the project
The recommended IDE is visual studio 2022. This project also works for Visual Studio 2017 and 2019. The test on other IDE hasn’t been done.
Create a static library as our engine project, so that it could be statically linked to our game application.
This project would become our engine project. Other than that, we have to create an empty project in this solution which will become our game application.
Here I’ll name the engine project “Illusion”.
Project Structure
Game and Illusion could be included in a single folder, such as Root. In my project, I included them in a folder called Collection. So the structure looks like this:
Game
The Game project, includes: src/… folder, assets/shaders/… folder, and assets/textures/… folder.
The src folder contains all the source code for the game application
The shaders folder contains customized shaders and the textures folder contains all kinds of texture resources.
Illusion
The Illusion project, includes: Lib/… folder, and src/Engine/… folder
In the src folder, the source code is separated into different folders based on their function, such as Core, Event, Renderer, etc.
The content in the Lib folder would be explained in the third parties part below.
Lib
The third-party library or tools that are not necessary for the Illusion Engine and Game Application, but is helpful when we build the whole project, such as premake, cmake, etc.
Either Illusion or Game could be executed without the existence of premake, but premake could help us get rid of configuring the project over and over again.
Scripts
The bat files that calls premake or clean up the project.
As a result, the final structure of the project looks like this:
A command line utility that reads a scripted definition of a software project, then uses it to perform build configuration tasks or generate project files.
All of these libraries could be found on GitHub. You could click on the name of the library to jump to its page on Github.
SpdLog, GLFW, Glad, ImGui, and glm are included in Collection/Illusion/Lib… folder.
Premake is included in Collection/Lib/… folder.
Configurations
Since we have premake, we could add a configuration file for our projects.
Inside Collection/… folder, create a file called “premake” and revise its extension to “.lua”.
-- Set up a workspace, this would work for every project workspace "Project" architecture "x64" -- Set the starting project to be Game startproject "Game" -- Define Build Configuration configurations { "Debug", "Release", "Dist" } -- Set the output file format to be like "Debug-Windows-x86_64" outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" -- Include directories relative to the root folder (solution directory) IncludeDir = {} IncludeDir["GLFW"] = "Illusion/Lib/GLFW/include" IncludeDir["Glad"] = "Illusion/Lib/Glad/include" IncludeDir["ImGui"] = "Illusion/Lib/imgui" IncludeDir["glm"] = "Illusion/Lib/glm" IncludeDir["stb_image"] = "Illusion/Lib/stb_image" -- Include these folders to load the configuration files at those positions include "Illusion/Lib/GLFW" include "Illusion/Lib/Glad" include "Illusion/Lib/imgui" -- Define Illusion Project, set the relative path, set the kind to be a static library, and set the language project "Illusion" location "Illusion" kind "StaticLib" language "C++" cppdialect "C++17" staticruntime "on" -- Set the output path and intermediate path targetdir ("bin/" .. outputdir .. "/%{prj.name}") objdir ("bin-int/" .. outputdir .. "/%{prj.name}") -- Define the precompile header pchheader "pch.h" pchsource "Illusion/src/pch.cpp" -- Define files that would be compiled files { "%{prj.name}/src/**.h", "%{prj.name}/src/**.cpp", "%{prj.name}/Lib/stb_image/**.h", "%{prj.name}/Lib/stb_image/**.cpp", "%{prj.name}/Lib/glm/glm/**.hpp", "%{prj.name}/Lib/glm/glm/**.inl", } -- Preprocess macros defines { "_CRT_SECURE_NO_WARNINGS" } -- Define include path includedirs { "%{prj.name}/src", "%{prj.name}/Lib/spdlog/include", "%{IncludeDir.GLFW}", "%{IncludeDir.Glad}", "%{IncludeDir.ImGui}", "%{IncludeDir.glm}", "%{IncludeDir.stb_image}" } -- Link these libraries to the project links { "GLFW", "Glad", "ImGui", "opengl32.lib" } -- Define some macros for different build options filter "system:windows" systemversion "latest"
After this, the configuration information for the whole project is recorded. To build the project, we only have to call premake5 and tell it the toolset that we are using:
1
> Lib/Premake5/Premake5.exe vs2022
To simplify this procedure, we need a bat file inside Collection/Scripts/… folder.
Inside Build.bat, enter the code:
1 2 3 4 5 6 7 8
@echo off pushd C: cd Program Files (x86)\Microsoft Visual Studio\Installer for /f "delims=" %%t in ('vswhere.exe -property catalog_productLineVersion') doset version=%%t popd cd ..\ call Lib\premake5\Premake5.exe vs%version% PAUSE
This file would figure out the version of visual studio installed on this device and pass it to premake to generate the correct version of project files such as .vs, .sln, .vcproj, etc.
Inside Clear.bat, enter the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
cd ..\ rd /s /q .vs rd /s /q bin rd /s /q bin-int del /a Project.sln del /a /s *.vcxproj.* pushd Illusion\Lib\Glad rd /s /q bin rd /s /q bin-int popd pushd Illusion\Lib\GLFW rd /s /q bin rd /s /q bin-int popd pushd Illusion\Lib\imgui rd /s /q bin rd /s /q bin-int popd PAUSE
This file would delete all the project files, including .vs, .sln, .vcproj, etc. Only source code would be left. It is a tool that helps us clean up the project and save space.
Thus, by running Build.bat and Clear.bat, we could easily generate or clean up the project.
Conclusion
So far, we have completed the configuration of the entire project. We stored the configuration information in premake.lua, and handed over the creation and cleaning of the project to the batch files to complete. By doing so, we don’t have to configure the project and struggle with the linkclude problem over and over again.