JParks JParks - 1 month ago 13
C++ Question

Changing the build output based on x86/x64 and debug/release Code::Blocks/Xcode

A little background information I think will help here. I am currently in a project for my school where we are building cross-platform libraries for use by future students. It has been mandated that we use the most popular IDE/Compiler per platform we are targeting. This means we are using Visual Studio 2015 with Visual C++ compiler for Windows, Code::Blocks with gcc for Linux (Ubuntu), and XCode with Clang for Mac.

We are currently in the process of developing a test sweet for our libraries, but have ran into something of a wall. The test sweet will need to know where to find the libraries for all configurations (x86 debug, x86 release, x64 debug, x64 release).

Visual Studio makes this easy because I can choose output directories for all these different builds.

Code::Blocks, on the other hand, Gives me only Release and Debug build options for output directories.

XCode is a whole other issue. It just gives me one option of where to put output. It doesn't care if it is debug/release or x86/x64. It just says name a folder and I'll put everything in there.

Is there a way to expand these options in Code::Blocks and XCode? I have looked into post build scripts to move these libraries for me, but can't figure out how to tell in the script if the libraries build configuration. I've been instructed that the libraries have to maintain the same name so renaming them per build configuration isn't an option.

Answer

I can't help with XCode, but I know that in codeblocks, you can add as many build configurations as you want. They're called build targets but they're not exactly the same as targets in gcc or visual studio make files.

To add additional targets, from the menu select "Project->Properties..." and then select the "Build targets" tab. You can then add 2 new targets to the project for the 32 or 64 bit builds. You may want to also rename the existing targets to reflect their build configuration.

At the very bottom of the build targets tab, there is a set of check boxes called "Build target files". At least on the version of codeblocks I use, when you add a new target, all of the check boxes are empty. If that's the case for you, you'll need to check check the files needed for that build configuration.

The final step is to set the compiler options, linker options, include folders, and lib folders for the new build configurations. Click the build options button, and add whatever additional compiler and the settings and folders that are appropriate for that build configuration.

There is one thing to pay attention to here. Codeblocks lets you set compiler and linker options both at the project and target level. By default, any settings made at the project level are applied for all targets.

For example, for a simple program, the -Wall option might be set at the project level, -g might be set for the debug configuration, and -O2 might be set for the release configuration. The net result is that when you try to build the debug target, the options used for the compiler are "-Wall -g" and for the release target they are "-Wall -O2". Similar remarks apply for the linker options and folders.

In your project, if there are any existing options set at the project level that apply only to the 32 or 64 bit targets, you'll need move those settings from the project level to the individual targets.