premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.24k stars 618 forks source link

`forceinclude` option not working properly #2257

Open edo9300 opened 1 month ago

edo9300 commented 1 month ago

What seems to be the problem? I'm using premake with a project that has a structure like this

test
├── premake5.lua
└── subproject
    ├── forced-header.h
    ├── premake5.lua
    └── src
        └── source.cpp

this is the content of the topmost premake5.lua file

workspace "test"
location "build"
language "C++"
objdir "obj"
configurations { "Debug", "Release" }

include "subproject"

this is the content of the second premake5.lua

project "subproject"
    kind "StaticLib"
    files { "src/*.cpp" }   
    forceincludes { "forced-header.h" }

My intention is to have forced-header.h be included in all the files in the src folder, and as the docs say Paths should be specified relative to the currently running script file. Instead, the generated solutions don't work as expected, with the gmake2 and msvc targets also differing in their behaviour:

What did you expect to happen? The function behaves as described and the targets properly find the header, or at least "break" in a consistent way

How can we reproduce this?

What version of Premake are you using? premake5 (Premake Build Script Generator) 5.0.0-beta2

richard-sim commented 1 month ago

I think the issue is that you're not adding test/subproject/ to the include search path, i.e.:

project "subproject"
    kind "StaticLib"
    files { "src/*.cpp" }   
    forceincludes { "forced-header.h" }
        includedirs { "." }

/FI (MSVC) and --include (gcc, clang) basically just prepend the source files with #include "forced-header.h", and have no additional magic to find that file beyond how it finds any other include file (well, other than GCC will first search the preprocessors working directory for forced includes... for reasons. Hence the difference you see between MSVC and gmake2).

edo9300 commented 1 month ago

Yeah, that seemed to be it, I guess the docs need to be updated in case to specify that the folder must be aging the include directories