CMake find with Homebrew

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:

    export CMAKE_PREFIX_PATH=$HOMEBREW_PREFIX
  • Setting CMAKE_PREFIX_PATH as a command line argument to cmake:

    cmake -DCMAKE_PREFIX_PATH=$HOMEBREW_PREFIX -B build

One can also have CMake ignore conda paths to ensure CMake doesn’t find Anaconda libraries or compilers.