Re: [AMBER-Developers] CMake in Amber

From: Jamie Smith <jsmith.crackofdawn.onmicrosoft.com>
Date: Mon, 5 Apr 2021 18:50:36 +0000

Yes, that page on the docs absolutely needs to be updated. It has gotten badly out of date, I'll work on it when I have time.

For what it's worth, CMake should autodetect and use external libraries like NetCDF without you having to do anything that verbose. Was it installed to a location that was not in your system directories (e.g. /usr)? If so, there's a much more straightforward way to do what you did: use CMAKE_PREFIX_PATH. Passing this option (e.g. -DCMAKE_PREFIX_PATH=<my/dir>) causes CMake to scan the include/ and lib/ directories of the given directory for libraries in addition to the regular system search path. It's equivalent to the Autoconf "--prefix" option if you've used that (except it doesn't change the install dir). What I like to do is install all my dependency libraries to a single prefix and then use that option so that it can find them.

Jamie

-----Original Message-----
From: Daniel Roe <daniel.r.roe.gmail.com>
Sent: Monday, April 5, 2021 11:41 AM
To: AMBER Developers Mailing List <amber-developers.ambermd.org>
Subject: Re: [AMBER-Developers] CMake in Amber

Hi All,

I heartily agree with Adrian - the documentation for cmake needs to be
*vastly* improved, and also centralized if at all possible. I ran into headaches with cmake documentation recently, details below.

On Mon, Apr 5, 2021 at 12:50 PM David A Case <david.case.rutgers.edu> wrote:
>
> We are using the wiki rather than a --help option for this purpose.
> Two pages are good starting points:
>
> https://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Quick-Start
>
> is a good overview. It has an FAQ with answers to questions such as
> "How can I build only one specific program?" or "I want to see what
> commands make is actually executing!"
>
> Also very helpful is this one:
>
> https://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Common-Options

These pages are good, but they are also incomplete. Recently, I was trying to figure out how to specify an external NetCDF library (with configure, accomplished using '--with-netcdf=$netcdf_home'). There is no specific option for cmake given, but the text at the bottom of the "Common Options" wiki page indicates (talking about the old configure flag -netcdfstatic):

"-netcdfstatic -- Just change NETCDF_LIBRARIES_C, NETCDF_LIBRARIES_F77, and NETCDF_LIBRARIES_F90 to point to static libraries."

This actually **does not work** for specifying an external NetCDF.
Cmake will complain about "Failed to find NetCDF interface for F77/F90". The manual has a few additional breadcrumbs (in 2.2.3): it mentions specifying the location of parallel NetCDF:

```
For example, if you saw this output:
-- Could NOT find PnetCDF_C (missing: PnetCDF_C_LIBRARY PnetCDF_C_INCLUDE_DIR) you could help CMake find the library with the following command:
cmake <path to source> -DPnetCDF_C_LIBRARY=<path to libpnetcdf.so> \
    -DPnetCDF_C_INCLUDE_DIR=<path to folder containing pnetcdf.h> ```

Using this as a hint, and diving into the cmake scripts for the actual variable names, I figured out I could specify an external NetCDF file via the CMAKE variables:

    -DNetCDF_LIBRARIES_C=$netcdf_home/lib/libnetcdf.a \
    -DNetCDF_INCLUDES=$netcdf_home/include \
    -DNetCDF_LIBRARIES_F77=$netcdf_home/lib/libnetcdff.a \
    -DNetCDF_LIBRARIES_F90=$netcdf_home/lib/libnetcdff.a \
    -DNetCDF_INCLUDES_F90=$netcdf_home/include \
    -DNetCDF_INCLUDES_F77=$netcdf_home/include

This took some dedicated sleuthing on my part, and I'm a long-time developer. I don't think users shouldn't have to jump through these hoops.

> p.p.s. Note that the current output of configure --help is 54 lines
> long, and that of configure --full-help (which is needed to get help
> for any but the most elementary subjects) is 154 lines.

Be that as it may, whenever I had a question on how to build amber, 99 times out of 100 I could do './configure --full-help | less` and have a one-stop shop of options and what they do, and then figure out what I needed to set. So I very much second Adrian's suggestion that there be a single location where all configurable cmake options are listed.
Whether that is a wiki page, a page in the manual, or some sort of onboard help program I don't particularly care. I just don't want to have to dive all over wiki pages, then the manual, then into the guts of cmake every time I want to change a default. Also, having a single source will make keeping that documentation up-to-date feasible.

-Dan

>
> This shows you how to ask for the most common changes, such as how to
> skip certain builds, change what libraries are used, change compiler flags, etc.
>
> If you look at the table of contents at the left of any of these
> pages, you will see several other CMake related pages.
>
> For everyone: please note that these are wiki pages! If there is
> something that is unclear, or is missing, please edit things to make them better.
>
> ...hope this helps....dac
>
> p.s. the links above are printed out at the very beginning of every
> CMake run. See also Section 2.2 of the Amber Reference Manual.
>
> p.p.s. Note that the current output of configure --help is 54 lines
> long, and that of configure --full-help (which is needed to get help
> for any but the most elementary subjects) is 154 lines. Also note
> that things like compiler info in the help output are 4-5 years out of
> date, and other pieces of information in the current help output are
> also wrong or misleading. So, in my view, using a wiki is a better
> way to make things easy to read, and to keep them up to date.
>
> Finally, the current configure help doesn't even try to answer
> Adrian's question about "building some things but not others". The
> answer for the legacy configure system is this "find the relevant Makefile, and edit it."
> For CMake, you add an option to your run_cmake script.
>
> _______________________________________________
> AMBER-Developers mailing list
> AMBER-Developers.ambermd.org
> http://lists.ambermd.org/mailman/listinfo/amber-developers

_______________________________________________
AMBER-Developers mailing list
AMBER-Developers.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber-developers
_______________________________________________
AMBER-Developers mailing list
AMBER-Developers.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber-developers
Received on Mon Apr 05 2021 - 12:00:04 PDT
Custom Search