diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 8d003ea4..d04c112f 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -561,6 +561,13 @@ tokens = true, } + api.register { + name = "ignoredefaultlibraries", + scope = "project", + kind = "list:mixed", + tokens = true, + } + api.register { name = "icon", scope = "project", diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 7f6ec3cb..06d68759 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -401,6 +401,7 @@ m.generateMapFile, m.moduleDefinitionFile, m.treatLinkerWarningAsErrors, + m.ignoreDefaultLibraries, m.additionalLinkOptions, } end @@ -1231,6 +1232,21 @@ end + function m.ignoreDefaultLibraries(cfg) + if #cfg.ignoredefaultlibraries > 0 then + local ignored = cfg.ignoredefaultlibraries + for i = 1, #ignored do + -- Add extension if required + if not p.tools.msc.getLibraryExtensions()[ignored[i]:match("[^.]+$")] then + ignored[i] = path.appendextension(ignored[i], ".lib") + end + end + + m.element("IgnoreSpecificDefaultLibraries", condition, table.concat(ignored, ';')) + end + end + + function m.ignoreWarnDuplicateFilename(prj) -- VS 2013 warns on duplicate file names, even those files which are -- contained in different, mututally exclusive configurations. See: diff --git a/src/tools/msc.lua b/src/tools/msc.lua index 482ca362..113b827b 100644 --- a/src/tools/msc.lua +++ b/src/tools/msc.lua @@ -211,6 +211,16 @@ local map = iif(cfg.kind ~= premake.STATICLIB, msc.linkerFlags, msc.librarianFlags) local flags = config.mapFlags(cfg, map) table.insert(flags, 1, "/NOLOGO") + + -- Ignore default libraries + for i, ignore in ipairs(cfg.ignoredefaultlibraries) do + -- Add extension if required + if not msc.getLibraryExtensions()[ignore:match("[^.]+$")] then + ignore = path.appendextension(ignore, ".lib") + end + table.insert(flags, '/NODEFAULTLIB:' .. ignore) + end + return flags end @@ -262,7 +272,6 @@ return links end - -- -- Returns makefile-specific configuration rules. -- diff --git a/tests/actions/vstudio/vc2010/test_link.lua b/tests/actions/vstudio/vc2010/test_link.lua index 4f9b3768..6968df95 100644 --- a/tests/actions/vstudio/vc2010/test_link.lua +++ b/tests/actions/vstudio/vc2010/test_link.lua @@ -460,3 +460,37 @@ ]] end + +-- +-- Test ignoring default libraries with extensions specified. +-- + + function suite.ignoreDefaultLibraries_WithExtensions() + ignoredefaultlibraries { "lib1.lib", "lib2.obj" } + prepare() + test.capture [[ + + Windows + false + bin\Debug\MyProject.lib + lib1.lib;lib2.obj + + ]] + end + +-- +-- Test ignoring default libraries without extensions specified. +-- + + function suite.ignoreDefaultLibraries_WithExtensions() + ignoredefaultlibraries { "lib1", "lib2.obj" } + prepare() + test.capture [[ + + Windows + false + bin\Debug\MyProject.lib + lib1.lib;lib2.obj + + ]] + end diff --git a/tests/tools/test_msc.lua b/tests/tools/test_msc.lua index 37c8f26d..4c028b73 100644 --- a/tests/tools/test_msc.lua +++ b/tests/tools/test_msc.lua @@ -326,3 +326,19 @@ prepare() test.contains('/LIBPATH:"/usr/local/lib"', msc.getLibraryDirectories(cfg)) end + +-- +-- Check handling of ignore default libraries +-- + + function suite.ignoreDefaultLibraries_WithExtensions() + ignoredefaultlibraries { "lib1.lib" } + prepare() + test.contains('/NODEFAULTLIB:lib1.lib', msc.getldflags(cfg)) + end + + function suite.ignoreDefaultLibraries_WithoutExtensions() + ignoredefaultlibraries { "lib1" } + prepare() + test.contains('/NODEFAULTLIB:lib1.lib', msc.getldflags(cfg)) + end