Message: Re: XCode as an IDE including compile warnings and stepping through code Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: XCode as an IDE including compile warnings and stepping through code 

Forum: Installation and Configuration
Re: Note XCode as an IDE including compile warnings and stepping through code (Calvin Giles)
Date: 14 Dec, 2010
From: Calvin Giles <Calvin Giles>

Below are instructions as requested. I had little time free to do this so bugs are likely - please get in touch if you have any comments.

If these prove useful, a better home for them should be found.

****First: Install geant4 in both release and debug configurations One key advantage of an IDE is debugging, but we don't want to slow down our final release version with this information. The geant4 source code should therefore be built twice - once with debug flags, once without.

Copy geant4.x into /Applications/geant4/geant4.x/Release and /Applications/geant4/geant4.x/Debug. You will also need to copy the data files. I have plenty of space so have duplicated them for both, but it may be possible to use /Applications/geant4/geant4.x/Data as it contains no source code. Make sure to tell both Debug and Release installations where to find these.

Install using your preferred method - I followed the step-by-step guides. If using the configure script, when it gets to *GEANT4 LIBRARY BUILD OPTIONS* and asks "Do you want to build libraries with debugging information?" - when building in the Debug folder - Yes, when building in release - No.

If all goes well, you now have your geant4.x code compiled with debug headers ready to be read by the gdb debugger used by Xcode.

****Second: Create A Project in Xcode This assumes you are using Xcode 3.1.2 but it should work for anything close.

Open Xcode, select File->New Project... Select Other->External Build System Pick somewhere in your g4work directory to store your project. g4work/Xcode may be good. If you use Xcode for other developments, ~/Xcode/workspaces/geant4. Xcode will create a folder named with your project for you. For this example, I have created TrialG4Simulation, so I now have ~/Xcode/workspaces/geant4/TrialG4Simulation/ which contains TrialG4Simulation.xcodeproj and build/ .

****Third: Set up environmental variables inside Xcode Project. You should now be presented with the project window. On the left you should see Targets. Click the reveal triangle to show TrialG4Simulation. Double click on the TrialG4Simulation Target. This brings up the build settings for this target - a makefile. This is where build time environmental variables are set. Set the target directory to $G4WORKDIR. Add a Build Setting by clicking on the plus called G4WORKDIR. Make it equal to /Users/username/Xcode/workspaces/geant4/TrialG4Simulation/source where username is correct. In the upper left corner is a drop down: "Setting show <Debug> configuration". Change this to <Release>. Add the same G4WORK Build Setting.

Go to Finder, and find your project directory. Create source in your project folder. This is the root of your conventional simulation code. It should contain a GNUMakefile, a main application code file ( for example) as well as src and include folders.

Close XCode!! Right Click on TrialG4Simulation.xcodeproj and select Show Package Contents. Open project.pbxproj in TextEdit.

Search for "/* Begin PBXLegacyTarget section */". You should find a line buildWorkingDirectory = $G4WORKDIR;

Do another search for G4WORK and you should find it in two more places like this: G4WORK = /Users/calvin/Xcode/workspaces/geant4/TrialG4Simulation/source; These two locations should be the buildSettings section of XCBuildConfiguration. You can now add all the environment variables you desire for debug and release configurations. Run to see what they are on your system then copy the values over to the buildSettings. Important changes: G4WORKDIR = $PROJECT_DIR/source G4BIN = $BUILD_DIR/bin/$CONFIGURATION G4TMP = $BUILD_DIR/tmp/$CONFIGURATION G4INSTALL = $G4INSTALLATIONDIR/$G4CONFIGURATION G4INSTALLATIONDIR = /Applications/geant4/geant4.x for Release only G4CONFIGURATION = release

for Debug only G4CONFIGURATION = debug G4DEBUG = 1

The use of G4CONFIGURATION ensures you use the correctly compiled versions of the source code. Using CONFIGURATION for build directories allows you to create more build configurations in the future and not have to think about how it keeps the build products separate.

***Make a copy of project.pbxproj*** Make the required changes to the project.pbxproj file in order to set up all the build settings. Xcode is capable of resolving the env variables for you (so long as you don't create a loop) so don't worry about the order. When you are done, save the files, close them, and open up Xcode. You should not find the variables have appeared in the Build Settings for both debug and release.

Copy an example project into source (eg N01), complete with all .cc and .hh files, and the GNUMakefile. Select Debug from active configuration and click Build. You should see the Build Results window appear, and it should compile successfully.

****Forth: Add an Executable If all has gone well, you should now have an executable at build/bin/Debug/Darwin-g++/N01. You can run this from a command line as before (don't forget to configure your environment with In your project in Xcode, select Project->New Custom Executable... Name this (Debug is a good idea). Click choose and navigate to its location. Click Next. It should now be listed under Executables in your project. You can change your active configuration from Debug to Release and repeat the process of build, new custom executable to create a Release Executable.

To configure the environment for run-time, right-click on the executable and Get Info. On the Arguments tab, add a cmd line argument "-m macroFile" to the arguments to be passed. On the Variables to be set, add two environment variables. Clost the Info window, and go back to TrialG4Simulator.xcodeproj/ open user.pbxuser (where user is your username). Search for Darwin-g++ you should find your executables. Above this you should find the environment variables as "environmentEntries" with a different format to the build settings. ***Environment settings set at build time do not resolve and cannot be dependent on each other!!*** You must therefore set each one literally. You can probably get away with a reduced set for runtime purposes. Arguments are under "argumentStrings" and should be easy to figure out.

Once you have set these up for each of your executables, you should be able to click Build and Go. This will build the code with make, and run it inside the xcode terminal.

***Fifth: Testing... Make a compile time error in your code and compile. The build will fail with the make output. Click on the error and it will take you to the line of your code that failed.

You can set break points by double clicking on the left border of the editor.

Comments welcome, code completion instructions to follow.



Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Comments on instructions   (Calvin Giles - 14 Dec, 2010)
2 Warning: Correction - don't use a source folder and watch out for ++   (Calvin Giles - 15 Dec, 2010)
 Add Message Add Message
to: "Re: XCode as an IDE including compile warnings and stepping through code"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]