MantisBT - CMake
View Issue Details
0014673CMakeCMakepublic2013-12-30 05:562016-06-10 14:31
jujjyl 
Kitware Robot 
normalfeaturealways
closedmoved 
Windows
 
 
0014673: Add support for targeting a custom Visual Studio Platform?
CMake is not able to target custom target Platforms when generating Visual Studio projects files.
Looking through the sources, I notice that CMake hardcodes the Solution Platform property of the generated project files, instead of allowing toolchain files to choose which Platform to generate project+solution files for.

There are multiple Visual Studio/MSBuild projects in development that create new custom build Platforms into VS itself, see e.g. the following:

https://github.com/juj/vs-tool [^] (I am the author of this)
  - Adds new platforms "Clang", "Emscripten", "MinGW" and "NaCl"
https://code.google.com/p/vs-android/ [^]
  - Adds new platform for Android
https://developers.google.com/native-client/devguide/devcycle/vs-addin#install [^]
  - Adds new platform for NaCl.

These plugins are more featured than just wrapping NMake/MinGW Make/Cygwin Make Makefile invocations to drive the build. The approach is that they implement a new MSBuild platform target DLLs written in .Net that enable MSBuild to build for those platforms, presenting integrated project property pages for the platforms.

I see that CMake hardcodes support in the sources for only the MS built-in platforms "win32", "x64" and "Itanium". I would like to be able to generate Visual Studio project files for CMake projects for the above platforms, so that I can use the VS IDE to edit and build the project for those targets.

To see what it would require to add support for the Emscripten platform, I forked the CMake sources and hacked a few commits in that let me do basic CMake+Visual Studio+Emscripten targeting. In the end, I only needed to do one change:

https://github.com/juj/CMake/commit/b526ab42492ec1dfc999d85c15b6e930ebb0afe7 [^]

The generator object gets allocated all the way in the startup of CMake, so I could not make a string property in the CMake toolchain script that would define the target Platform. I resorted to using the convention of parsing that -G "Visual Studio 10 <foo>" will generate for the VS Platform "foo".

This let me do (at least basic) builds of CMake projects for Emscripten. I suspect though that in the long run, there would be need to be able to add custom XML properties in the generated VS project files that are platform-specific. For example, I initially had to remove this hardcoded logic: https://github.com/juj/CMake/commit/ea37570f1a682dfd017fbbed72de7cd3b18d8a4c [^] , but later on, we added a workaround to Emscripten compiler itself so that it doesn't get confused by this directive: https://github.com/kripken/emscripten/pull/1946 [^] .

I think there are too many target Platform plugins out there in development that it doesn't make sense to hardcode support for each of them specifically into the CMake C++ sources. Perhaps it would be best to develop some kind of generic set of CMake variables/functions for supporting customizing VS project file generation, so that the toolchain.cmake files for each platform could then configure in detail what they need to generate in the VS project XML files.

What do you think about all this? How would this be accomplished cleanly?

Best Regards,
   Jukka
No tags attached.
Issue History
2013-12-30 05:56jujjylNew Issue
2014-01-02 15:09Brad KingNote Added: 0034899
2014-05-20 12:58Tim A.Note Added: 0035901
2014-09-22 18:04pchandra25Note Added: 0036851
2014-09-24 09:01Brad KingNote Added: 0036862
2016-06-10 14:29Kitware RobotNote Added: 0042455
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0034899)
Brad King   
2014-01-02 15:09   
Patrick added support for WinCE target platform generators that are not hard-coded in C++ but rather loaded from the available tools on the system. This "generator factory" work can probably be extended to more platforms.
(0035901)
Tim A.   
2014-05-20 12:58   
I am also porting my project to support a closed hardware platform. My issues can also be resolved by way of the one change jujjyl made in his fork. Ultimately, the target platform name needs to line up with the platform name expected by a proprietary debugger plug-in. Would it be possible to integrate this functionality into the main release? Otherwise, a VS_TARGET_NAME or similar property would be lovely.
(0036851)
pchandra25   
2014-09-22 18:04   
Just want to add a vote for this feature. I applied the patch and it opens up Visual Studio for a couple of additional platforms that I need to support, which is much more pleasant than a text editor.
(0036862)
Brad King   
2014-09-24 09:01   
Recently in the development version of CMake support for a CMAKE_GENERATOR_PLATFORM variable was added specifically to set the <Platform></Platform> value in .vcxproj files. Support was merged by the following commits:

 Merge topic 'vs-generator-platform'
 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0a92b23c [^]

 Merge topic 'vs-generator-platform'
 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b2348366 [^]

One can try it out with the nightly sources or builds:

 http://www.cmake.org/files/dev/?C=M;O=D [^]
(0042455)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.