Premake :https://github.com/premake/premake-core
Premake 是一个基于 Lua 脚本语言的构建系统工具,用于生成项目文件和构建脚本,能够帮助开发者快速创建和配置跨平台的项目。
使用 Premake,开发者可以通过编写简单的 Lua 脚本来描述项目的结构和构建选项,Premake 会根据这些脚本生成特定平台(如 Windows、Linux、Mac 等)的项目文件和构建脚本,例如 Visual Studio 的 .sln 文件、Makefile 或 Xcode 的 .xcodeproj 文件等。
下载最新的windows release版本,不需要自己编译
解压后,只需要其中的premake.exe文件,放在项目路径中
完整的使用教学可以参考wiki
这是wiki的第一个premake使用示例
#include <stdio.h>
int main(void) {
puts("Hello, world!");
return 0;
}
在项目中创建一个文件 premake5.lua
workspace "HelloWorld"
configurations { "Debug", "Release" }
project "HelloWorld"
kind "ConsoleApp"
language "C"
targetdir "bin/%{cfg.buildcfg}"
files { "**.h", "**.c" }
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
稍微复杂点的使用(用于根据源代码生成VS的.sln),编写lua脚本
- 假设解决方案名称为MySolution,其中有两个项目,第一个MyProject1 是生成动态链接库供第二个项目MyApp使用
workspace "MySolution"
architecture "x64"
configurations
{
"Debug",
"Release",
"Dist"
}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.arcchitecture}"
project "MyProject1"
location "MyProject1"
kind "SharedLib"
language "C++"
targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}
include
{
"%{prj.name}/3rd/glfw/include"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "10.0.22000.0"
defines
{
"PLATFORM_WINDOWS",
"BUILD_DLL"
}
postbuildcommands
{
("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/MyApp")
}
filter "configurations:Debug"
defines "_DEBUG"
symbols "On"
filter "configurations:Release"
defines "_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "_DIST"
optimize "On"
project "MyApp"
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"
}
include
{
"%{prj.name}/vendor/spdlog/include",
"MyProject1/src"
}
links
{
"MyProject1"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "10.0.22000.0"
defines
{
"PLATFORM_WINDOWS"
}
filter "configurations:Debug"
defines "_DEBUG"
symbols "On"
filter "configurations:Release"
defines "_RELEASE"
optimize "On"
filter "configurations:Dist"
defines "_DIST"
optimize "On"
之后在lua所在路径打开CMD,输入 call premake5.exe vs2022
即可。
- premake5.exe如果不在同一路径下,则在前面加上它的相对路径如:
call premake/premake.exe vs2022;
- 目标vs版本可以自己选择
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)