<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/85748/compiler-flags-in-vscode-with-nrf-connecy-extension</link><description>I want to add compiler flags to my build configuration i.e _DEBUG, etc 
 My understanding is that a build is done by build task 
 nRF Connect extension allows to create a tasks.json from a default nRF Connect build task 
 In Terminal-&amp;gt;Configure tasks</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Fri, 08 Apr 2022 06:08:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/85748/compiler-flags-in-vscode-with-nrf-connecy-extension" /><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/362481?ContentTypeID=1</link><pubDate>Fri, 08 Apr 2022 06:08:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1bf36ddd-97e7-4bd3-a340-6d5a7b67397a</guid><dc:creator>user107732</dc:creator><description>&lt;p&gt;Hi Andy,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Adding&amp;nbsp;&lt;/span&gt;&lt;code&gt;-DCMAKE_C_FLAGS=-DAPP_DBG_LEVEL=4&lt;/code&gt; in the extra flags field is one way to do this.&amp;nbsp;But this is not a shareable way.&lt;/p&gt;
&lt;p&gt;Could you try doing it the following way.?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Add a flag to control compilation flags on the command line, and set additional flags in an if/else in the cmakelists.txt file. This is how you can implement this:&lt;/p&gt;
&lt;p&gt;In cmake, set up a flag that controls the behavior - for instance &amp;quot;APP_DBG_LEVEL&amp;quot;. Then, in the cmake code, you can check this flag, and activate other settings or behavior depending on the value. Take a look at this Stack overflow answer, for example: &lt;a title="https://stackoverflow.com/a/48984477/2495121" href="https://stackoverflow.com/a/48984477/2495121" rel="noopener noreferrer" target="_blank"&gt;https://stackoverflow.com/a/48984477/2495121&lt;/a&gt;. In the answer, a flag called &lt;code&gt;USE_MY_LIB &lt;/code&gt;is added to control compilation flags and other things.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Where the snippet in that answer says &amp;quot;#add some compilation flags&amp;quot;, you could do&lt;/p&gt;
&lt;p&gt;&lt;code&gt;target_compile_definitions(app PRIVATE ABC=5)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;which creates a define called &amp;quot;ABC&amp;quot; that can be referenced in the source code.&lt;/p&gt;
&lt;p&gt;This way, there is no need to specify -DCMAKE_C_FLAGS=&amp;quot;-DABC=5&amp;quot; on the command line to get the expected behavior, but could enable different configuration types through more understandable command line flags, if required. Hope this helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Swathy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/362351?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 12:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a1ed7b4-98db-4832-9c51-1dcf09d77d77</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;This has not been resolved. Any other ideas? It seems like a fundamental feature that is trivial to configure in all other IDE&amp;#39;s I&amp;#39;ve worked with&lt;/p&gt;
&lt;p&gt;What am I missing??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/360013?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 13:02:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8888a3f2-8437-4deb-8679-ae59c037e8ef</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;Any other ideas? Seems like such a&amp;nbsp; basic thing in any IDE to configure debug and release build configurations with some compiler flags present on one but not the other. How can this be accomplished in a vscode project??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358881?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2022 13:32:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0455b19-901c-46db-89e9-df933eb11b4d</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;Could you clarify: where does the &amp;quot;target_compile_definitions&amp;quot; directive needs to be added? In CMakeLists.txt?&lt;br /&gt;If that&amp;#39;s the case it does not solve my problem. My ultimate goal is to have 2 configurations, one for debug and one for release. In the debug configuration the APP_DBG_LEVEL is 4 and in the release one it&amp;#39;s 0 . And those configurations need to be shareable. How do I accomplish that?&lt;br /&gt;Thank you&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358870?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2022 13:01:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad68c278-cf7d-42f4-93a6-018f9daf6acd</guid><dc:creator>user107732</dc:creator><description>&lt;p&gt;Hi Andy,&lt;/p&gt;
&lt;p&gt;Sorry for the late response..&lt;/p&gt;
&lt;p&gt;The field &lt;em&gt;Extra flags for CMAKE&lt;/em&gt; adds variables that CMake understands and those are not saved, so they only apply to the build just being created.&lt;/p&gt;
&lt;p&gt;Adding&amp;nbsp;-DCMAKE_C_FLAGS=-DAPP_DBG_LEVEL=4 in the extra flags field is one way to do this.. To make it shareable, try adding it in the cmake file by using the following command:&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;target_compile_definitions(app PRIVATE -DAPP_DBG_LEVEL=4)&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Best Regards,&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Swathy&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358740?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 18:17:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69717f51-5583-43df-bb08-0e2a8793aec7</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;Any other ideas? I&amp;#39;m stuck&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358283?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2022 16:23:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2a45749-5be6-4a86-a19b-8b0599f61d1d</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;Did a bit more experimentation. The only way I could make this work was to add the following to CMakeLists.txt&lt;br /&gt;set(CMAKE_C_FLAGS &amp;quot;${CMAKE_C_FLAGS} -DAPP_DBG_LEVEL=4&amp;quot;)&lt;br /&gt;But that does achieve my goal of setting that flag to a certain value based on a condition ( debug vs release build )&lt;br /&gt;When I set that flag in the build configuration window &amp;quot;Extra flags for CMAKE&amp;quot; I see it appear in the output but the flag is not processed by the preprocessor so it remains undefined in the code&lt;br /&gt;#ifndef APP_DBG_LEVEL&lt;br /&gt;#error App debug level undefined&lt;br /&gt;#endif&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358061?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 17:20:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40770fbf-15fd-4b9d-ae1e-f2eb6b7332a5</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;Another question. The build configuration generated by the nRF extension has hard coded paths that are specific to my PC&lt;/p&gt;
&lt;p&gt;I am not the only developer working on this project. Which means that they will have to recreate the build configuration on their machine? And add &amp;lt;all&amp;gt; extra compile flags? Is there a way to add compile flags&amp;nbsp;in such a way that it can be shared across the team?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358060?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 17:17:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4e92bb9-46c6-4b36-8357-176e3db235b7</guid><dc:creator>user77539</dc:creator><description>&lt;p&gt;According to that article the extra cmake flags can be added in &amp;quot;additional cmake flags&amp;quot; field. I did that and when I hover a mouse over the build directory I see the flag that I added. But when I reference it in the code I get an error&lt;br /&gt;In build config-&amp;gt;additional cmake flags:-DDBG_LEVEL=4&lt;br /&gt;In the code&amp;nbsp;&lt;br /&gt;printk(&amp;quot;Debug level:%d&amp;quot;,DBG_LEVEL);&lt;br /&gt;Error:&amp;nbsp;&lt;span&gt;DBG_LEVEL is undefined&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compiler flags in vscode with nRF connecy extension</title><link>https://test-devzone.nordicsemi.com/thread/358046?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2022 16:17:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e209b1dd-8dbf-4042-b5f9-e79e27ab5d44</guid><dc:creator>user107732</dc:creator><description>&lt;p&gt;Hi Andy,&lt;/p&gt;
&lt;p&gt;Kindly take a look at the documentation for nRF Desktop application that includes several build types which also include Debug and Release option :&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/nrf_desktop/README.html#id22"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/nrf_desktop/README.html#id22&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Best Regards,&lt;/p&gt;
&lt;p&gt;Swathy&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>