windiws开发 linux生产,是一套综合起来比较好的做法,premake5 可通过lua脚本配置自动化生成vs工程和gmake工程,方便在linux和windows下开发和编译。
下面是一个例子,解决方案server 工程stick_engine 和app,其中stick_engine是生成静态库app生成可执行文件。
--[[
premake5.lua
windows: premake5.exe --os=windows vs2015
linux: premake5.exe --os=linux gmake
]]
workspace "server"
location (_ACTION) -- subdir vs2015 (or gmake, ...)
configurations { "Release", "Debug" }
platforms { "x64"}
targetdir "../bin/%{cfg.platform}/%{cfg.buildcfg}"
language "C++"
flags {
"C++11",
"StaticRuntime",
}
includedirs {
"../src/stick_engine",
"../src/stick_engine/3rd",
"../src/app",
"../deps/include",
"../external/include",
"../external/include/PhysX",
}
links {
"stick_engine",
"hiredis",
}
filter "configurations:Debug"
flags { "Symbols" }
defines { "DEBUG" }
filter "configurations:Release"
defines { "NDEBUG" }
optimize "Full"
filter {}
if os.is("windows") then
defines {
"_WIN32_WINNT=0x0600", -- i.e. Windows 7 target
"WIN32_LEAN_AND_MEAN", -- To fix error : WinSock.h has already been included
"NOMINMAX", -- To disable windows.h min/max.
"_CRT_SECURE_NO_WARNINGS", -- for strerror()
}
libdirs {
"../deps/lib_win64",
}
links {
"libeay32",
"ws2_32",
}
buildoptions { "/MP" }
filter "configurations:Debug"
libdirs { "../deps/lib_win64/Debug" }
links {
"libprotobufd",
}
filter "configurations:Release"
libdirs { "../deps/lib_win64/Release" }
links {
"libprotobuf",
}
linkoptions { "/SAFESEH:NO" }
filter {}
elseif os.is("linux") then
includedirs {
}
linkoptions { "-Wl,-E" }--
libdirs { "../deps/lib_centos" }
links {
"crypt",
"pthread",
"crypto",
"expat",
"sasl2",
"ssl",
"protobuf",
"tcmalloc_and_profiler",
"unwind",
"dl",
"m",
"rt",
"PhysX3_x64",
"PhysX3Extensions",
"PhysX3Common_x64",
"PhysX3Cooking_x64",
"PxFoundation_x64",
"PxPvdSDK_x64",
}
filter "configurations:Debug"
links {
}
filter "configurations:Release"
links {
}
end
project "stick_engine"
kind "StaticLib"
files {
"../src/stick_engine/**", -- *.cpp;h
}
if os.is("windows") then
includedirs {
}
buildoptions { "/MP" }
else
includedirs {
}
removefiles {
"../src/stick_engine/3rd/lua/*.cpp",
"../src/stick_engine/3rd/lua/*.h",
"../src/stick_engine/3rd/lua/*.c",
"../src/stick_engine/3rd/lua/*.hpp",
"../src/stick_engine/3rd/vld/*.cpp",
"../src/stick_engine/3rd/vld/*.h",
"../src/stick_engine/3rd/vld/*.c",
"../src/stick_engine/3rd/vld/*.hpp",
"../src/stick_engine/3rd/qiniu/*.cpp",
"../src/stick_engine/3rd/qiniu/*.h",
"../src/stick_engine/3rd/qiniu/*.c",
"../src/stick_engine/3rd/qiniu/*.hpp",
}
end
removelinks { "stick_engine" }
removelinkoptions { "/SAFESEH:NO" }
project "app"
kind "ConsoleApp"
targetname "stick_engine_app"
files {
"../src/app/**", -- *.cpp;h
}
includedirs {
"../src/app",
}
if os.is("windows") then
includedirs {
}
else
includedirs {
}
removefiles {
"../src/stick_engine/3rd/lua/*.cpp",
"../src/stick_engine/3rd/lua/*.h",
"../src/stick_engine/3rd/lua/*.c",
"../src/stick_engine/3rd/lua/*.hpp",
"../src/stick_engine/3rd/vld/*.cpp",
"../src/stick_engine/3rd/vld/*.h",
"../src/stick_engine/3rd/vld/*.c",
"../src/stick_engine/3rd/vld/*.hpp",
"../src/stick_engine/3rd/qiniu/*.cpp",
"../src/stick_engine/3rd/qiniu/*.h",
"../src/stick_engine/3rd/qiniu/*.c",
"../src/stick_engine/3rd/qiniu/*.hpp",
}
end
linux下cd到gmake目录 直接make即可