premake / premake-core

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

Workspace vpaths overriding project ones #2293

Open UAVXP opened 1 month ago

UAVXP commented 1 month ago

Hello. I have a question about vpaths inheritance.

I want to make a separate (or rather additional) set of vpaths in my project.

This is the project tree:

src_main
    appframework/
...
    public/
        appframework/
            AppFramework.h
            IAppSystem.h
    premake5.lua

src_main/premake5.lua:

workspace "everything"
...
    vpaths {
        ["Header Files"] = { "**.h", "**.hpp" },
        ["Source Files"] = { "**.c", "**.cpp" },
        ["Shaders"] = { "**.fxc", "**.psh", "**.vsh" },
    }
...
    group "Common"
    include "appframework"

And this is what I have in src_main/appframework/premake5.lua:

local prj = project("appframework")
...
    files {
        ...
    }
    vpaths {
        ["Interface"] = "../public/appframework/**.h"
    }

Seems like Premake only considers the main vpaths (from workspace), but not the vpaths from "appframework" project. It puts headers from src_main/public/appframework to a "Header Files" filter in the final ".vcxproj.filters" file, but not "Interface".

How can I accomplish the desired functionality?

UAVXP commented 5 days ago

Here's the example project I made to show an issue: premake_vpaths_inheritance.zip

Archive hierarchy:

premake_vpaths_inheritance
    myproject/ - example project folder
    premake5/ - compiled premake-core binaries from https://github.com/premake/premake-core/commit/1a804088d6062814d79f22b292a3f471786d9fe7
    public/ - custom headers for myproject
    premake5.lua

If you want - you can use the latest official Premake build.

premake5.lua:

workspace "everything"

    configurations { "Debug", "Release" }

    vpaths {
        ["Header Files"] = { "**.h", "**.hpp" },
        ["Source Files"] = { "**.c", "**.cpp" },
    }

    group "Common"
    include "myproject"

myproject/premake.lua:

project "myproject"

    language "C++"
    kind "StaticLib"
    targetname "%{prj.name}"
    targetdir "%{cfg.buildcfg}"

    includedirs { "%{wks.location}/public" }

    files {
        "main.cpp",
        "main.h",

        "%{wks.location}/public/public_header.h",
    }

    vpaths {
        ["Interface"] = {

            -- These three does not work
            "%{wks.location}/public/**.h",
            "public/**.h",
            "**.h",

        },
    }

To run: premake5\premake5.exe vs2022

In the resulted myproject/myproject.vcxproj.filters you would see this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\public\public_header.h">
      <Filter>Header Files</Filter>
    </ClInclude>
    <ClInclude Include="main.h">
      <Filter>Header Files</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="main.cpp">
      <Filter>Source Files</Filter>
    </ClCompile>
  </ItemGroup>
</Project>

as opposed to vpaths settings from myproject/premake5.lua

UAVXP commented 1 day ago

No one knows what's going on here? Really? A month has been passed, and not one person replied to this issue

UAVXP commented 1 day ago

Also, if I cheat a little and do this in premake5.lua:

function defaultVpaths()
    vpaths {
        ["Header Files"] = { "**.h", "**.hpp" },
        ["Source Files"] = { "**.c", "**.cpp" },
    }
end

workspace "everything"

    configurations { "Debug", "Release" }

    -- vpaths {
        -- ["Header Files"] = { "**.h", "**.hpp" },
        -- ["Source Files"] = { "**.c", "**.cpp" },
    -- }

    group "Common"
    include "myproject"

and this in myproject/premake5.lua:

project "myproject"

    language "C++"
    kind "StaticLib"
    targetname "%{prj.name}"
    targetdir "%{cfg.buildcfg}"

    includedirs { "%{wks.location}/public" }

    files {
        "main.cpp",
        "main.h",

        "%{wks.location}/public/public_header.h",
    }

    defaultVpaths()
    vpaths {
        ["Interface"] = {

            -- These three does not work
            "%{wks.location}/public/**.h",
        --  "public/**.h",
        --  "**.h",

        },
    }

then, for some reason, public/public_header.h filter becomes public and not Interface:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
    </Filter>
    <Filter Include="public">
      <UniqueIdentifier>{A4949D15-9036-C8EB-79F1-DB3F65324F3C}</UniqueIdentifier>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\public\public_header.h">
      <Filter>public</Filter>
    </ClInclude>
    <ClInclude Include="main.h">
      <Filter>Header Files</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="main.cpp">
      <Filter>Source Files</Filter>
    </ClCompile>
  </ItemGroup>
</Project>

I don't even know what's going on with vpaths anymore...

UAVXP commented 1 day ago

This:

defaultVpaths = {
    ["Header Files"] = { "**.h", "**.hpp" },
    ["Source Files"] = { "**.c", "**.cpp" },
}

workspace "everything"

    configurations { "Debug", "Release" }

    -- vpaths {
        -- ["Header Files"] = { "**.h", "**.hpp" },
        -- ["Source Files"] = { "**.c", "**.cpp" },
    -- }

    group "Common"
    include "myproject"
project "myproject"

    language "C++"
    kind "StaticLib"
    targetname "%{prj.name}"
    targetdir "%{cfg.buildcfg}"

    includedirs { "%{wks.location}/public" }

    files {
        "main.cpp",
        "main.h",

        "%{wks.location}/public/public_header.h",
    }

    vpaths {
        defaultVpaths,
        ["Interface"] = {

            -- These three does not work
            "%{wks.location}/public/**.h",
            "%{wks.location}/public/*.h",
            "public/**.h",
            "public/*.h",
            "**.h",
            "*.h",

        },
    }

didn't work either

UAVXP commented 1 day ago
function test()
    local arr = {}
    arr["Header Files"] = { "**.h", "**.hpp" }
    arr["Source Files"] = { "**.c", "**.cpp" }
    return arr
end

workspace "everything"

    configurations { "Debug", "Release" }

    -- vpaths {
        -- ["Header Files"] = { "**.h", "**.hpp" },
        -- ["Source Files"] = { "**.c", "**.cpp" },
    -- }

    group "Common"
    include "myproject"
project "myproject"

    language "C++"
    kind "StaticLib"
    targetname "%{prj.name}"
    targetdir "%{cfg.buildcfg}"

    includedirs { "%{wks.location}/public" }

    files {
        "main.cpp",
        "main.h",

        "%{wks.location}/public/public_header.h",
    }

    vpaths {
        test(),

        ["Interface"] = {

            "%{wks.location}/public/**.h",
            "%{wks.location}/public/*.h",
            "public/**.h",
            "public/*.h",
            "**.h",
            "*.h",

        },

        ["Interface/*"] = {

            "%{wks.location}/public/**.h",
            "%{wks.location}/public/*.h",
            "public/**.h",
            "public/*.h",
            "**.h",
            "*.h",

        },

    }

It doesn't work. The myproject.vcxproj.filters file is still the same. I don't even fucking know, and this behavior (and the fact no one actually replied to me) drives me insane.

UAVXP commented 1 day ago

@starkos @samsinsane @nickclark2016 Please?

nickclark2016 commented 1 day ago

I don't have an answer for you, as I'm not terribly familiar with vpaths in Premake (hence why I didn't answer).

nickclark2016 commented 1 day ago

Looking further into your described behavior, this may be a bug.