Skip to content

Commit 19b8ac0

Browse files
committed
Added the PROFILE flag for msc and Visual Studio
1 parent e22633d commit 19b8ac0

File tree

12 files changed

+159
-2
lines changed

12 files changed

+159
-2
lines changed

modules/vstudio/tests/vc2010/test_link.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,3 +767,33 @@
767767
</Link>
768768
]]
769769
end
770+
771+
772+
--
773+
-- Test for the Profile flag.
774+
--
775+
776+
function suite.profileOn()
777+
profile "On"
778+
prepare()
779+
test.capture [[
780+
<Link>
781+
<SubSystem>Windows</SubSystem>
782+
<ImportLibrary>bin\Debug\MyProject.lib</ImportLibrary>
783+
<Profile>true</Profile>
784+
</Link>
785+
]]
786+
end
787+
788+
789+
function suite.profileOff()
790+
profile "Off"
791+
prepare()
792+
test.capture [[
793+
<Link>
794+
<SubSystem>Windows</SubSystem>
795+
<ImportLibrary>bin\Debug\MyProject.lib</ImportLibrary>
796+
<Profile>false</Profile>
797+
</Link>
798+
]]
799+
end

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@
825825
m.additionalLinkOptions,
826826
m.programDatabaseFile,
827827
m.assemblyDebug,
828+
m.profile,
828829
}
829830
end
830831
end
@@ -2550,7 +2551,14 @@
25502551

25512552
function m.assemblyDebug(cfg)
25522553
if cfg.assemblydebug then
2553-
m.element("AssemblyDebug", nil, "true")
2554+
m.element("AssemblyDebug", nil, "true")
2555+
end
2556+
end
2557+
2558+
2559+
function m.profile(cfg)
2560+
if cfg.profile ~= nil then
2561+
m.element("Profile", nil, iif(cfg.profile, "true", "false"))
25542562
end
25552563
end
25562564

src/_premake_init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,12 @@
11881188
kind = "list:string",
11891189
}
11901190

1191+
p.api.register {
1192+
name = "profile",
1193+
scope = "config",
1194+
kind = "boolean"
1195+
}
1196+
11911197

11921198
-----------------------------------------------------------------------------
11931199
--

src/tools/clang.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
}),
6868
visibility = gcc.shared.visibility,
6969
inlinesvisibility = gcc.shared.inlinesvisibility,
70-
linktimeoptimization = gcc.shared.linktimeoptimization
70+
linktimeoptimization = gcc.shared.linktimeoptimization,
71+
profile = gcc.shared.profile,
7172
}
7273

7374
clang.cflags = table.merge(gcc.cflags, {
@@ -253,6 +254,7 @@
253254
end,
254255
},
255256
linker = gcc.ldflags.linker,
257+
profile = gcc.ldflags.profile,
256258
sanitize = table.merge(gcc.ldflags.sanitize, {
257259
Fuzzer = "-fsanitize=fuzzer",
258260
}),

src/tools/emcc.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ emcc.tools = {
1616
ar = "emar"
1717
}
1818

19+
-- Disable the default clang flags for profiling, since they don't work with emcc.
20+
--
21+
-- TODO: Investigate how to apply --cpuprofiler, --memoryprofiler, and ---threadprofiler
22+
-- flags correctly to emcc builds.
23+
emcc.shared.profile = nil
24+
emcc.ldflags.profile = nil
25+
1926
function emcc.gettoolname(cfg, tool)
2027
return emcc.tools[tool]
2128
end

src/tools/gcc.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
},
163163
inlinesvisibility = {
164164
Hidden = "-fvisibility-inlines-hidden"
165+
},
166+
profile = {
167+
On = "-pg",
165168
}
166169
}
167170

@@ -501,6 +504,9 @@
501504
Default = "",
502505
LLD = "-fuse-ld=lld"
503506
},
507+
profile = {
508+
On = "-pg",
509+
},
504510
sanitize = {
505511
Address = "-fsanitize=address",
506512
Thread = "-fsanitize=thread",

src/tools/msc.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@
386386
table.insert(flags, '/NODEFAULTLIB:' .. ignore)
387387
end
388388

389+
if cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp" or cfg.kind == "SharedLib" then
390+
if cfg.profile then
391+
table.insert(flags, "/PROFILE")
392+
end
393+
end
394+
389395
return flags
390396
end
391397

tests/tools/test_clang.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,25 @@
197197
test.contains("-O3", clang.getcflags(cfg))
198198
test.contains("-O3", clang.getcxxflags(cfg))
199199
end
200+
201+
--
202+
-- Test profiling flag
203+
--
204+
205+
function suite.flags_onProfileOff()
206+
profile "Off"
207+
208+
prepare()
209+
test.excludes({ "-pg" }, clang.getcflags(cfg))
210+
test.excludes({ "-pg" }, clang.getcxxflags(cfg))
211+
test.excludes({ "-pg" }, clang.getldflags(cfg))
212+
end
213+
214+
function suite.flags_onProfileOn()
215+
profile "On"
216+
217+
prepare()
218+
test.contains({ "-pg" }, clang.getcflags(cfg))
219+
test.contains({ "-pg" }, clang.getcxxflags(cfg))
220+
test.contains({ "-pg" }, clang.getldflags(cfg))
221+
end

tests/tools/test_gcc.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,3 +1252,25 @@ end
12521252
test.contains({ "-x objective-c++" }, gcc.getcflags(cfg))
12531253
test.contains({ "-x objective-c++" }, gcc.getcxxflags(cfg))
12541254
end
1255+
1256+
--
1257+
-- Test profiling flag
1258+
--
1259+
1260+
function suite.flags_onProfileOff()
1261+
profile "Off"
1262+
1263+
prepare()
1264+
test.excludes({ "-pg" }, gcc.getcflags(cfg))
1265+
test.excludes({ "-pg" }, gcc.getcxxflags(cfg))
1266+
test.excludes({ "-pg" }, gcc.getldflags(cfg))
1267+
end
1268+
1269+
function suite.flags_onProfileOn()
1270+
profile "On"
1271+
1272+
prepare()
1273+
test.contains({ "-pg" }, gcc.getcflags(cfg))
1274+
test.contains({ "-pg" }, gcc.getcxxflags(cfg))
1275+
test.contains({ "-pg" }, gcc.getldflags(cfg))
1276+
end

tests/tools/test_msc.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,26 @@ end
628628
test.contains("/DLL", msc.getldflags(cfg))
629629
end
630630

631+
function suite.ldflags_onProfile()
632+
kind "ConsoleApp"
633+
profile "On"
634+
prepare()
635+
test.contains("/PROFILE", msc.getldflags(cfg))
636+
end
631637

638+
function suite.ldflags_onNoProfile()
639+
kind "ConsoleApp"
640+
profile "Off"
641+
prepare()
642+
test.missing("/PROFILE", msc.getldflags(cfg))
643+
end
644+
645+
function suite.ldflags_onProfileInvalidKind()
646+
kind "StaticLib"
647+
profile "On"
648+
prepare()
649+
test.missing("/PROFILE", msc.getldflags(cfg))
650+
end
632651

633652
--
634653
-- Check handling of CLR settings.

0 commit comments

Comments
 (0)