# Order of arguments in commands

**URL:** https://discourse.cmake.org/t/order-of-arguments-in-commands/4245
**Category:** Code
**Created:** [October 11, 2021, 1:11pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245 "2021-10-11T13:11:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Panu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@Panu](https://discourse.cmake.org/u/Panu)
#### Post date: [October 11, 2021, 1:11pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245/1 "2021-10-11T13:11:04Z")

</div>

Should the arguments be given to commands in the same order as in command documentation? For example, there’s `install` command in [tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html):

> install(EXPORT MathFunctionsTargets  
> FILE MathFunctionsTargets.cmake  
> DESTINATION lib/cmake/MathFunctions  
> )

Here the order of options is EXPORT, FILE and DESTINATION but in the [documentation](https://cmake.org/cmake/help/latest/command/install.html#export) the order is EXPORT, DESTINATION and FILE.

It seems that in many commands any order will work but is that by design?

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [October 11, 2021, 1:20pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245/2 "2021-10-11T13:20:52Z")

</div>

In most commands the only important thing is to match `ARG_NAME` and `ARG_VALUE` correctly and the order of those doesn’t matter. It, of course, only stands if there are named arguments. Positional arguments have fixed order.

---

<div class="post-metadata">

### Author: ![Panu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@Panu](https://discourse.cmake.org/u/Panu)
#### Post date: [October 11, 2021, 1:59pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245/3 "2021-10-11T13:59:24Z")

</div>

Does that also apply to arguments without value? For example, can `EXCLUDE_FROM_ALL` in [install](https://cmake.org/cmake/help/latest/command/install.html#export) command be placed anywhere in the command invocation?

What about the commands where the order of arguments do matter? Is it always mentioned in the documentation or how can one know in which commands the order matters and in which it doesn’t?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 11, 2021, 2:04pm UTC](https://discourse.cmake.org/t/order-of-arguments-in-commands/4245/4 "2021-10-11T14:04:03Z")

</div>

The only positional arguments can appear in the beginning of the argument list. Anything without a dedicated `KEYWORD`-like argument signifier can be assumed to be positional (e.g., in `add_library(tgt)`, `tgt` is positional and must be first).
