GEOS-ESM / ESMA_cmake

Custom CMake macros for the GEOS Earth System Model
Apache License 2.0
4 stars 9 forks source link

BASELIBS directory structure in cmake #186

Closed amdasilva closed 1 year ago

amdasilva commented 3 years ago

Currently a typical cmake command for the GEOS systems reads:

... cd build cmake .. -DBASEDIR=$BASEDIR/Linux -DCMAKE_Fortran_COMPILER=ifort \ -DCMAKE_INSTALL_PREFIX=../install

My issue is with the option

-DBASEDIR=$BASEDIR/Linux

For many years BASEDIR have a very specific structure, and Linux (really, uname -s) has been part of it. To have the environment variable BASEDIR and the cmake variable BASEDIR mean something different is plain confusing and a potential source of errors when exercising the "-e" option in GNU make. Don't do it.

amdasilva commented 3 years ago

Better yet, if $BASEDIR is defined an environment variable, there is no need to specify -DBASEDIR=$BASEDIR. More generally, in the spirit of auto tools, if enviroment variables are set for

BASEDIR CMAKE_Fortran_COMPILER CMAKE_INSTALL_PREFIX

why do we need to specify this with the -D option? Can't your cmake script check for env variables and set the cmake variables automatically? In any event, g5modules should set these variables and "mepo --cmake" (see the issue that I filed under mepo for the --cmake option) should take care of it behind the scenes.

mathomp4 commented 3 years ago

@amdasilva The only thing that is truly required by our CMake (for GEOS users) is the -DBASEDIR option. I'll try and take a look at having it work via an environment variable but I'll have to be careful as I want to make sure it doesn't break our non-Baselibs users of MAPL and GOCART.

Now, as for CMAKE_Fortran_COMPILER, that technically is not required. CMake will, by default, use FC from the environment for the CMAKE_Fortran_COMPILER. But, that assumes FC is defined. It turns out, the Intel modulefiles used at NAS (which are the modulesfiles supplied by Intel) do not define FC. I have had all sorts of words with NAS (and Intel) about this, but no luck. The fun comes in that at NAS I build GCC modules and they do define an FC. (I'm having similar arguments with some AWS modulefiles as well that others at NCCS made.)

Thus, for safety's sake, I've put in the instructions that one should specify the CMAKE_Fortran_COMPILER though it's not needed really anywhere but at NAS.

And, finally, you technically do not need a CMAKE_INSTALL_PREFIX. The (current) default is, if no CMAKE_INSTALL_PREFIX is specified, to put the install directory inside the build directory as it's the one place @tclune and I figured is guaranteed you have the rights to write to (you can build from a source tree in my directories in a build tree in your directories). (NOTE: The CMake default is /usr/local but @tclune and I realized no one usually has rights to write there, so we "hijack" and set our own default.)

So on discover this:

cmake .. -DBASEDIR=$BASEDIR/Linux

is all that's needed assuming g5_modules is source, the appropriate environment variables are set, etc.

And I can look at removing the BASEDIR bits as well, but as I said, @tclune and I will have to be careful as we don't want to require BASEDIR for things like MAPL or GOCART if not needed.