Support for Android CMake projects in Visual Studio

CMake is a cross-platform project generator that enables reuse of shared C++ code across multiple IDE and project systems.

We made a change to CMake to support our Android toolchain in Visual Studio. With this change, you can take your existing CMake project targetting Android, and with minimal modifications, you can have it open in Visual Studio, and benefit from our rich IDE experience for Android.

We have contributed to the Microsoft CMake open source github repository, and we are planning to work with Kitware to integrate those changes into the public CMake repository.

A CMake toolchain file is not required, the example is self-contained. We care a great deal about usability and made sure the minimum amount of information is fed into the system by the users. The only information required is the system name.

Known issues and limitations

Currently we only support libraries, object, static, or dynamic. We do not support the packaging project (Java), which is used as a bootstrapper, we are planning to add support for it soon.

We only support x86 and ARM architectures, we are planning to add support for x64 and ARM64 soon.

What’s next?

Going forward, we will add x64 and ARM64, as well as packaging project support. We will also work with Kitware to integrate this work into the public CMake repository.

We hope you find this support useful in your CMake projects and we look forward to your feedback and suggestions on how to improve this support. For more news on this front please reach out to us directly or follow us on VCBlog and our Visual C++ cross-platform page.

Tags

Join the conversation

Do you see any chance that this feature propagate over to other cross-platform and native tools alike outside the scope of Android? I am aware that cross-platform is a must in mobile development, but there are other use cases as well. Perhaps CMake-ifying the experience of remote GCC debugging instead of using an NMake project? The GCC support sure could use some more automation.

By the way, VS2015 installs its own Android SDK right? So if I got everything (SDK, NDK) already installed "manually", i.e. the original one from Google, VS can't make use of it, or can it? So basically at the moment I got everything twice on my harddrive? It's all quite big, so it would be great if MS would just use the original stuff!

@Paul Panther, The Visual Studio installer has an option to install the Android SDK (and NDK), but you don't have to install it if you already have it installed or you want to install and use a different version of the SDK or NDK, you can just point Visual Studio to it. Yo can do it from Tools – Options – Cross Platform – C++ – Android, or you can override the "VS_AndroidHome" MSBUILD property. This is not exposed thru CMake, but we could add a variable which sets this if you think that would be useful.

@David Hunter, unfortunately this specifically targets Android, and I can't comment on clang/c1, could you send me an email at Ion dot Todirel@microsoft.com, and I'll connect you with the PMs owning this experience.

I understand the question about NTest, but not sure I understand the other scenario, for the GCC/NMake question If I understand your question correctly, I believe this is a matter of how you write your CMake scripts, and what your asking for is in a way a redirection? It sounds interesting, we'd be interested in hearing more about this and the scenarios you have in mind, could you drop me an email at Ion dot Todirel@microsoft.com, and we can talk more about this offline?

@Anup Walvekar, sorry to hear that, what version of Visual Studio do you use, and could you tell me about the environment (OS, version, etc.) in which the CMake projects were generated, and also, if different, the environment where the CMake projects were opened in Visual Studio, are those two different environments or same machine? Could you also share the version of CMake used to generate the projects with? Could it be an older version? you can try typing "where cmake"and see where it points to, and run "cmake -version". Could you also share the console output when you ran "cmake -G…"?

Some debugging (–debug–trycompile) revealed that msbuild unable to build the compiler identification project because PlatformToolset is not set. So I added that to the cmake command line (-T Clang_3_6) but this has no affect because the generated project has the <PlatformToolset> element in commented out!

Just tried it today to build an SDL2 based application. Some of the flags used by are not detected. Some android-specific file are not built. I haven’t figured out whose false was it (probably the SDL2’s CMAKE script is not written properly somehow though). Anyway after I manually added some file into the project, the code starts to build.

I have a number of OpenGL ES function’s ‘undefined reference’ error during the linking stage and still trying to figure out how to solve. I’ve added the linker flag manually to link against GLESv2, but the reference error still persists. Can you please see if you can identify the problem ?

Interested to see if these get any traction in mainline CMake with relation to existing toolchain support and existing projects like https://github.com/taka-no-me/android-cmake and its forks. The latter can use visual studio, but only as a task executor, as far as I know.

What would be really handy is the ability to export our solution to a cmake file for beuilding on other platforms, but doing all the dev VS. Even better would be to extend the Android support to allow us to build & debug Linux programs from VS, so I can write in VS and build for Win & Linux (ideally Mac too).