Skip to content

Commit e22633d

Browse files
Merge pull request #2438 from nickclark2016/usages-tutorial
Added more documentation for usages and uses
2 parents 1d06f62 + f399db6 commit e22633d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

website/docs/Home.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Welcome to the **Premake 5 User Guide**!
2222
* [Configurations and Platforms](Configurations-and-Platforms.md)
2323
* [Filters](Filters.md)
2424
* [Build Settings](Build-Settings.md)
25+
* [Usages and Uses](Usages-and-Uses.md)
2526
* [Command Line Arguments](Command-Line-Arguments.md)
2627
* [Using Modules](Using-Modules.md)
2728
* [More Topics…](Topics.md)

website/docs/Usages-and-Uses.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Usages & Uses
3+
---
4+
5+
Defining how libraries of code are to be used is a crucial piece of any build system. Premake exposes this functionality via the `usage` and `uses` APIs. A `usage` specifies a reusable configuration scope which can be later consumed by `uses`.
6+
7+
Unlike other scopes, usages do not inherit their properties from their parent scopes. This is to ensure that consumers only receive the configuration explicitly specified by the usage block.
8+
9+
```lua
10+
project "A"
11+
defines { "A_PRIVATE_DEF" }
12+
usage "PUBLIC"
13+
defines { "A_PUBLIC_DEF" }
14+
15+
project "B"
16+
uses { "A" }
17+
-- B will now contain the defines { "A_PUBLIC_DEF" }
18+
```
19+
20+
Usage containers can be provided with any name, however Premake provides three names of power. These words of power allow specifying the name of a project in the `uses` field rather than having to specify the exact name of the usage block.
21+
22+
* `PRIVATE` specifies a usage block that will be applied only to the project defining the usage. This is the default behavior of properties defined outside of usage blocks in Premake.
23+
* `INTERFACE` specifies a usage block that will be applied only to any projects consuming the usage.
24+
* `PUBLIC` specifies a usage that will be applied to both the project defining the usage and any projects consuming the usage.
25+
26+
Usages are not applied recursively by default. This is to match the existing Premake behaviors where everything is private by default. In order to apply usages recursively, usage blocks can be utilized to specify which usages should be propagated to the children. This chain can be applied indefinitely by specifying the usages that should be applied in each project's `PUBLIC` block.
27+
28+
```lua
29+
project "A"
30+
usage "PUBLIC"
31+
defines { "A_PUBLIC_DEF" }
32+
33+
project "B"
34+
usage "PUBLIC"
35+
uses { "A" }
36+
defines { "B_PUBLIC_DEF" }
37+
38+
project "C"
39+
-- C will now contain the defines { "A_PUBLIC_DEF", "B_PUBLIC_DEF" }
40+
uses { "B" }
41+
```
42+
43+
Similarly, for forcing consumers to link or depend on your project, we can specify a usage block as follows:
44+
45+
```lua
46+
project "MyLib"
47+
-- Force consumers to link MyLib, but do not force MyLib to link against it
48+
usage "INTERFACE"
49+
links { "MyLib" }
50+
51+
project "MyExe"
52+
-- MyExe will now link against MyLib
53+
uses { "MyLib" }
54+
```
55+
56+
It's worth noting that `usage` blocks do not need to be named with a name of power. They can be specified and used as follows:
57+
58+
```lua
59+
project "A"
60+
usage "MyCustomUsageName"
61+
defines { "HelloWorld" }
62+
63+
project "B"
64+
uses { "MyCustomUsageName" }
65+
```
66+
67+
### See Also ###
68+
69+
* [usage](usage.md)
70+
* [uses](uses.md)

website/sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
'Configurations-and-Platforms',
2525
'Filters',
2626
'Build-Settings',
27+
'Usages-and-Uses',
2728
'Command-Line-Arguments',
2829
'Using-Modules',
2930
'Topics'

0 commit comments

Comments
 (0)