[CMake] How to generate a non-standard platform and non-standard project file with the Visual studio generator

jeff at 22ndtech.com jeff at 22ndtech.com
Tue Apr 16 23:28:58 EDT 2019


OK, no response yet.  I'm not sure if that means this is a problem that isn't interesting to most or if it is a good hard problem that no one knows how to solve.

Thinking a little more, I'm starting to lean toward a solution where I have a build_src folder where I put something like the sample .vcxproj file that I pasted in my first e-mail.  I can update the file substituting CMake variables for some of the information that needs to be updated and use configure_package_config_file() to replace the data according to the execution of cmake against the current CMakeLists.txt file.  Then, maybe I could copy the output file over the standard cmake process generated .vcxproj file as a post build step.  Not sure if this would work, particularly the bit about copying over the standard .vcxproj file, but one way to find out, right?

This is the approach I'm going to attempt unless anyone has a better suggestion.  Trying not to beg for help here.  😉

-----Original Message-----
From: CMake <cmake-bounces at cmake.org> On Behalf Of jeff at 22ndtech.com
Sent: Sunday, April 14, 2019 9:27 PM
To: cmake at cmake.org
Subject: [CMake] How to generate a non-standard platform and non-standard project file with the Visual studio generator

Hi all,

Do you have any suggestions for generation of a non-standard platform and project file from Visual Studio.  I'm trying to generate a file compatible with the Magic Leap Visual Studio Extension.  The first problem I have is that the platform is ML, not the standard x86 or x64.  The next problem is that it is not a standard msbuild project file, but an nmake file.  I've included the .vcxproj file from their simple OpenGL app sample below.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="$toolsversions$" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|ML">
      <Configuration>Debug</Configuration>
      <Platform>ML</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ML">
      <Configuration>Release</Configuration>
      <Platform>ML</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <!-- Project global & default -->
    <ProjectGuid>{"$mlprojguid$"}</ProjectGuid>
    <MLProjectFile>$mlprojfile$</MLProjectFile>
    <MLProjectKind>$mlprojkind$</MLProjectKind>
    <MLMfitExtraArgs>$ml_mfit_extra_args$</MLMfitExtraArgs>
  </PropertyGroup>
  <ItemGroup>
    <ProjectCapability Include="MLProject" />
    <ProjectCapability Include="NoVCDefaultBuildUpToDateCheckProvider" />
  </ItemGroup>
  <PropertyGroup>
    <PlatformTargetsFound>True</PlatformTargetsFound>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ML'"
Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <PlatformToolset>$platformtoolset$</PlatformToolset>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ML'"
Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <PlatformToolset>$platformtoolset$</PlatformToolset>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"
Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <PlatformToolset>$platformtoolset$</PlatformToolset>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"
Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <PlatformToolset>$platformtoolset$</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
 
<UseDefaultDebuggersPropertyPageSchemas>false</UseDefaultDebuggersPropertyPa
geSchemas>
    <UseDefaultPropertyPageSchemas>false</UseDefaultPropertyPageSchemas>
  </PropertyGroup>
  <ItemGroup>
    <PropertyPageSchema
Include="$(VCTargetsPath)$(LangID)\ProjectItemsSchema.xml" />
    <PropertyPageSchema
Include="$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\general.xaml">
      <Context>Project</Context>
    </PropertyPageSchema>
    <PropertyPageSchema
Include="$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\build.xaml" />
    <!-- Don't expose these to user any more as they are of little value to user... 04/11/17
    <PropertyPageSchema
Include="$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\intellisense.xaml"
/>
    -->
    <!--Only show this page if the project is to create a package. -->
    <PropertyPageSchema
Condition="$([System.String]::copy($(MLProjectFile)).ToLower().EndsWith('.pa
ckage'))" 
 
Include="$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\package_signing.xa
ml" />
    <PropertyPageSchema
Include="$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\build_events.xml"
/>
    <PropertyPageSchema Condition="'$(MLProjectKind)' == 'program'"
Include="
                        $(VCTargetsPath)$(LangID)\debugger_general.xml;
 
$(VCTargetsPath)$(LangID)\debugger_local_windows.xml;
 
$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\debugger.xaml" />
    <!-- Property sheet only rules -->
    <PropertyPageSchema
Include="$(VCTargetsPath)$(LangID)\general_makefile_ps.xml;$(VCTargetsPath)$
(LangID)\usermacros.xml">
      <Context>PropertySheet</Context>
    </PropertyPageSchema>
    <!-- File only rules -->
    <PropertyPageSchema
Include="$(VCTargetsPath)$(LangID)\general_file.xml">
      <Context>File</Context>
    </PropertyPageSchema>
  </ItemGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ML'">
    <MLSDK>$mlsdkpath$</MLSDK>
    <MLCertificateFile>$device_debug_certificate$</MLCertificateFile>
    <!--This should appear before <NMakeBuildCommandLine> -->
    <MLExtraBuildOption>$ml_extra_build_options$</MLExtraBuildOption>
    <MabuTargetFullSpec>$device_debug_full_spec$</MabuTargetFullSpec>
    <ExecutablePath>$(MLSDK);$(PATH)</ExecutablePath>
    <IncludePath />
    <ReferencePath></ReferencePath>
    <LibraryPath></LibraryPath>
    <NMakeBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_debug -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeBuildCommandLine>
    <NMakeReBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_debug -r -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeReBuildCommandLine>
    <NMakeCleanCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_debug -c -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeCleanCommandLine>
 
<NMakePreprocessorDefinitions>$device_debug_preprocessor_defines$</NMakePrep
rocessorDefinitions>
 
<NMakeIncludeSearchPath>$device_debug_include_paths$</NMakeIncludeSearchPath
>
 
<NMakeForcedIncludes>$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\ml_is.
h</NMakeForcedIncludes>
    <PackageFile>$device_debug_packagefile$</PackageFile>
    <IntDir>$device_debug_outputdir$</IntDir>
    <OutDir>$(ProjectDir)\$(IntDir)</OutDir>
    <NMakeOutput>$(IntDir)\$device_debug_outputfile$</NMakeOutput>
    <ELFFile>$(NMakeOutput)</ELFFile>
    <DebuggerFlavor>MLDebugger</DebuggerFlavor>
    <!-- following are defaults for debugger options -->
    <Attach>false</Attach>
    <EnableAutoStop>true</EnableAutoStop>
    <AutoStopAtFunction>main</AutoStopAtFunction>
    <EnablePrettyPrinting>true</EnablePrettyPrinting>
    <MLDownloadOnStart>true</MLDownloadOnStart>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ML'">
    <MLSDK>$mlsdkpath$</MLSDK>
    <MLCertificateFile>$device_release_certificate$</MLCertificateFile>
    <MLExtraBuildOption>$ml_extra_build_options$</MLExtraBuildOption>
    <MabuTargetFullSpec>$device_release_full_spec$</MabuTargetFullSpec>
    <ExecutablePath>$(MLSDK);$(PATH)</ExecutablePath>
    <IncludePath />
    <ReferencePath></ReferencePath>
    <LibraryPath></LibraryPath>
    <NMakeBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_release -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeBuildCommandLine>
    <NMakeReBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_release -r -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeReBuildCommandLine>
    <NMakeCleanCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t device_release -c -v --set-options=ide/visualstudio $(MLExtraBuildOption)</NMakeCleanCommandLine>
 
<NMakePreprocessorDefinitions>$device_release_preprocessor_defines$</NMakePr
eprocessorDefinitions>
 
<NMakeIncludeSearchPath>$device_release_include_paths$</NMakeIncludeSearchPa
th>
 
<NMakeForcedIncludes>$(LOCALAPPDATA)\Microsoft\VisualStudio\MagicLeap\ml_is.
h</NMakeForcedIncludes>
    <PackageFile>$device_release_packagefile$</PackageFile>
    <IntDir>$device_release_outputdir$</IntDir>
    <OutDir>$(ProjectDir)\$(IntDir)</OutDir>
    <NMakeOutput>$(IntDir)\$device_release_outputfile$</NMakeOutput>
    <ELFFile>$(NMakeOutput)</ELFFile>
    <DebuggerFlavor>MLDebugger</DebuggerFlavor>
    <!-- following are defaults for debugger options -->
    <Attach>false</Attach>
    <EnableAutoStop>false</EnableAutoStop>
    <AutoStopAtFunction></AutoStopAtFunction>
    <EnablePrettyPrinting>true</EnablePrettyPrinting>
    <MLDownloadOnStart>true</MLDownloadOnStart>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <MLSDK>$mlsdkpath$</MLSDK>
    <MLCertificateFile>$host_debug_certificate$</MLCertificateFile>
    <MLExtraBuildOption>$ml_extra_build_options$</MLExtraBuildOption>
    <MabuTargetFullSpec>$host_debug_full_spec$</MabuTargetFullSpec>
    <ExecutablePath>$(MLSDK);$(PATH)</ExecutablePath>
    <NMakeBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_debug -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeBuildCommandLine>
    <NMakeReBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_debug -r -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeReBuildCommandLine>
    <NMakeCleanCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_debug -c -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeCleanCommandLine>
 
<NMakePreprocessorDefinitions>$host_debug_preprocessor_defines$</NMakePrepro
cessorDefinitions>
 
<NMakeIncludeSearchPath>$host_debug_include_paths$</NMakeIncludeSearchPath>
    <PackageFile>$host_debug_packagefile$</PackageFile>
    <IntDir>$host_debug_outputdir$</IntDir>
    <OutDir>$(ProjectDir)\$(IntDir)</OutDir>
    <NMakeOutput>$(IntDir)\$host_debug_outputfile$</NMakeOutput>
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
    <!-- following are defaults for debugger options -->
    <Attach>false</Attach>
    <MLDownloadOnStart>true</MLDownloadOnStart>
    <!-- Set this for running with Simulator (ML Remote) -->
 
<LocalDebuggerEnvironment>PATH=$(MLSDK)\VirtualDevice\bin;$(MLSDK)\VirtualDe
vice\lib;$(MLSDK)\lib\win64</LocalDebuggerEnvironment>
    <!-- set this for launching Lumin RT examples -->
 
<LocalDebuggerWorkingDirectory>$(ProjectDir)\$ml_asset_folder$</LocalDebugge
rWorkingDirectory>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <MLSDK>$mlsdkpath$</MLSDK>
    <MLCertificateFile>$host_release_certificate$</MLCertificateFile>
    <MLExtraBuildOption>$ml_extra_build_options$</MLExtraBuildOption>
    <MabuTargetFullSpec>$host_release_full_spec$</MabuTargetFullSpec>
    <ExecutablePath>$(MLSDK);$(PATH)</ExecutablePath>
    <NMakeBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_release -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeBuildCommandLine>
    <NMakeReBuildCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_release -r -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeReBuildCommandLine>
    <NMakeCleanCommandLine>mabu $(MLProjectFile) MLSDK="$(MLSDK)" -t msvc-$msvcversion$_release -c -v VCDIR="$(VCInstallDir) $(MLExtraBuildOption)</NMakeCleanCommandLine>
 
<NMakePreprocessorDefinitions>$host_release_preprocessor_defines$</NMakePrep
rocessorDefinitions>
 
<NMakeIncludeSearchPath>$host_release_include_paths$</NMakeIncludeSearchPath
>
    <PackageFile>$host_release_packagefile$</PackageFile>
    <IntDir>$host_release_outputdir$</IntDir>
    <OutDir>$(ProjectDir)\$(IntDir)</OutDir>
    <NMakeOutput>$(IntDir)\$host_release_outputfile$</NMakeOutput>
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
    <!-- following are defaults for debugger options -->
    <Attach>false</Attach>
    <!-- Set this for running with Simulator (ML Remote) -->
 
<LocalDebuggerEnvironment>PATH=$(MLSDK)\VirtualDevice\bin;$(MLSDK)\VirtualDe
vice\lib;$(MLSDK)\lib\win64</LocalDebuggerEnvironment>
    <!-- set this for launching Lumin RT examples -->
 
<LocalDebuggerWorkingDirectory>$(ProjectDir)\$ml_asset_folder$</LocalDebugge
rWorkingDirectory>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
$mlprojsources$
$mlprojincludes$
$mlprojresources$
$mlotherfiles$
  <ItemGroup>
    <None Include="$mlprojfile$" />
  </ItemGroup>
</Project>

I've been thinking about several alternatives.  My first thought was to make modifications to the Visual Studio generator to support passing in the Platform and the options that I need but after reviewing the generator code, it looks like a monumental task, especially considering how many changes there are from a typical Visual Studio project file.  The second thought I had was to post process the build file using CMake string replace or python.
This seems like it would be much more manageable but before I went down that path I wanted to see if there is a more obvious way that is in better alignment with the CMake approach.  I've even been asking myself if it makes sense to use CMake for this at all or is it just too far outside of the typical use cases.

Any suggestions on the best path forward would be greatly appreciated.

Thanks,
Jeff

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list