Cherno youtube视频:https://www.youtube.com/watch?v=sULV3aB2qeU&list=PLlrATfBNZ98dC-V-N3m0Go4deliWHPFwT&index=7
premake: https://github.com/premake/premake-core
完整代码:https://github.com/DXT00/Hazel_study/tree/master/Premake
premake5.lua
workspace "Hazel"
architecture "x64"
configurations{
"Debug",
"Release",
"Dist"
}
outputDir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" --Debug-Windows-x64
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"
cppdialect "C++17"
staticruntime "On" --linking the runtime library
systemversion "latest"
defines
{
"HZ_BUILD_DLL",
"HZ_PLATFORM_WINDOWS",
}
--create a postbuild step to put the .dll where we want to be
postbuildcommands{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" ..outputDir.. "/Sandbox")
}
filter "configurations:Debug" --only apply to Debug configurations
defines "HZ_DEGUG"
symbols "On"
filter "configurations:Release" --only apply to Debug configurations
defines "HZ_RELEASE"
optimize "On"
filter "configurations:Dist" --only apply to Debug configurations
defines "HZ_DIST"
optimize "On"
project "Sandbox"
location "Sandbox"
kind "ConsoleApp" --.exe
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" --linking the runtime library
systemversion "latest"
defines
{
"HZ_PLATFORM_WINDOWS",
}
filter "configurations:Debug" --only apply to Debug configurations
defines "HZ_DEGUG"
symbols "On"
filter "configurations:Release" --only apply to Debug configurations
defines "HZ_RELEASE"
optimize "On"
filter "configurations:Dist" --only apply to Debug configurations
defines "HZ_DIST"
optimize "On"
注意:Sandbox需要链接Hazel
links{
"Hazel"
}
注意:
.. 是lua的字符串连接符
targetdir("bin/" .. outputDir .. "/%{prj.name}")
objdir("bin-int/" .. outputDir .. "/%{prj.name}")
使用postbuildcommands ---执行copy命令从Hazel复制.dll到 Sendbox
postbuildcommands :https://github.com/premake/premake-core/wiki/postbuildcommands
postbuildcommands{
("COPY %{cfg.buildtarget.relpath} ../bin" ..outputDir.. "/Sandbox")
}
tockens: https://github.com/premake/premake-core/wiki/Tokens
kind:https://github.com/premake/premake-core/wiki/kind
premake.exe 编译 premake5.lua
把命令写到.bat中:
GenerateProject.bat
call vendor\bin\premake\premake5.exe vs2017 premake5.lua
PAUSE
运行GenerateProject.bat
生成项目文件 .sln /bin /bin-int 等
打开.sln
可以看到premake已经帮我们自动设置了targetdir,objdir这些属性了
F5运行: