views:

74

answers:

2

Where I work, we have a large codebase of C code that we build using Visual Studio 2005. It's separated into a variety of projects, including several static libraries. There are two solutions we primarily use, Full Debug (which turns off optimizations entirely), and Debug (we selectively optimize around 20% of files, while leaving the rest unoptimized for ease of debugging). Right now we enable the selective optimization of files by setting those properties on each file individually.

This system SORT of works, but is a giant pain because of the very large size of our project. I was looking into adding manual precompiled headers into our code base, but ran into the problem that the optimization setting of the precompiled header must match that of the C file. So, for our Debug build I need to make two precompiled headers, one optimized and one not. I would then set the project to use the nonoptimized one, and go through to each optimized file and manually change which precompiled header to use. I don't really want to do this.

What are some possible solutions for this? If there was some way to apply property sheets to individual files (as opposed to an entire configuration) that would make things a lot easier. Also, if I could somehow craft a macro statement for the precompiled header location ($(confname)/$(valueofparameteroptimized).pch or something) that would also solve it. Or, if those aren't possible, what solutions do people create adhoc for dealing with setting properties on subsets of files? Upgrading to 2008 is an option, if there's some solution there that would fix it (we were thinking about upgrading anyway).

A: 

Maybe I don't fully understand your problem, but you can just select all the source files you want to change the properties for and then set the properties just for these files. To make it easier you can put these files (only .c files no header files) in a separate folder.

Dani van der Meer
The problem is that we have probably a thousand or so source files, and a random subset of them are set to optimize. yeah, I probably do need to reorganize all of the optimized files into sub folders or something, that would definitely make it easier.
JZig
Well, i would still much prefer setting the files in a separate folder and apply settings from VS, than using #pragma directives, which IMO will lead to a maintenance nightmare. Build settings belong in the build tool (IDE), and source in the source file.
Dani van der Meer
A: 

You can avoid changing file settings by enabling and disabling optimisations using #pragma optimize in code:

eg.cpp:

// top of the file, after headers
#if defined(DEBUG) && defined(PARTIAL_OPTIMISATION)
#pragma optimize( "g", on )
#endif

void MyFunc()
{...}
redwyre
Hey, I didn't know that. Thanks for the advice, I may reorganize it that way
JZig