
Brent's univariate minimizer and zero finder
This project provides a CMake framework, that automatically downloads and builds Brent's univariate minimizer and zero finder from Netlib (https://netlib.org/c/brent.shar).
Prerequisites
What you need:
- Git (optional) for getting the code and contributing to the project
- CMake for building the project
- C compiler
- gcc for linux/mac (https://gcc.gnu.org/)
- cygwin + gcc for windows (https://www.cygwin.com/)
Linux (Ubuntu)
Use your distribution's package manager to install the packages cmake
and
gcc
.
$ sudo apt-get install cmake gcc
Mac OS X
Homebrew
$ brew install cmake gcc
MacPorts
$ sudo port -v install cmake ninja clang-<XX> gcc<YY>
$ sudo port -v install gcc<YY>-libcxx +clang<XX>
$ sudo port -v install openblas +native
where you have to replace <XX>
with the latest stable version of Clang and
<YY>
with the latest stable version of GCC (it's a dependency of OpenBLAS).
You can discover all available versions of Clang and GCC like this:
$ port search --name --line --regex '^clang-?\d*\.?\d*$'
$ port search --name --line --regex '^gcc\d*$'
Windows
Install Cygwin and use the Cygwin package manager to install the packages
cmake
and gcc-g++
.
How to compile
- Clone the git repository or download the BrentMinimizer source code archive
and unpack it to an arbitrary directory (e.g.
brent-minimizer
). - Go to the
brent-minimizer
directory.-
Type
cp ./CMakeUserPresets.template.json ./CMakeUserPresets.json
. -
Next, type
cmake --workflow --list-presets
. A list of available build workflows will be shown to you. It is strongly recommended to use ashared
variant. You should prefer shared libraries and dynamic linking over static linking. -
For configuring, building and installing the project, type
cmake --workflow --preset user-shared-release-install
. This will try to populate the./build
directory with a CMake configuration tree, execute the build and install the project. By default, the configured installation directory is./install
.But it will fail due to an unaccepted license. Study the license text and proceed to the next step.
-
Open
./CMakeUserPresets.json
in your favorite editor and set"Brent_TERMS_ACCEPTED": true
in the first configure preset"user-config"
. -
Repeat step 2.3. Configuring, building and installing should be successful now.
-
Now, the brent-minimizer
code is compiled and you can use it in other
projects. The installed brent-minimizer
package is discoverable by CMake as
BrentMinimizer. In the CMakeLists.txt
of the other project, call:
find_package(BrentMinimizer CONFIG REQUIRED)
This makes the Netlib::BrentMinimizer
CMake library target available to you.
Then, to help CMake discover the BrentMinimizer package, call CMake for the other project like this:
$ cmake -B ./build -DCMAKE_PREFIX_PATH=/path/to/BrentMinimizer/install/prefix
If BrentMinimizer is installed in a proper system-wide location, the
CMAKE_PREFIX_PATH
shouldn't be necessary.