premake-core
premake-core copied to clipboard
Can't create a precompiled header for Visual Studio 2019
What are you trying to do? I'm trying to create a precompiled header for Visual Studio 2019.
What problem are you having?
My pchheader
is set correctly but my pchsource
is not. When I right click on the pch source file and go to Properties > Configuration Properties > C/C++ > Precompiled Headers
, my source file is set to Use (/Yu)
instead of Create (Yc)
.
What have you tried so far? I made minimal example to replicate my issue. My project structure is like so:
MyProject/
src/
main.cpp
pch.cpp
pch.h
PremakeConfig/
main.lua
premake.5.exe
My premake config is as follows:
workspace "MyWorkspace"
location ".."
startproject "MyProject"
configurations { "Debug", "Release" }
OutputDir = "%{cfg.buildcfg}"
TargetDir = "%{wks.location}/bin/%{OutputDir}"
ObjDir = "%{wks.location}/bin-int/%{OutputDir}"
project "MyProject"
kind "ConsoleApp"
location "%{wks.location}/%{prj.name}"
language "C++"
targetdir "%{TargetDir}/%{prj.name}"
objdir "%{ObjDir}/%{prj.name}"
pchheader "pch.h"
pchsource "%{prj.location}/src/pch.cpp"
files {
"%{prj.location}/src/**.h",
"%{prj.location}/src/**.cpp"
}
includedirs "%{prj.location}/src"
I ran the command .\premake5.exe --file="PremakeConfig\main.lua" vs2019
.
Explicitly adding every file in files
like so:
files {
"%{prj.location}/src/pch.h",
"%{prj.location}/src/pch.cpp",
"%{prj.location}/src/main.cpp"
}
solves the problem. The problem is that the real project I'm working on has a lot of files and I don't wan't to list them all in my config and have to change it every time I add a new file.
Is this a bug or is there something I'm not understanding about precompiled headers?
What version of Premake are you using? premake5 (Premake Build Script Generator) 5.0.0-alpha15
Thanks in advance.
Clément
After further investigation, I realized the problem came from the prj.location
token. I replaced it with ../%{prj.name}
(which is what prj.location
is in my case) and it worked.
I also tried %{wks.location}/%{prj.name}
but it didn't work so the problem might come from wks.location
.
Just a sanity check on this, are you intentionally setting the location to be the parent directory?. Also, should:
pchheader "pch.h"
be
pchheader "%{prj.location}/src/pch.h"
Yes, I'm intentionally setting the location to be the parent directory. Why can't pchheader
just be pch.h
if %{prj.location}/src
is in includedirs
?
Yes, I'm intentionally setting the location to be the parent directory. Why can't
pchheader
just bepch.h
if%{prj.location}/src
is inincludedirs
?
That would make sense if you could, just trying to grab information. I'm not very familiar with PCH, so I'll try to look into it more this weekend. Is this in a public repo or anything that I can pull to immediately test out this issue?
The small example is not in a repo. I attached a zip archive with all the files you need to test to this comment. You'll just have to run the batch file to generate the .sln
and .vcxproj
files.
Appreciated. I'll try to take a look over the coming weekend.
Thanks for your time :)
In case you haven't seen it already, this page in the user guide explains some hoops to jump through to get PCH working across tooling environments. Not sure if it actually applies to your case.
After further investigation, I realized the problem came from the
prj.location
token. I replaced it with../%{prj.name}
(which is whatprj.location
is in my case) and it worked. I also tried%{wks.location}/%{prj.name}
but it didn't work so the problem might come fromwks.location
.
I have been having this same issue. I came to this same conclusion, and it is consistently reproducible. It seems the the location
token doesn't expand correctly when used in the pchsource()
command. Neither wks
nor prj
work in this instance. When using the tokens for location the .vcxproj file will not contain the expected value of:
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
More specifically, it will only create the line <ClCompile Include="pch.cpp" />
It's also worth noting, I am using 5.0.0alpha16 on VStudio2019
Is there any update on this? I have the same problem