1

我想使用特定版本的 g++ installedvat /opt/blabla/bin/g++。

如何强制 premake 在 makefile 中添加 CXX 变量的初始化,使其指向特定位置?

我确实意识到一旦生成了makefile,我可以'make CXX = ...',但我想在自动生成的makefile中设置CXX。

使用 premake5,针对 gmake。

提前致谢

==============

更新:

通过戳示例和浏览代码,我发现我可以通过将此代码添加到 premake5.lua 中来做到这一点:

local GCC_BIN_PATH = "/opt/blala/bin"

-- start: setting gcc version
-- todo: consider moving this instrumentation into a side lua script
local gcc = premake.tools.gcc

gcc.tools = {
   cc = GCC_BIN_PATH.."/gcc",
   cxx = GCC_BIN_PATH.."/g++",
   ar = GCC_BIN_PATH.."/ar"
}

function gcc.gettoolname(cfg, tool)
   return gcc.tools[tool]
end
-- finish: setting gcc version

有没有更好的方法来实现同样的目标?特别是,重新定义 gettoolname 函数是否有意义?

4

3 回答 3

2

Same answer as above but more generic. This file can be named "add_new_gcc_toolset.lua":

local function add_new_gcc_toolset (name, prefix)
  local gcc                         = premake.tools.gcc
  local new_toolset                 = {}  
  new_toolset.getcflags             = gcc.getcflags
  new_toolset.getcxxflags           = gcc.getcxxflags
  new_toolset.getforceincludes      = gcc.getforceincludes
  new_toolset.getldflags            = gcc.getldflags
  new_toolset.getcppflags           = gcc.getcppflags
  new_toolset.getdefines            = gcc.getdefines
  new_toolset.getincludedirs        = gcc.getincludedirs
  new_toolset.getLibraryDirectories = gcc.getLibraryDirectories
  new_toolset.getlinks              = gcc.getlinks
  new_toolset.getmakesettings       = gcc.getmakesettings
  new_toolset.toolset_prefix        = prefix

  function new_toolset.gettoolname (cfg, tool)  
    if     tool == "cc" then
      name = new_toolset.toolset_prefix .. "gcc"  
    elseif tool == "cxx" then
      name = new_toolset.toolset_prefix .. "g++"
    elseif tool == "ar" then
      name = new_toolset.toolset_prefix .. "ar"
    end
    return name
  end  

  premake.tools[name] = new_toolset
end

return add_new_gcc_toolset
于 2015-04-23T08:04:53.363 回答
1

我认为官方的方式是创建自己的工具集。

下面的示例创建了一个名为“arm_gcc”的工具集:

premake.tools.arm_gcc         = {}

local arm_gcc                 = premake.tools.arm_gcc
local gcc                     = premake.tools.gcc

arm_gcc.getcflags             = gcc.getcflags
arm_gcc.getcxxflags           = gcc.getcxxflags
arm_gcc.getforceincludes      = gcc.getforceincludes
arm_gcc.getldflags            = gcc.getldflags
arm_gcc.getcppflags           = gcc.getcppflags
arm_gcc.getdefines            = gcc.getdefines
arm_gcc.getincludedirs        = gcc.getincludedirs
arm_gcc.getLibraryDirectories = gcc.getLibraryDirectories
arm_gcc.getlinks              = gcc.getlinks
arm_gcc.getmakesettings       = gcc.getmakesettings

function arm_gcc.gettoolname (cfg, tool)  
  local prefix = path.getabsolute ("../../arm_env")
  prefix       =  prefix .. "/arm_toolchain/bin/arm-linux-gnueabihf-"
  if     tool == "cc" then
    name = prefix .. "gcc"  
  elseif tool == "cxx" then
    name = prefix .. "g++"
  elseif tool == "ar" then
    name = prefix .. "ar"
  else
    name = nil
  end
  return name
end

然后你可以使用:

toolset "arm_gcc" 

在您的项目、过滤器等内部。

This method has the advantage that you aren't overwriting the regular gcc toolset. Both can coexist if necessary.

In my case I actually find cleaner to add each compiler in its own lua file and then include it from the main (premake5.lua) script.

于 2015-04-22T13:55:36.677 回答
0

as a workaround, I found this method:

makesettings [[
    CC = gcc
]]

https://github.com/premake/premake-core/wiki/makesettings

于 2019-04-29T22:12:43.287 回答