{"id":6746,"date":"2020-10-05T12:28:56","date_gmt":"2020-10-05T19:28:56","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=6746"},"modified":"2020-10-05T12:28:56","modified_gmt":"2020-10-05T19:28:56","slug":"importing-external-embedded-cmake-projects-in-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/cmake\/import\/","title":{"rendered":"Importing External Embedded CMake Projects in VisualGDB"},"content":{"rendered":"<p>This tutorial shows how use VisualGDB to build and debug existing Embedded CMake projects that are not based on the VisualGDB&#8217;s embedded framework (i.e. do not utilize <strong>find_bsp()<\/strong> and other similar statements). We will show how to import a <a href=\"https:\/\/github.com\/sysprogs\/tutorials\/tree\/master\/visualgdb\/ARM\/CMake\/ImportedProjectDemo\/ExistingProject\">very basic STM32 project<\/a> into VisualGDB, and will explain the differences between the imported project and a CMake-based project created from scratch.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/01-emb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6723\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/01-emb.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>Enter the name and location of the VisualGDB project you would like to create. The VisualGDB project will store high-level settings (such as IntelliSense or debugging settings) and can be placed in the same directory as the existing CMake project, or in any other location. In this tutorial we will place it in the parent directory (<strong>C:\\tutorials\\visualgdb\\ARM\\CMake\\ImportedProjectDemo<\/strong> where the existing CMake project is checked out to <strong>C:\\tutorials\\visualgdb\\ARM\\CMake\\ImportedProjectDemo\\ExistingProject<\/strong>):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/02-name-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6747\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/02-name-1.png\" alt=\"\" width=\"1024\" height=\"680\" \/><\/a><\/li>\n<li>On the first page of VisualGDB wizard, select &#8220;<strong>Import a project built with command-line tools -&gt; Import a CMake project with Advanced CMake Project Subsystem<\/strong>&#8220;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-cmake-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6754\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-cmake-2.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the next page select the toolchain and the device you would like to target. that it will be used to configure IntelliSense\/debugging, but will not affect the build process, unless the existing <strong>CMakeLists.txt<\/strong> files explicitly read the toolchain location from the <strong>TOOLCHAIN_ROOT<\/strong> variable: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6749\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/03-device.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a><\/li>\n<li>On the next page of the wizard enter the location of the project you are importing: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/04-import-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6755\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/04-import-1.png\" alt=\"\" width=\"886\" height=\"693\" \/><\/a>Note that normally VisualGDB will try to generate a <strong>toolchain.cmake<\/strong> file defining the toolchain selected in the wizard and will pass it to CMake via the <strong>CMAKE_TOOLCHAIN_FILE<\/strong> variable. If you want to override this behavior, enable the &#8220;<strong>use existing CMAKE_TOOLCHAIN_FILE<\/strong>&#8221; checkbox and point to your existing <strong>toolchain.cmake<\/strong> file (or leave the path empty if your toolchain information is hardcoded in CMakeLists.txt).<\/li>\n<li>Click &#8220;Finish&#8221; to complete the project importing. You will now be able to build it as a regular Embedded project:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/06-built.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6752\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/06-built.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>Set a breakpoint in main() and press F5 to begin debugging. VisualGDB will program the FLASH memory and launch the application. The breakpoint in main() will trigger, letting you examine the program state: <a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/07-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6753\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/07-debug.png\" alt=\"\" width=\"1193\" height=\"739\" \/><\/a><\/li>\n<li>Unlike the <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/cmake\/\">Advanced Embedded CMake projects managed by VisualGDB<\/a>, imported CMake projects will not use the Sysprogs embedded framework, so changing the device via VisualGDB Project Properties, or adding\/removing frameworks will not affect <strong>CMakeLists.txt<\/strong> files. Instead, you would need to edit low-level target settings (e.g. preprocessor definitions or CFLAGS) via target properties, or by editing CMakeLists.txt directly:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/08-props.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6756\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2020\/10\/08-props.png\" alt=\"\" width=\"1193\" height=\"768\" \/><\/a>The rest of the project editing functionality (e.g. adding\/removing targets or source files) will work as expected.<\/li>\n<\/ol>\n<p>If you are looking for a better integration between CMake and embedded tools, please consider creating an embedded project using the Sysprogs Embedded Framework as shown in <a href=\"https:\/\/visualgdb.com\/tutorials\/arm\/cmake\/\">this tutorial<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how use VisualGDB to build and debug existing Embedded CMake projects that are not based on the<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[222],"tags":[53,77,223,61],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6746"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=6746"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6746\/revisions"}],"predecessor-version":[{"id":6757,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/6746\/revisions\/6757"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=6746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=6746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=6746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}