Difference between revisions of "Adding CMAKE To PHASTA"

From PHASTA Wiki
Jump to: navigation, search
(Created page with "If you'd like to use the new CMake based build system as described on the Compiling PHASTA With CMake page, but haven't merged your copy with [[https://redmine.scorec.rpi.edu...")
(No difference)

Revision as of 20:44, 1 July 2013

If you'd like to use the new CMake based build system as described on the Compiling PHASTA With CMake page, but haven't merged your copy with [SVN trunk] recently, you can follow these steps to add CMake support to your fork.


First, download the CMake build scripts:

 git clone https://github.com/matthb2/phasta-buildsystem.git
 

Next, we'll re-arrange your checkout of PHASTA to remove any redundant directories

 cd phasta
 mv phSolver tmp
 mv tmp/phSolver ./
 rmdir tmp
 #and so on with each directory that you have

Once that's done, you'll need to copy all the CMakeLists.txt files into their respective directories:

 #starting from your phasta source directory:
 for i in `find ../phasta-buildsystem -name 'CMakeLists.txt' | sed 's:\.\.\/::g' | sed 's:CMakeLists.txt$::g' | sed 's:^phasta\-buildsystem\/::g'`; do cp ../phasta-buildsystem/$i/CMakeLists.txt ./$i/

From this point, if you're on a fairly normal system, you can probably just build using CMake. That said, if you want your setup to be robust, it's a good idea to make some minor code changes in order to allow CMake to compute the necessary name mangling for the Fortran callable C functions.

CMake will generate a header file called "FCMangle.h" which supplies some macros. The one we're interested in is called

 FortranCInterface_GLOBAL_()

This macro takes two arguments, both of which are the name of the global symbol that should be Fortran callable. The first argument should be all lowercase, and the second should be all uppercase. The macro returns the Fortran name of the symbol.

For example, if I have a C function "foo()" that I want to call from Fortran, in my C header, I'd add these lines:

 #include <FCMangle.h>
 #define foo FortranCInterface_GLOBAL_(foo,FOO)


To take advantage of this in PHASTA, you'll find blocks of code that look like:

 #ifdef ibm
 #define something
 #endif
 #ifdef aix
 #define something
 #endif

Which should be replaced by calls to FortranCInterface_GLOBAL_. I've found that grepping for "ibm" catches most of these. If you fail to update any of these pieces of code, you'll see linker errors on certain platforms.


Note that to avoid another second class of bug, we've also been removing the trailing underscores from any functions that have them. For example "readheader_()" becomes "readheader()"


There is a (slightly outdated) video showing this process on an arbitrary fork of PHASTA available [here]

If you have any problems with this process, feel free to email [AT colorado.edu Ben] and please share any lessons learned on this page.