[cmake-developers] Link element in C# project causing issues with binary dir

Robert Dailey rcdailey.lists at gmail.com
Fri Jun 29 16:12:46 EDT 2018


According to the code, the logic is wrong:

void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
  cmSourceFile const* sf, std::string& link)
{
  std::string f = sf->GetFullPath();
  if (!this->InSourceBuild) {
    const std::string stripFromPath =
      this->Makefile->GetCurrentSourceDirectory();
    if (f.find(stripFromPath) != std::string::npos) {
      link = f.substr(stripFromPath.length() + 1);
      if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
        link = l;
      }
      ConvertToWindowsSlash(link);
    }
  }
}


It's checking if the whole binary dir is rooted where source dir is,
instead it should be checking each file to see if they are descendents
of CMAKE_BINARY_DIR, and if so, use the <Link>, otherwise don't use
it. This allows <Link> to be variable between files in the project.

Does anyone know if there's already a function in CMake for checking
if a file is in the CMAKE_BINARY_DIR? Or do I have to write my own
code for that check?

On Fri, Jun 29, 2018 at 3:08 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> When I use configure_file() to generate AssemblyInfo.cs, which I allow
> to go to the CMAKE_CURRENT_BINARY_DIR, Visual Studio 2017 reports:
>
> Warning The file
> 'E:\code\layout-composer-build\Properties\AssemblyInfo.cs' could not
> be added to the project.  Cannot add a link to the file
> E:\code\layout-composer-build\Properties\AssemblyInfo.cs. This file is
> within the project directory tree.
>
> When I define a target using C# language, it adds this for files under
> the same directory as the generated CSPROJ file:
>
> <Compile Include="E:\code\layout-composer-build\Properties\AssemblyInfo.cs">
>   <Link>build\Properties\AssemblyInfo.cs</Link>
> </Compile>
>
> The CSPROJ file is located: E:\code\layout-composer-build\LayoutComposer.csproj
>
> Is there a way to make the <Link> element not needed in this scenario?


More information about the cmake-developers mailing list