Skip to content

Commit 6b32d20

Browse files
committed
Add buildoptions, linkoptions support
1 parent 1fc5b66 commit 6b32d20

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

modules/ninja/ninja_cpp.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function m.generate(prj)
3434
_p("") -- Empty line at end of file
3535
end
3636

37-
-- Generate all ninja rules (compile, link, etc.)
3837
function m.rules(prj)
39-
-- Generate rules for each configuration to handle different toolsets
4038
local rulesDone = {}
4139

4240
for cfg in project.eachconfig(prj) do
@@ -304,6 +302,9 @@ function m.getCFlags(cfg, toolset)
304302

305303
local forceincludes = toolset.getforceincludes(cfg)
306304
flags = table.join(flags, forceincludes)
305+
306+
local buildopts = cfg.buildoptions or {}
307+
flags = table.join(flags, buildopts)
307308

308309
return flags
309310
end
@@ -323,6 +324,9 @@ function m.getCxxFlags(cfg, toolset)
323324

324325
local forceincludes = toolset.getforceincludes(cfg)
325326
flags = table.join(flags, forceincludes)
327+
328+
local buildopts = cfg.buildoptions or {}
329+
flags = table.join(flags, buildopts)
326330

327331
return flags
328332
end
@@ -333,6 +337,9 @@ function m.getLdFlags(cfg, toolset)
333337

334338
local toolFlags = toolset.getldflags(cfg)
335339
flags = table.join(flags, toolFlags)
340+
341+
local linkopts = cfg.linkoptions or {}
342+
flags = table.join(flags, linkopts)
336343

337344
local libdirs = toolset.getLibraryDirectories(cfg)
338345
flags = table.join(flags, libdirs)

modules/ninja/tests/test_ninja_config.lua

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,76 @@ target_MyProject_Debug = MyProject
370370
end
371371

372372

373+
--
374+
-- Check that buildoptions are included in flags.
375+
--
376+
377+
function suite.configVars_withBuildOptions_Linux()
378+
toolset "gcc"
379+
_OS = "Linux"
380+
kind "ConsoleApp"
381+
files { "main.cpp" }
382+
buildoptions { "-Wall", "-Wextra" }
383+
384+
local cfg = prepare()
385+
cpp.configurationVariables(cfg)
386+
387+
test.capture [[
388+
cflags_MyProject_Debug = -Wall -Wextra
389+
cxxflags_MyProject_Debug = -Wall -Wextra
390+
ldflags_MyProject_Debug = -s
391+
objdir_MyProject_Debug = obj/Debug
392+
targetdir_MyProject_Debug = bin/Debug
393+
target_MyProject_Debug = MyProject
394+
395+
]]
396+
end
397+
398+
399+
function suite.configVars_withBuildOptions_Windows()
400+
toolset "msc"
401+
_OS = "Windows"
402+
kind "ConsoleApp"
403+
files { "main.cpp" }
404+
buildoptions { "/W4", "/WX" }
405+
406+
local cfg = prepare()
407+
cpp.configurationVariables(cfg)
408+
409+
test.capture [[
410+
cflags_MyProject_Debug = /MD /W4 /WX
411+
cxxflags_MyProject_Debug = /MD /EHsc /W4 /WX
412+
ldflags_MyProject_Debug = /NOLOGO
413+
objdir_MyProject_Debug = obj/Debug
414+
targetdir_MyProject_Debug = bin/Debug
415+
target_MyProject_Debug = MyProject.exe
416+
417+
]]
418+
end
419+
420+
421+
function suite.configVars_withBuildOptions_Macosx()
422+
toolset "gcc"
423+
_OS = "macosx"
424+
kind "ConsoleApp"
425+
files { "main.cpp" }
426+
buildoptions { "-Wall", "-Wextra" }
427+
428+
local cfg = prepare()
429+
cpp.configurationVariables(cfg)
430+
431+
test.capture [[
432+
cflags_MyProject_Debug = -Wall -Wextra
433+
cxxflags_MyProject_Debug = -Wall -Wextra
434+
ldflags_MyProject_Debug = -Wl,-x
435+
objdir_MyProject_Debug = obj/Debug
436+
targetdir_MyProject_Debug = bin/Debug
437+
target_MyProject_Debug = MyProject
438+
439+
]]
440+
end
441+
442+
373443
---
374444
-- C/C++ flags function tests
375445
---

0 commit comments

Comments
 (0)