I was encountering one weird problem while building one project with premake4. The following is the one minimal demo to reproduce it.

.
├── premake4.lua
├── src
│   └── premake4.lua
└── test
    └── premake4.lua

# ./premake4.lua
solution "mysolution"
  configurations { "Debug", "Release" }

  include("src")
  include("test")
  includedirs { "inc/" }

# ./src/premake4.lua
project "src-pro"
  kind "ConsoleApp"
  language "C"
  files "*.c"

# ./test/premake4.lua
project "test-pro"
  kind "ConsoleApp"
  language "C"
  files "*.c"

As far as I understand it, the includedirs should affect both projects in src and test. However, after a few runs, I discovered that it only worked with the one proceeding the includedirs directive. In other words, the include directories are reflected in the Makefile for test project, but not for src project in above example. The documentation says nothing about the ordering (sequence) of directives. Therefore, I had to look at the source code of premake4 to comprehend this behavior.

After a few hours struggling, I realized that includedirs works only with the current container, which could be one solution or one project, and in this case, it’s the project introduced by include. Actually, the semantics of above script would have been more clear if it’s indented this way:

solution "mysolution"
  configurations { "Debug", "Release" }

  include("src")
  include("test")
    includedirs { "inc/" }

premake4 (or lua) doesn’t care about indentation, but developers do. Once the problem is identified, the solution is pretty simple: just move the includedirs directive ahead of any include directives, like this:

solution "mysolution"
  configurations { "Debug", "Release" }

  includedirs { "inc/" }

  include("src")
  include("test")

§Conclusion

Both solution and project introduce one scope, and all the following parameters are tied to this scope, if it makes sense. The only way to end one scope is to start another scope, or EOF. Therefore, the bottom line is to put all the include directives in the beginning of the file.

§Reference