<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compiling variations on a common code base: best practices? in MCUXpresso IDE</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786321#M2647</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Robert,&lt;/P&gt;&lt;P&gt;I recommend build targets as well (see &lt;A class="link-titled" href="https://mcuoneclipse.com/2016/05/19/build-configurations-in-eclipse/" title="https://mcuoneclipse.com/2016/05/19/build-configurations-in-eclipse/"&gt;Build Configurations in Eclipse | MCU on Eclipse&lt;/A&gt; ), especially if the set of sources files remains the same for all the different variants. You can control each build target compiler settings and output file name(s), and you would add your define to the compiler settings (-D option).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Jun 2018 18:29:12 GMT</pubDate>
    <dc:creator>BlackNight</dc:creator>
    <dc:date>2018-06-14T18:29:12Z</dc:date>
    <item>
      <title>Compiling variations on a common code base: best practices?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786319#M2645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a large-ish body of code that supports seven different analog sensor boards (and more in the future...).&amp;nbsp; About 90% of the code is shared among all the variants.&amp;nbsp; I've already conditionalized the code to support the different sensor boards with constructs along these lines:&lt;/P&gt;&lt;PRE&gt;void sensor_init() {
#ifdef IS_SENSOR_A
&amp;nbsp;&amp;nbsp;&amp;nbsp; sensor_a_init()
#elif IS_SENSOR_B
&amp;nbsp;&amp;nbsp;&amp;nbsp; sensor_b_init()
#else
&amp;nbsp;&amp;nbsp;&amp;nbsp; #error Unknown sensor!
#endif
}&lt;/PRE&gt;&lt;P&gt;When I build the project, MCUXpresso generates&amp;nbsp;&lt;STRONG style="font-family: terminal, monaco, monospace;"&gt;my_project.axf&lt;/STRONG&gt;&amp;nbsp;file compiled for one of the seven variants.&amp;nbsp; What I usually do then is rename &lt;STRONG style="font-family: terminal, monaco, monospace;"&gt;my_project.axf&lt;/STRONG&gt;&amp;nbsp;to &lt;STRONG style="font-family: terminal, monaco, monospace;"&gt;sensor_a.axf&lt;/STRONG&gt; or &lt;STRONG style="font-family: terminal, monaco, monospace;"&gt;sensor_b.axf&lt;/STRONG&gt; depending on the conditionals in effect when I built it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course, this approach is fraught with potential for errors --&amp;nbsp;it's easy to forget to rename the .axf file, and it's not obvious which variant&amp;nbsp; &lt;STRONG style="font-family: terminal, monaco, monospace;"&gt;my_project.axf&lt;/STRONG&gt;&amp;nbsp;was compiled for after the fact.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to do this automatically, or achieve the same effect?&amp;nbsp; (E.g. should I create seven different projects that share a common code base?&amp;nbsp; If so, how?)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 14:57:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786319#M2645</guid>
      <dc:creator>robertpoor</dc:creator>
      <dc:date>2018-06-14T14:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Compiling variations on a common code base: best practices?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786320#M2646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The simplest thing would probably be to create a number different build configurations (i.e. beyond&amp;nbsp;the default Debug and Release build configs). To do this, right click on the project in the Project Explorer view, and select the menu:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Build Configurations -&amp;gt; Manage&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another approach might be to have a project for each build variant that you want, which then use "linked resources" to link to another "master project" that contains your sensor sources.&amp;nbsp;Linked resources allow you to link a folder in one project into a folder in another. This is similar to a linux symbolic link. You can have a many linked folders as you need - there is no limit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By using a master project plus "secondary"&amp;nbsp;projects with&amp;nbsp;linked folder, you get a single copy of your sources (editable from both projects) but with different project (and MCU) settings. It is fully compatible with source code control systems, such as Git or SVN. Details on linked resources can be found in the Help (Help-&amp;gt;Help Contents and search for Linked Resources).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With regards to the master project, as this is really just a container of files rather than something you actually want to build, you might want to create it just using the&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;File -&amp;gt; New -&amp;gt; &amp;nbsp;Project -&amp;gt; General -&amp;gt; Project&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple way to create your secondary&amp;nbsp;projects with a linked folder is as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Use the New Project Wizard to create a project with the appropriate settings&lt;/LI&gt;&lt;LI&gt;delete the src folder&lt;/LI&gt;&lt;LI&gt;Right-click on the project and File-&amp;gt;New-&amp;gt;Folder&lt;/LI&gt;&lt;LI&gt;Enter src into the Folder name&lt;/LI&gt;&lt;LI&gt;Press the Advanced&amp;gt;&amp;gt; button&lt;/LI&gt;&lt;LI&gt;Click on "Link to alternate location (Linked folder)"&lt;/LI&gt;&lt;LI&gt;Press "Variables"&lt;/LI&gt;&lt;LI&gt;In the new Dialog, select the WORKSPACE entry&lt;/LI&gt;&lt;LI&gt;press the Extend button&lt;/LI&gt;&lt;LI&gt;a Browser is shown - browse to the src folder in your 'master' project&lt;/LI&gt;&lt;LI&gt;Press OK&lt;/LI&gt;&lt;LI&gt;Press Finish&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You new project will now have a src folder that is linked to the src folder in your master project. You can make changes to your secondary project(s) to provide different build options (e.g. defines).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another possibility might be to consider using a library project, with build configs for each of your sensor options. Then have a project for each sensor type - which contains any project specific code, but also links to the appropriate build config of the central library project. I suspect that this is probably the most complex option though.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;MCUXpresso IDE Support&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 15:51:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786320#M2646</guid>
      <dc:creator>lpcxpresso_supp</dc:creator>
      <dc:date>2018-06-14T15:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compiling variations on a common code base: best practices?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786321#M2647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Robert,&lt;/P&gt;&lt;P&gt;I recommend build targets as well (see &lt;A class="link-titled" href="https://mcuoneclipse.com/2016/05/19/build-configurations-in-eclipse/" title="https://mcuoneclipse.com/2016/05/19/build-configurations-in-eclipse/"&gt;Build Configurations in Eclipse | MCU on Eclipse&lt;/A&gt; ), especially if the set of sources files remains the same for all the different variants. You can control each build target compiler settings and output file name(s), and you would add your define to the compiler settings (-D option).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 18:29:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786321#M2647</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2018-06-14T18:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Compiling variations on a common code base: best practices?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786322#M2648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using build configurations with -D options solves 95% of my needs nicely!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the remaining 5%: is there a way to select one of two memory layouts / linker scripts?&amp;nbsp; In my case, it would be useful to&amp;nbsp;choose between a "standalone" image (starting at 0x0) and a "bootloaded" image (starting at 0x4000 with a Boot Control Area).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since MCU / Memory Configuration / Linker Scripts don't appear to be under control of Build Configurations, perhaps this would be a case for linked projects -- a master project without relocation and a secondary project with relocation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does that sound sensible?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jun 2018 08:09:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786322#M2648</guid>
      <dc:creator>robertpoor</dc:creator>
      <dc:date>2018-06-16T08:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Compiling variations on a common code base: best practices?</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786323#M2649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For anyone who has arrived here seeking wisdom:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As recommended by&amp;nbsp;MCUXpresso IDE Support and by &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/BlackNight"&gt;BlackNight&lt;/A&gt;, I started out using build configurations to create the different versions of the code, one version per sensor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It worked well, but as scope of the project grew -- and the client wanted not only different sensors but multiple variations on individual sensors -- my code became increasingly cluttered with #ifdef and #ifndef statements and unexpected inter-dependencies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I made the jump: I converted the common code base&amp;nbsp;into a library (see Erich's&amp;nbsp;&lt;A href="https://mcuoneclipse.com/2015/01/06/creating-a-library-with-kinetis-design-studio/"&gt;Creating a Library with Kinetis Design Studio&lt;/A&gt;).&amp;nbsp; A&amp;nbsp;suite of projects -- one project per sensor configuration -- link to the common library base.&amp;nbsp; I found another of Erich's blogs,&amp;nbsp;&lt;A href="https://mcuoneclipse.com/2013/02/12/creating-and-using-libraries-with-arm-gcc-and-eclipse/"&gt;Creating and using Libraries with ARM gcc and Eclipse&lt;/A&gt;, to be helpful in setting that up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code base is now quite clean: the preprocessor conditionals are gone and the individual projects are very compact.&amp;nbsp; Adding a new sensor (or a variation on a sensor) is easy.&amp;nbsp; And&amp;nbsp;if I find myself repeating code across multiple projects, I just add a new function in my sensor_utils.c library file so it can be shared.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One unexpected bonus of this approach:&amp;nbsp;the new structure makes it easy to create a virtual "debugging sensor" that doesn't read a physical sensor, but rather allows me to test and validate the functions in the library.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Erich might say, happy code sharing!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Sep 2018 01:02:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/Compiling-variations-on-a-common-code-base-best-practices/m-p/786323#M2649</guid>
      <dc:creator>robertpoor</dc:creator>
      <dc:date>2018-09-16T01:02:13Z</dc:date>
    </item>
  </channel>
</rss>

