|Message: Re: XCode as an IDE including compile warnings and stepping through code||Not Logged In (login)|
Click on the Forum title, e.g. on the "Forums by Category" page, to read a sequence of postings to the Forum and its threads all in one page. If you are only interested in one thread or the thread following a specific posting, click the thread or the posting, which takes you to a smaller page, which contains only the part you are interested in and may be easier to navigate.
Messages are "chained" if there are only replies at the first level, i.e. 1/1.html, 1/1/1.html etc. In case of "chained" messages the message number is replaced by the icon and there is no indentation.
Inline: Display the subject line only or also the text of the posting(s); for the choice "All" the "Outline" choices are switched off.
|1||0||1||no text / full text of posting|
|2||1||All||text for level 1 only / text for All postings|
Outline: Choose the depth of the posting thread, successive toggle controls provide increasing detail.
|1||2||1||2 levels / 1 level (original posting)|
|2||3||2||3 levels / 2 levels|
|3||3||All||3 levels / all levels (all postings)|
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 (TrialG4Simulation.cc 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 env.sh 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 env.sh). 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:||Outline Depth:||Add message:|