premake-core icon indicating copy to clipboard operation
premake-core copied to clipboard

Can Premake build directly like "cmake --build"?

Open jinq0123 opened this issue 8 years ago • 6 comments

cmake --build makes CMake ideal for CI(Continue Integrate). I think direct building is good for Premake to replace CMake. My problem is it is hard to build a library with Premake using conan package management. See conan issue https://github.com/conan-io/conan/issues/1559.

jinq0123 avatar Aug 01 '17 09:08 jinq0123

It can't... however, there is nothing stopping anyone from making a "build" action, and I've considered it a few times myself... I just haven't got the time for something elaborate as that right now. I'd help however with whoever wants to take that on.

tvandijck avatar Aug 01 '17 14:08 tvandijck

At least for VS this is quite a bit of work to do out-of-the-box without any third party dependencies.

We have some code to get Windows SDKs, Visual Studio SDKs aswell as MSBuild SDKs that could help if someone is interested: https://github.com/mono/CppSharp/blob/master/src/Core/Toolchains/MSVCToolchain.cs#L357

We could either bind the Windows registry APIs to Lua and port as much as possible of this code over, or just rely on https://github.com/Microsoft/vswhere but that only works for VS2017+.

tritao avatar Aug 17 '17 00:08 tritao

Just looked at how it works in CMake, it looks like they implement FindMakeProgram method for each generator

here's how it's implemented in VS gen

for vs it's a matter of finding devenv.exe or msbuild.exe and then execute it by passing generated sln

build command e.g. premake5 vs2017 --build would be a neat feature 😉 it needs to support choosing configuration too basically replicate https://cmake.org/cmake/help/v3.0/command/build_command.html

currently to build vs project from command-line you need msbuild or devenv in your PATH so you have to use VS command prompt or somehow add it

premake implements generators in Lua(as modules) so that would be handled differently here just like @tritao says.

the very first step would be to add build option in _premake_init.lua now this logic has to be located somewhere:

  • check if _OPTIONS["build"]
  • check current _ACTION
  • find a program for current _ACTION (e.g. msbuild.exe or devenv.exe for vs actions) (I propose to create scripts like tools/msbuildlocator.lua etc.)
  • somehow get the location of generated projects/solutions
  • invoke build command (os.execute perhaps?)

it would be nice if third party modules could make use of this feature too...so locating the tool would have to be a part of the module (it could be separated for official modules), no? maybe some global like _ACTION_BUILD_COMMAND that could be set from third-party-modules.

But before that can be done either

bind the Windows registry APIs to Lua

or

rely on https://github.com/Microsoft/vswhere

I think having access to the registry would be nicer, cmake doesn't rely on any external tools for that

@tvandijck please tell me how would you like it to be (how to organize it)

bugproof avatar Dec 22 '18 22:12 bugproof

The actions define a bunch of event functions - onWorkspace, onProject, et al - you can probably begin by adding one called onBuild and then start fleshing it out for the action you wish to start with. You're probably going to want to call it towards the end of this, probably right at the end.

samsinsane avatar Dec 23 '18 15:12 samsinsane

I started some work but I'm not promising anything, here are functions for finding devenv and/or msbuild

function findmsbuild(toolsVersion)
	local msBuildToolsPath = os.getWindowsRegistry("HKLM:SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\" .. toolsVersion .. "\\MSBuildToolsPath")
	local msBuildExePath = msBuildToolsPath:gsub("\\", "/") .. "MSBuild.exe"
	if os.isfile(msBuildExePath) then
		return msBuildExePath
	end
	return nil
end

function finddevenv(ideVersion)
	local arch = iif(os.is64bit(), "\\WOW6432Node\\", "\\")

	local vsPath = os.getWindowsRegistry("HKLM:SOFTWARE" .. arch .. "Microsoft\\VisualStudio\\" .. ideVersion .. "\\InstallDir")
	if vsPath ~= nil then
		local devenvPath = vsPath:gsub("\\", "/") .. "/devenv.com"
		if os.isfile(devenvPath) then
			return devenvPath
		end
	end

	vsPath = os.getWindowsRegistry("HKLM:SOFTWARE" .. arch .. "Microsoft\\VisualStudio\\SxS\\VS7\\" .. ideVersion)
	if vsPath ~= nil then
		local devenvPath = vsPath:gsub("\\", "/") .. "Common7/IDE/devenv.com"
		if os.isfile(devenvPath) then
			return devenvPath
		end
	end

	return nil
end

not sure where to put it yet... should it be a part of vstudio module or part of premake so all modules could access it? advices? also merry xmas 🎅

bugproof avatar Dec 24 '18 22:12 bugproof

My solution for Visual Studio is to build in a standalone bat:

-- Find msbuild.exe
for /f "delims=" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe') do (
	SET MSBUILD_PATH=%%i
)

-- Build
"%MSBUILD_PATH%" %ENGINE_ROOT_PATH%/build/Engine.sln /p:Configuration=Debug /p:Platform=x64

T-rvw avatar May 31 '22 06:05 T-rvw