Atmel Studio how to exclude files from target

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, I'm using Atmel Studio and want to exclude specific files from building for a particular target. For example, foo.c compiles for target Debug and not for Release

 

This post answers the question but I think it's outdated since I cant't find the option in Atmel Studio 7 -  https://www.avrfreaks.net/forum/conditional-compiling-0

Selecting Properties on the source file shows the Build Action option which allows to disable building a file but it's carried out through the entire project. 

 

Is there a way to exclude building from specific targets only?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can set File Properties but AS7.0 gets upset when you have multiple Projects in a Solution that share some common Files.

 

If you want to distinguish between Debug and Release,   just enclose the source lines in an #if defined(DEBUG) block

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pavel5 wrote:
This post answers the question but I think it's outdated since I cant't find the option in Atmel Studio 7 -  https://www.avrfreaks.net/forum/conditional-compiling-0

Conditional compilation is a feature of MSBuild.

Ideally, the MSBuild log can be read then one can tweak MSBuild's invocation.

GNU Make is available; don't know what's invoked due to 'Use Extnernal External Makefile'.

 

https://www.avrfreaks.net/search/site/conditional%20compilation%20MSBuild?solrsort=ds_created%20desc&filter_by=9631&so=0

Build and Run Options | Atmel Studio 7

[bottom]

MSBuild project build output verbosity

Sets the verbosity level for the build output. For more information, see the /verbosity switch in MSBuild Command Line Reference.

MSBuild project build log file verbosity

Sets the verbosity level for the build log file. For more information, see the /verbosity switch in MSBuild Command Line Reference.

Build Options | Atmel Studio 7

Build Options | Atmel Studio 7

 

edit : 2 strikethrus plus MSBuild - Visual Studio 2015 | Microsoft Docs

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Oct 24, 2019 - 03:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you say "Build Action" is just a global on/off switch - it's not conditional on the build configuration.

 

I'd just go with what David suggests. Release builds in AS7 (and Visual Studio) always define NDEBUG. While I got Atmel to add the opposite "DEBUG" as a default macro in Debug builds I'd probably still go with NDEBUG and just disable/enable the entire file contents accordingly.

 

Another approach would be to add a "stub" that always builds that just does:

#ifdef NDEBUG
    // do nowt
#else
    #include "actual_file_to_be_built_for_debug.c"
#endif

(or the other way around) but that's just moving the #if(n)def test out of the actual .c file itself.