该系列教程源自youtube的cherno的视频-GAME ENGINE series!
视频地址: https://www.youtube.com/watch?v=vtWdgtMo1T4
引擎源代码地址: https://github.com/TheCherno/Hazel
主要内容简介:
将使用第三方构建工具premake: https://github.com/premake/premake-core来自动生成平台项目文件
在premake: https://github.com/premake/premake-core/releases/tag/v5.0.0-alpha15下载最新版本 premake-5.0.0-alpha15-windows.zip
将premake-5.0.0-alpha15-windows.zip解压到 项目根目录/vendor/bin/premake/下
在项目根目录下 新建文本文件 命名为premake5.lua
premake5.lua
workspace "Hazel" --解决方案名称
architecture "x86_64" --编译平台 只编64位--(x86,x86_64,ARM)
configurations
{
"Debug",
"Release",
"Dist"
}
--临时变量 定义 输出目录
--详细的所有支持的tokens 可参考 [https://github.com/premake/premake-core/wiki/Tokens]
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
project "Hazel" --项目名称
location "Hazel" --相对路径
kind "SharedLib" --表明该项目是dll动态库
language "c++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")--输出目录
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")--中间临时文件的目录
files--该项目的文件
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}
includedirs--附加包含目录
{
"%{prj.name}/vendor/spdlog/include"
}
filter "system:windows"--windows平台的配置
cppdialect "c++17"
staticruntime "On"
systemversion "latest"
defines --预编译宏
{
"HZ_BUILD_DLL",
"HZ_PLATFORM_WINDOWS",
"_WINDLL",
"_UNICODE",
"UNICODE",
}
postbuildcommands -- build后的自定义命令
{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/Sandbox") --拷贝引擎dll库到sanbox.exe的同一目录下去
}
filter "configurations:Debug"
defines "HZ_DEBUG"
runtime "Debug"
symbols "on"
filter "configurations:Release"
defines "HZ_RELEASE"
runtime "Release"
optimize "on"
filter "configurations:Dist"
defines "HZ_DIST"
runtime "Release"
optimize "on"
project "Sandbox"
location "Sandbox"
kind "ConsoleApp"
language "c++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}
includedirs
{
"Hazel/vendor/spdlog/include",
"Hazel/src"
}
links
{
"Hazel"
}
filter "system:windows"
cppdialect "c++17"
staticruntime "On"
systemversion "latest"
defines
{
"HZ_PLATFORM_WINDOWS",
"_UNICODE",
"UNICODE",
}
filter "configurations:Debug"
defines "HZ_DEBUG"
runtime "Debug"
symbols "on"
filter "configurations:Release"
defines "HZ_RELEASE"
runtime "Release"
optimize "on"
filter "configurations:Dist"
defines "HZ_DIST"
runtime "Release"
optimize "on"
在项目根目录下 新建文本文件 命名为GenerateProjects.bat
GenerateProjects.bat
call vendor\bin\premake\premake5.exe vs2019
pause
双击执行GenerateProjects.bat即可 自动生成工程
打开vs build工程,注意第一遍可能由于目录还没生成 导致自定义的拷贝dll命令失败, 重新执行一次即可