Skip to content

Commit

Permalink
Fix gmake action mixing up compilers from different toolsets.
Browse files Browse the repository at this point in the history
Due to Make behavior, specifically its default values to the CC and CXX
implicit rules, we could end up in a scenario where the gcc and clang
compilers would be used in the same project.

Be more explicit into using either the `cc` or `c++` system default
compilers when no toolset is specified, and `gcc` and `g++` compilers
when the `gcc` toolset is specified.

Fixes #2207.
  • Loading branch information
tritao committed Sep 1, 2024
1 parent db072b4 commit 1ff1bd8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
9 changes: 9 additions & 0 deletions modules/gmake/tests/cpp/test_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
function suite.usesCorrectTools()
make.cppTools(cfg, p.tools.gcc)
test.capture [[
ifeq ($(origin CC), default)
CC = cc
endif
ifeq ($(origin CXX), default)
CXX = c++
endif
ifeq ($(origin AR), default)
AR = ar
endif
RESCOMP = windres
]]
end
9 changes: 9 additions & 0 deletions modules/gmake2/tests/test_gmake2_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
function suite.usesCorrectTools()
gmake2.cpp.tools(cfg, p.tools.gcc)
test.capture [[
ifeq ($(origin CC), default)
CC = cc
endif
ifeq ($(origin CXX), default)
CXX = c++
endif
ifeq ($(origin AR), default)
AR = ar
endif
RESCOMP = windres
]]
end
19 changes: 16 additions & 3 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,16 @@
architecture = {
x86 = function (cfg)
local r = {}
if not table.contains(os.getSystemTags(cfg.system), "darwin") then
if not (table.contains(os.getSystemTags(cfg.system), "darwin")
or table.contains(os.getSystemTags(cfg.system), "emscripten")) then
table.insert (r, "-L/usr/lib32")
end
return r
end,
x86_64 = function (cfg)
local r = {}
if not table.contains(os.getSystemTags(cfg.system), "darwin") then
if not (table.contains(os.getSystemTags(cfg.system), "darwin")
or table.contains(os.getSystemTags(cfg.system), "emscripten")) then
table.insert (r, "-L/usr/lib64")
end
return r
Expand Down Expand Up @@ -667,6 +669,13 @@
-- default value should be used.
--

gcc.systemtools = {
cc = "cc",
cxx = "c++",
ar = "ar",
rc = "windres"
}

gcc.tools = {
cc = "gcc",
cxx = "g++",
Expand All @@ -684,5 +693,9 @@
if ((cfg.gccprefix or version ~= "") and gcc.tools[tool]) or tool == "rc" then
return (cfg.gccprefix or "") .. gcc.tools[tool] .. version
end
return nil
-- if no toolset was specified, then lets default to system tools
if cfg.toolset == nil then
return gcc.systemtools[tool]
end
return gcc.tools[tool]
end
15 changes: 12 additions & 3 deletions tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@

function suite.tools_onDefaults()
prepare()
test.isnil(gcc.gettoolname(cfg, "cc"))
test.isnil(gcc.gettoolname(cfg, "cxx"))
test.isnil(gcc.gettoolname(cfg, "ar"))
test.isequal("cc", gcc.gettoolname(cfg, "cc"))
test.isequal("c++", gcc.gettoolname(cfg, "cxx"))
test.isequal("ar", gcc.gettoolname(cfg, "ar"))
test.isequal("windres", gcc.gettoolname(cfg, "rc"))
end

function suite.tools_withGcc()
toolset "gcc"
prepare()
test.isequal("gcc", gcc.gettoolname(cfg, "cc"))
test.isequal("g++", gcc.gettoolname(cfg, "cxx"))
test.isequal("ar", gcc.gettoolname(cfg, "ar"))
test.isequal("windres", gcc.gettoolname(cfg, "rc"))
end

Expand Down

0 comments on commit 1ff1bd8

Please sign in to comment.