Netlib F2C
This project provides a CMake framework, that automatically downloads and builds
the Fortran-to-C converter f2c
from Netlib (https://www.netlib.org/f2c/) and
the accompanying library libf2c
.
Prerequisites
What you need:
- Git (optional) for getting the code and contributing to the project
- CMake and Ninja for building the project
- C compiler
- gcc for linux/mac (https://gcc.gnu.org/)
- cygwin + gcc for windows (https://www.cygwin.com/)
- LoadStaticSharedTargets (https://gitlab.aei.uni-hannover.de/cmake/loadstaticsharedtargets)
Linux (Ubuntu)
Use your distribution's package manager to install the packages cmake
, ninja
and gcc
.
$ sudo apt-get install cmake ninja gcc
Mac OS X
Homebrew
$ brew install cmake ninja gcc
MacPorts
$ sudo port install cmake ninja gcc
Windows
Install Cygwin and use the Cygwin package manager to install the packages
cmake
, ninja
and gcc-core
.
How to compile
-
(Optional) First, build the LoadStaticSharedTargets project and install it either system-wide or in a central location, e. g. somewhere in your home directory. Please refer to the project README for build instructions. If you skip this step, LoadStaticSharedTargets should automatically be downloaded and included in your build. But you might end up compiling some parts multiple times unnecessarily.
-
Clone the git repository or download the source code archive and unpack it to an arbitrary directory (e.g.
netlib-f2c
). -
Go to this directory and type
cmake --list-presets
. A list of available build configurations will be shown to you. -
For building with
ninja
, typecmake --preset ninja-shared-release
, if you installed LoadStaticSharedTargets system-wide or not at all. Otherwise, type$ cmake -DCMAKE_PREFIX_PATH="/path/to/LoadStaticSharedTargets/install/prefix" --preset ninja-shared-release
Replace the path to the LoadStaticSharedTargets install prefix with the actual path on your system! The license of the NetlibF2C source code will be shown to you. If you accept this license, add the required variable to the previous command:
$ cmake -DNetlibF2C_LICENSE_ACCEPTED=YES --preset ninja-shared-release
or
$ cmake -DCMAKE_PREFIX_PATH="/path/to/LoadStaticSharedTargets/install/prefix" -DNetlibF2C_LICENSE_ACCEPTED=YES --preset ninja-shared-release
This will populate the
build/shared
directory with a CMake build tree. -
Now, you can build with
cmake --build ./build/shared
. You should see some informative terminal output. -
Finally, install the built artifacts to the
bin
folder withcmake --install ./build/shared --prefix ./bin
. You can also specify a different install prefix, e. g. if you want to install system-wide:cmake --install ./build/shared --prefix /usr/local
(might requiresudo
). You can also install either only the executable or only the library withcmake --install ./build/shared --prefix <any> --component executable
orcmake --install ./build/shared --prefix <any> --component library
. -
Repeat steps 4. - 6. with
cmake --preset ninja-static-release
and the build directory./build/static
.
Now, the f2c
code is compiled and you can use it in other projects. The
installed f2c
package is discoverable by CMake as NetlibF2C. In the
CMakeLists.txt
of the other project, call:
find_package(NetlibF2C CONFIG REQUIRED)
This makes two CMake targets available to you, the Netlib::f2c
executable
target and the Netlib::libf2c
library target (static or shared depends on the
value of BUILD_SHARED_LIBS
in the other project).
Then, to help CMake discover the NetlibF2C package, call CMake for the other project like this:
$ cmake -B ./build -DCMAKE_PREFIX_PATH="/path/to/NetlibF2C/install/prefix"
Replace the path to the NetlibF2C install prefix with the actual path on your
system! If NetlibF2C is installed in a proper system-wide location, the
CMAKE_PREFIX_PATH
shouldn't be necessary.
For more information read the f2c
executable's man page.
References
S. I. Feldman, David M. Gay, Mark W. Maimone, and N. L. Schryer. 1990. A Fortran-to-C Converter. AT&T Bell Laboratories Murray Hill, NJ 07974 (May 1990). Computing Science Technical Report No. 149. https://www.netlib.org/f2c/f2c.pdf