0

In the premake lua script for my solution. How do i set it to create "/Yc" the phc instead of being set to use "/Yu" on first initialisation.

I have searched the online documentation and tried other help sites. I can't find any help.

I assume it's a build option but have tried buildoptions { "/Yc" }

Some help would be much appritiated?

Alice Turner
  • 81
  • 1
  • 9

3 Answers3

1

The solution was to set the correct path to the source file.

premake5.lua

pchheader "awepch.h"
pchsource "%{prj.name}/Src/awepch.cpp" // this is where the source file is located on disk

* Also it is mandatory that you use the correct case for the characters. If you use "pch.h" for a file name on disk that must be the file name in this section of your "premake5.lua" script

Sorry to take so long to deliver the answer :)

Alice Turner
  • 81
  • 1
  • 9
0

you need to specify

pchheader('StdAfx.h')

and

pchsource('StdAfx.cpp') 
Mihai Sebea
  • 398
  • 2
  • 10
  • Thank you for you reply. I have already put this links to the file locations in my code using `pchheader` and 'pchsource'. The issue is however, rather than set the "precompiled header" option to "Create (/Yc)" it sets it to "Use (/Yu)". On the first set up and build Premake should set this to "Create (/Yc)" and once the solution is built VS will automatically change it to "Use (/Yu)" but Premake intially sets this option to "Use (/Yu)" – Alice Turner Jul 06 '19 at 20:06
  • I will keep looking in to it @Mihai – Alice Turner Jul 10 '19 at 00:36
0

For the current version of premake v5. 0.0-beta1, you must do the following in order for the precompiled header to work across all IDEs (especially for Visual Studio):

  1. Put both pch.h and pch.cpp under the root directory of your project (not solution/workspace).

  2. Set the exact name (not a path) of the pch.h to pchheader().

  3. Set the full path of pch.cpp relative to premake5.lua script in pchsource(). This is IMPORTANT. I don't know why, but if you do not specify the full relative path, then premake will Use (/Yu) (use precompiled header) to the phc.cpp instead of Create (/Yc) (create precompiled header), which results in not creating the precompiled header in Visual Studio.

  4. Include the directory where pch.h and pch.cpp are located in includedirs()

  5. #include "pch.h" IN EVERY .cpp file in your project, IN THE FIRST LINE of each .cpp file. Remember: #include "pch.h", "pch.h" must be excactly the same as the string you set in pchheader() in your premake5.lua script.

  6. If you have .c files, you MUST rename them to .cpp instead, otherwise Visual Studio will complain about using a precompiled header that was compiled using a c++ compiler.

I know it's overcomplicated but this is how it is.

Example:

project "LearnGL"
    location "Projects/LearnGL/"
    kind "ConsoleApp"
    language "C++"
    targetdir "builds/"
    objdir "obj/%{prj.name}_%{cfg.shortname}"

    pchheader "pch.h" --Do not use paths here. Use directly the header file name
    pchsource "Projects/LearnGL/src/pch.cpp" --Full path MUST be specified relative to the premake5.lua (this) script.

    files {
        "Projects/LearnGL/src/**.h",
        "Projects/LearnGL/src/**.hpp",
        "Projects/LearnGL/src/**.cpp"
    }

    includedirs {
        "Projects/LearnGL/src/", --This is where pch.h and pch.cpp are located.
        "Projects/LearnGL/src/external/glad/include/",
        "Projects/LearnGL/src/external/stb_image/include/",
        "External/glfw/include/",
        "External/spdlog/include/"
    }
babaliaris
  • 663
  • 8
  • 16