0
votes

I'm keeping all my source files in a separate location to keep my trunk clean and organized. I simply point to this "SourceCode" location within my lua files but set my "location" to a completely separate "builds" directory. For the most part, this produces exactly the type of behavior I want and seems to be an elegant solution. Except...

When I run premake to generate project files, it's creating Link elements for each (Compile element) file that is included. As a result, an extraneous folder is created upon opening the solution file. That folder is never used again.

Ex excerpt of generated project file:

<ItemGroup>
    <Compile Include="..\..\SourceCode\FileUtilities\FileUtilities.cs">
      <Link>SourceCode\FileUtilities\FileUtilities.cs</Link>
    </Compile>
    <Compile Include="..\..\SourceCode\FileUtilities\FileWriter.cs">
      <Link>SourceCode\FileUtilities\FileWriter.cs</Link>
    </Compile>
</ItemGroup>

Upon opening the solution in VS2013, a "bin" and "obj" folder are created (as needed). But an extra "SourceCode" directory (and its children) is also created yet never used again. Is there a flag I can use to simply tell premake to NOT include Link blocks within the project files?

I am using premake5.

Here's how my directory structure is set up:

\trunk\builds
\trunk\SourceCode\<Contains separate folders for each projects source code>
\trunk\premake\solutions\<contains premake solution files>
\trunk\premake\projects\<contains premake project files>
\trunk\premake\configurations\<contains premake configuration files>

template solution file, 'solution-Template.lua':

solutionName = "Template"

solution(solutionName)

    location("../../builds/" .. solutionName)

    --Include a configuration file to define all your build settings
    include "../configurations/configurations-Template.lua"

    --List all the projects contained in your solution.
    --Note: The first project will be the default StartUp project
    include "../projects/project-Template.lua"
    include "../projects/project-AnotherProject.lua"

template project file, 'project-Template.lua':

projectName = "Template"

buildLocation = projectName
if solutionName ~= nil then
    buildLocation = solutionName .. "/" .. projectName
end

project(projectName)

    location("../../builds/" .. buildLocation)

    --kind is the output type of the project.
    --https://github.com/premake/premake-core/wiki/kind
    kind "SharedLib"
    --language is the programming language the project is written in
    --https://github.com/premake/premake-core/wiki/language
    language "C#"
    targetdir("../../builds/" .. buildLocation .. "/bin/%{cfg.buildcfg}")

    --List all the files used in the project using relative paths
    --The wild card "*" works (e.g. *.cs). "**" checks all child folders
    files
    {
        "../../SourceCode/Template/File1.cs",
        "../../SourceCode/Template/File2.cs",
        "../../SourceCode/Template/Etc.cs"
    }

    --List all the libraries/references that your project uses, including 
    --other projects
    links 
    {
        "System",
        "Template"
    }

template configuration file, 'configurations-Template.lua':

configurations { "Debug", "Release" }

--Define the platform configuration names. These can be named anything.
--Visual Studio will default to the first value upon opening the solution.
--Note: Be careful, 'Win32' is a predefined name and will be replaced with 'x86' even if
--you set the architecture to "x64".
platforms { "Win64", "Win32" }

--Set all the filters needed to produce the desired build/platform configuration results.
--https://github.com/premake/premake-core/wiki/Configurations_And_Platforms
filter "configurations:Debug"
    defines { "DEBUG" }
    flags { "Symbols" }

filter "configurations:Release"
    defines { "NDEBUG" }
    optimize "On"

filter { "platforms:Win32" }
    system "Windows"
    architecture "x86"

filter { "platforms:Win64" }
    system "Windows"
    architecture "x64"

I would then run the following command from command prompt in \trunk\premake:

premake5 --file=./solutions/solution-Template.lua vs2013

This results in a folder being created in my \trunk\builds\ directory and a folder for each project being created within that. This is exactly what I want (and keeps my trunk organized and clean). However, upon opening the solution file in VS2013, a folders for my SourceCode directories are automatically created along with bin and obj folders but they aren't used for anything at all. As far as I can tell, it's because of the Link elements being added to the project files.

2
What version of premake are you using ? And would it be possible to have the hierarchy of your project + the relevent parts of the Premake script ?Citron
I edited my original post with more info. Thanks!Kevin Pick

2 Answers

1
votes

Usually Visual Studio insists that you keep your C# sources underneath your project directory. A good test would be try to create the same project layout manually in Visual Studio; it should create the same <Link> elements. If it doesn't, your best bet would probably be to open a new issue ticket with a quick description of how the Visual Studio markup differs from what Premake is generating.

Sorry, let me edit that to be more clear: the default files that Visual Studio creates (i.e. when you choose File > New Project…) are always in the same directory as the project file, or in a subdirectory of that location. If you try to add a new file to the project, VS will always place it in a folder underneath the project as well. In that case, no <Link> element is needed.

MyProject/MyProject.csproj
MyProject/src/Hello.cs  <--- in or under project directory, no link needed

You are trying to place your source files in a directory above the project file location.

MyProject/build/MyProject.csproj
MyProject/src/Hello.cs <--- not in or under project directory, needs link

If you move your src/ folder underneath the project file location, Premake will not add the <Link> element. And if you try to create the same layout--src/ located outside of the project directory--in Visual Studio, you'll find that it adds <Link> elements itself.

0
votes

I solved this by modifying vs2005_csproj.lua (and running 'premake5 embed' and then rebuilding premake). I added an "if _ACTION" condition at line 180.

if external then
--Change by Kpick, this is not needed (at least for vs2013)
    if _ACTION < "vs2013" then
        _p(3,'<Link>%s</Link>', path.translate(link))
    end
end

I should add that I haven't verified if the Link element is needed at all for any version of VS. I just know it's NOT needed for vs2013 and I didn't want to modify the source code any more than I had to.