macOS package managers allow easy download, build and install of developer programs and libraries.
Homebrew
is by far the most popular macOS package manager.
Homebrew has a large number of packages and the ability to create unofficial “taps” to easily distribute software.
Homebrew taps allow distributing binaries via Homebrew before going to include in the main homebrew package repo, which takes time and justification.
Homebrew distributes per-OS compiled binaries, so package install time is almost instant.
It is possible to also download source and build locally with Homebrew if desired.
MacPorts
generally distributes source code that is compiled on install, although it can also use precompiled binaries.
Macports installs packages under a
prefix.
Homebrew is much more popular than MacPorts or
Fink.
Anaconda Python puts itself first on PATH when activated.
This can become a problem for libraries like HDF5, where “conda install h5py” puts
compiler script h5cc
on environment variable PATH before the intended script path.
For systems where Homebrew is used to provide packages to find from CMake, tell CMake to prefer a package location with
CMAKE_PREFIX_PATH.
This can be done a few different ways:
Setting CMAKE_PREFIX_PATH in the environment before running cmake:
exportCMAKE_PREFIX_PATH=$HOMEBREW_PREFIX
Setting CMAKE_PREFIX_PATH as a command line argument to cmake:
CMake Git operations such as shallow clone can cause unexpected failures due to too small INACTIVITY_TIMEOUT in ExternalProject or FetchContent.
Be sure to set INACTIVITY_TIMEOUT to a large enough value.
15 seconds is too short a timeout for Git shallow clone, for example.
Consider 60 seconds or larger INACTIVITY_TIMEOUT.
lowSpeedLimit might be set to 1000 (bits/second) or as appropriate for the network.
If lowSpeedTime is too short, this download failure can also occur.
Set to 60 seconds or more.
Normally it is not necessary to specify the path to the CMake generator backend, assuming the generator executable is in environment variable $PATH or
CMAKE_PROGRAM_PATH.
For special use cases such as testing CMake with different versions of a generator the generator executable absolute path may be specified via
CMAKE_MAKE_PROGRAM.
The absolute path to the generator is necessary or CMake will not find it.
Suppose a GitHub Actions Linux image has ninja-linux.zip containing executable file “ninja”.
Get the absolute path using realpath.
CMake Find modules are by their nature a little aggressive about finding libraries and executables.
This becomes a factor on Windows in particular when Anaconda Python is not active in the current Terminal.
CMake find_package(Python) by default prefers Anaconda Python over system Python unless overridden as below.
Anaconda Python won’t operate correctly without conda activate, which presumably the user has either forgotten to do or doesn’t desire at the moment.
To decrease the aggressiveness and find Windows Store Python etc. when conda isn’t activated on Windows, add to the project CMakeLists.txt beforefind_package(Python):
set(Python_FIND_REGISTRYLAST)# this avoids non-active conda from getting picked anyway on Windows
set(Python_FIND_VIRTUALENVSTANDARD)# Use environment variable PATH to decide preference for Python
find_package(Python)
Anaconda Python by default auto-activates the “base” environment each time a new Terminal is opened.
This slows opening new Terminal, particularly on systems with slow disks or virtual disks.
Particularly if the user isn’t constantly using Python, it can be beneficial to make conda only active when specified.
To disable conda auto-activation on new Terminal, type:
Fortran compilers typically have options for enforcing Fortran standards.
The compilers raise additional warnings or errors for code that is not deemed compliant.
Fortran standard options can make false warnings, so we generally do not enable standards checking for user defaults.
However, we do enforce implicit none as a quality measure.
It’s also important to use implicit none so that each variable must be assigned beforehand.
We recommend the Fortran 2018 statement:
implicitnone(type,external)
which requires explicitly defined procedure interfaces as well.
type
the traditional implicit none default
external
new for Fortran 2018, requires explicit interface for external procedures.
GCC Gfortran and Intel oneAPI are the most advanced, widely available modern Fortran compilers.
Useful Fortran 2018 enhancements include:
select rankassumed array rank,
error stop
within pure procedures,
random_init
to initialize random number seed, and
implicit none (type, external)
to require external procedures to be explicitly declared.
GCC 10 is the
oldest version
currently maintained.
Intel oneAPI has full Fortran 2018
support.
To get recent GCC is usually straightforward.
Red Hat should use
GCC Toolset.
macOS Homebrew quickly adds the latest
GCC version.
If Ubuntu gfortran repo
defaults
aren’t adequate, get recent Gfortran via
PPA.
Here are some of the major changes in Gfortran by version:
Gfortran 12 enhances OpenMP 5 and OpenACC 2.6 support. Numerous bugfixes. bind(C) with character length greater than one.
Gfortran 11 completed OpenMP 4.5 support
Gfortran 10 added select rank
Gfortran 9 added random_init() to initialize the random generator seed.
Gfortran 8 added automatic nested loop exchange with do concurrent, actual argument array with too few elements for dummy argument now errors, initial support for parameterized derived types (simply define kind at initialization) and coarray support for teams. Standard flag -std=f2018 added and deprecated -std=f2008ts.
Gfortran 7 added derived type IO select type. Complete Fortran 2003 support, Fortran 2018 non-constant stop and error stop codes, and -fdec- options to help compile very old non-standard code.
Gfortran 6 added Fortran 2008 submodule support, useful for large projects to save compilation time and allow powerful use scenarios.
Fortran 2003 deferred-length character are
useful
for avoiding bothersome trim() everywhere.
GCC 5 added full support for OpenMP 4.0, Fortran 2003 ieee_ intrinsics, Fortran 2008 error stop in pure procedures with constant error code.
GCC 4.9 added Fortran 2003 deferred-length character variables in derived types.
GCC 4.8 supported Fortran 2008 polymorphism, including select type, class(*), type(*), and Fortran 2018 assumed rank dimension(..).
GCC 4.6 was the first version of Gfortran reaching beyond Fortran 95, with Fortran 2003 deferred-length character variable and Fortran 2008 impure elemental support.
GCC 4.5 added Fortran 2008 iso_fortran_env.
GCC 4.4 added initial support for polymorphism and OpenMP 3.
CMake allows switching parameters based on compiler version.
This is very useful for modern Fortran programs.
Example CMakeLists.txt for Fortran compiler version dependent options.
CMake can
detect the host CPU arch
to use with Intel compilers.
We discourage package maintainers from setting flags automatically like “-march=native” (GCC, Clang) and “-xHost” (Intel oneAPI) because they may
break
on user systems such as ARM or HPC.
However, the user can set flags for a project by setting environment variables like CFLAGS before the first project configure in CMake.
This allows optimizing for a target compiler while compiling from a different host.
Or, the user on an appropriate system may simply set their ~/.profile to have CFLAGS=-march=native or similar.