Skip to content

Fix: GCC ninja module pchheader generation#2692

Merged
nickclark2016 merged 3 commits into
premake:masterfrom
ngorden:gcc-ninja-pchheader
May 29, 2026
Merged

Fix: GCC ninja module pchheader generation#2692
nickclark2016 merged 3 commits into
premake:masterfrom
ngorden:gcc-ninja-pchheader

Conversation

@ngorden
Copy link
Copy Markdown
Contributor

@ngorden ngorden commented May 28, 2026

What does this PR do?

  • fixes Clang/GCC pchheader command to remove path duplication in generated build.ninja files

How does this PR change Premake's behavior?

  • writes correct ninja rules on clang for Unix machines

Anything else we should know?

given a dummy project with the following structure:

$ tree
.
├── build.ninja
├── HostApp
│   ├── HostApp.ninja
│   ├── include
│   │   └── pch.h
│   ├── premake5.lua
│   └── src
│       └── main.cc
├── premake5.lua
├── provision.sh
├── README.md
├── run-tests
└── Vagrantfile

4 directories, 11 files
$ cat HostApp/premake5.lua 
project "HostApp"
    kind "ConsoleApp"
    language "C++"
    cppdialect "C++17"

    files { "src/*.cc" }
    includedirs { "include" }
    pchheader "pch.h"%   

premake v5.0.0-beta8 generated build.ninja:

$ cat HostApp/HostApp.ninja
...
build HostApp/obj/Debug/pch.h.gch | HostApp/obj/Debug/pch.h.gch.d: pch_clang HostApp/HostApp/include/pch.h # <- pch.h doesn't exist here
  cflags = $cxxflags_HostApp_Debug
  depfile = HostApp/obj/Debug/pch.h.gch.d
build HostApp/obj/Debug/main.o: cxx_clang HostApp/src/main.cc | HostApp/obj/Debug/pch.h.gch
  cxxflags = $cxxflags_HostApp_Debug -include obj/Debug/pch.h # <- pch.h doesn't exist here
build HostApp/bin/Debug/HostApp: link_clang HostApp/obj/Debug/main.o
  ldflags = $ldflags_HostApp_Debug

$ ninja
ninja: error: 'HostApp/HostApp/include/pch.h', needed by 'HostApp/obj/Debug/pch.h.gch', missing and no known rule to make it

post-changes output:

$ cat HostApp/HostApp.ninja
...
build HostApp/obj/Debug/pch.h.gch | HostApp/obj/Debug/pch.h.gch.d: pch_gcc HostApp/include/pch.h
  cflags = $cxxflags_HostApp_Debug
  depfile = HostApp/obj/Debug/pch.h.gch.d
build HostApp/obj/Debug/main.o: cxx_gcc HostApp/src/main.cc | HostApp/obj/Debug/pch.h.gch
  cxxflags = $cxxflags_HostApp_Debug -I HostApp/include -include HostApp/obj/Debug/pch.h
build HostApp/bin/Debug/HostApp: link_gcc HostApp/obj/Debug/main.o
  ldflags = $ldflags_HostApp_Debug

$ ninja
[1/3] Generating precompiled header HostApp/include/pch.h
[2/3] Compiling C++ source HostApp/src/main.cc
[3/3] Linking target HostApp/bin/Debug/HostApp

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

@ngorden ngorden force-pushed the gcc-ninja-pchheader branch from 0eb58a7 to 83a4093 Compare May 28, 2026 13:57
Comment thread modules/ninja/ninja_cpp.lua
@nickclark2016
Copy link
Copy Markdown
Member

Verified these changes locally. Leaving open for ~24 hours for comments before merging. Thank you!

@nickclark2016 nickclark2016 merged commit 13ade0e into premake:master May 29, 2026
53 checks passed
@ngorden ngorden deleted the gcc-ninja-pchheader branch May 29, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants