{"id":7251,"date":"2015-12-15T19:16:00","date_gmt":"2015-12-15T19:16:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/12\/15\/support-for-android-cmake-projects-in-visual-studio\/"},"modified":"2021-10-05T14:41:47","modified_gmt":"2021-10-05T14:41:47","slug":"support-for-android-cmake-projects-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/support-for-android-cmake-projects-in-visual-studio\/","title":{"rendered":"Support for Android CMake projects in Visual Studio"},"content":{"rendered":"<p><a href=\"https:\/\/cmake.org\/\">CMake <\/a>is a cross-platform project generator that enables reuse of shared C++ code across multiple IDE and project systems.\nWe made a change to CMake to support our Android toolchain in <a href=\"https:\/\/www.visualstudio.com\/en-us\/downloads\/download-visual-studio-vs.aspx\">Visual Studio<\/a>. 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.\nWe have contributed to the Microsoft CMake <a href=\"https:\/\/github.com\/Microsoft\/CMake\/tree\/feature\/VCMDDAndroid\">open source github repository<\/a>, and we are planning to work with Kitware to integrate those changes into the public CMake repository.\nBut currently, this is what you have to do to get going.\nAs a prerequisite,<a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2014\/11\/12\/cross-platform-mobile-development-with-visual-c.aspx\"> please install the Android MDD package<\/a> in Visual Studio.<\/p>\n<h2>Getting CMake<\/h2>\n<p>Go to the VCMDDAndroid branch on the <a href=\"https:\/\/github.com\/Microsoft\/CMake\/tree\/feature\/VCMDDAndroid\">Microsoft CMake repository<\/a>.<\/p>\n<ul>\n<li>Click the Download ZIP button and download an offline copy of the VCMDDAndroid branch, unzip the archive.<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7282.p1.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7282.p1.jpg\" alt=\"Image 7282 p1\" width=\"1013\" height=\"517\" class=\"alignnone size-full wp-image-29243\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7282.p1.jpg 1013w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7282.p1-300x153.jpg 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7282.p1-768x392.jpg 768w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/><\/a><\/li>\n<li>Install CMake 3.4.1 from <a href=\"https:\/\/cmake.org\/download\/\">https:\/\/cmake.org\/download\/<\/a>, this is necessary to build CMake itself, the Win32 Installer is recommended.<\/li>\n<li>Run <em>cmake -G \u201cVisual Studio 14\u201d<\/em> on the unzipped archive, this should be run from the root folder of CMake. This will take a good 15 minutes or so.<\/li>\n<\/ul>\n<p>This will use the Visual Studio 2015 generator, and generate Visual Studio projects. The goal is to build CMake in Visual Studio.\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7024.p2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7024.p2.png\" alt=\"Image 7024 p2\" width=\"976\" height=\"353\" class=\"alignnone size-full wp-image-29242\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7024.p2.png 976w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7024.p2-300x109.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7024.p2-768x278.png 768w\" sizes=\"(max-width: 976px) 100vw, 976px\" \/><\/a>After CMake runs, you should have the Visual Studio projects in the out directory.<\/p>\n<ul>\n<li>Run <em>msbuild cmake.sln<\/em>, this will build CMake. You can run msbuild from a <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms229859(v=vs.110).aspx\">VS2015 Developer Command Prompt<\/a>.<\/li>\n<\/ul>\n<p>The compiled binaries will be in the bin\\Debug folder.<\/p>\n<ul>\n<li>Either add the output directory to PATH, or make sure to run cmake.exe from this directory, so it runs the modified version of CMake and not the installed one.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/8726.p3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/8726.p3.png\" alt=\"Image 8726 p3\" width=\"882\" height=\"631\" class=\"alignnone size-full wp-image-29244\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/8726.p3.png 882w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/8726.p3-300x215.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/8726.p3-768x549.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/a><\/p>\n<h2>Building your CMake projects<\/h2>\n<p>The following example illustrate the capabilities of the generator and the CMake\u00a0variables.\nRun <em>cmake -G \u201cVisual Studio 14 ARM\u201d \u2013DCMAKE_SYSTEM_NAME=VCMDDAndroid<\/em> to generate the Visual Studio projects.\nYou can remove the ARM specifier to compile for x86.\nHere\u2019s the content of the CMakeLists.txt. You can also find a link to this short sample below.\n<span style=\"font-family: courier new,courier\">cmake_minimum_required(VERSION 3.4)<\/span>\n<span style=\"font-family: courier new,courier\">project (Sample)<\/span>\n<span style=\"font-family: courier new,courier\">add_library(Sample STATIC sample.cpp)<\/span>\n<span style=\"font-family: courier new,courier\"># demo of the variables being set when VCMDDAndroid is targeted<\/span>\n<span style=\"font-family: courier new,courier\">if(VC_MDD_ANDROID AND VC_MDD_ANDROID_VERSION MATCHES &#8220;1.0&#8221;)<\/span>\n<span style=\"font-family: courier new,courier\">\u00a0 message(&#8220;VCMDDAndroid 1.0&#8221;)<\/span>\n<span style=\"font-family: courier new,courier\">else()<\/span>\n<span style=\"font-family: courier new,courier\">\u00a0 if(CMAKE_GENERATOR MATCHES &#8220;Visual Studio 14&#8221; AND CMAKE_SYSTEM_NAME MATCHES &#8220;VCMDDAndroid&#8221;)<\/span>\n<span style=\"font-family: courier new,courier\">\u00a0\u00a0\u00a0 message(&#8220;VCMDDAndroid&#8221;)<\/span>\n<span style=\"font-family: courier new,courier\">\u00a0 endif()<\/span>\n<span style=\"font-family: courier new,courier\">endif()<\/span>\n<span style=\"font-family: courier new,courier\"># optional, demo of the VC_MDD_ANDROID* properties<\/span>\n<span style=\"font-family: courier new,courier\">set_property(TARGET Sample PROPERTY VC_MDD_ANDROID_USE_OF_STL &#8220;c++_static&#8221;)<\/span>\n<span style=\"font-family: courier new,courier\">set_property(TARGET Sample PROPERTY VC_MDD_ANDROID_API_LEVEL &#8220;android-21&#8221;)<\/span>\nA 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.\nOpen and build the generated projects in <a href=\"https:\/\/www.visualstudio.com\/en-us\/downloads\/download-visual-studio-vs.aspx\">Visual Studio<\/a>.\n<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4.png\" alt=\"Image 3733 p4\" width=\"1115\" height=\"740\" class=\"alignnone size-full wp-image-29241\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4.png 1115w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4-300x199.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4-1024x680.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/3733.p4-768x510.png 768w\" sizes=\"(max-width: 1115px) 100vw, 1115px\" \/><\/a><\/p>\n<h2>Known issues and limitations<\/h2>\n<ol>\n<li>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.<\/li>\n<li>We only support x86 and ARM architectures, we are planning to add support for x64 and ARM64 soon.<\/li>\n<\/ol>\n<h2>What\u2019s next?<\/h2>\n<p>Going forward, we will add x64 and ARM64, as well as packaging project support. We will also\u00a0work with Kitware to integrate this work into the public CMake repository.\nWe 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<a href=\"https:\/\/www.visualstudio.com\/vs\/cplusplus-mdd\/\"> Visual C++ cross-platform page<\/a>.\n<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/sample.zip\">sample.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":311,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[232,140,252,233,253,13,36],"class_list":["post-7251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-android","tag-c","tag-cmake","tag-cross-platform","tag-mdd","tag-msbuild","tag-vc"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/311"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=7251"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7251\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=7251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=7251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=7251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}