Skip to content

Commit 8bb73c0

Browse files
committed
Added more documentation for usages and uses
1 parent 62b9bc7 commit 8bb73c0

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

website/docs/Home.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 3 names of power. `PUBLIC` specifies that a usage will be applied to the project defining the usage and any project consuming the usage. `INTERFACE` specifies that a usage will be applied to only projects consuming the usage. Finally, `PRIVATE` specifies that a usage will only be applied to the project defining the usage. The self application properties of `PRIVATE` and `PUBLIC` will happen without any need to specify `uses` for that project. This is the same behavior as defining properties directly on the project. Additionally, these names of power allow users to specify the project name containing the usage block, rather than having to fully type out the usage block name, in the `uses` statement.
21+
22+
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.
23+
24+
```lua
25+
project "A"
26+
usage "PUBLIC"
27+
defines { "A_PUBLIC_DEF" }
28+
29+
project "B"
30+
usage "PUBLIC"
31+
uses { "A" }
32+
defines { "B_PUBLIC_DEF" }
33+
34+
project "C"
35+
-- C will now contain the defines { "A_PUBLIC_DEF", "B_PUBLIC_DEF" }
36+
uses { "B" }
37+
```
38+
39+
Similarly, for forcing consumers to link or depend on your project, we can specify a usage block as follows:
40+
41+
```lua
42+
project "MyLib"
43+
-- Force consumers to link MyLib, but do not force MyLib to link against it
44+
usage "INTERFACE"
45+
links { "MyLib" }
46+
47+
project "MyExe"
48+
-- MyExe will now link against MyLib
49+
uses { "MyLib" }
50+
```
51+
52+
### See Also ###
53+
54+
* [usage](usage.md)
55+
* [uses](uses.md)

website/sidebars.js

Lines changed: 1 addition & 0 deletions
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)