Skip to content

Latest commit

 

History

History
 
 

cmake

HiGHS CMake Build Instructions

OS C++ Fortran Python CSharp Example .NET
Linux Status Status Status (1) Status
MacOS Status Status Status (1) Status
Windows Status (2) Status Status Status

(1) CMake C# is currently only supported for Microsoft Visual Studio 11 2012 and later. You can still build and run the HiGHS C# nuget package on Linux and MacOS with dotnet, see the workflows in the .NET column. It is only the CSharp example build with CMake that is not supported for Unix generators.

(2) Not tested yet.


Contents

Introduction

HiGHS can be built from source using CMake: http://www.cmake.org/. CMake works by generating native Makefiles or build projects that can be used in the compiler environment of your choice.

HiGHS can be built as a standalone project or it could be incorporated into an existing CMake project.

Requirement

You'll need:

  • CMake >= 3.15.
  • A C++11 compiler

Supported compilers

Here is a list of the supported compilers:

  • Clang clang
  • GNU g++
  • Intel icc
  • Microsoft MSVC

Build

To build the C++ library and executable run

cd HiGHS
cmake -S. -B build 
cmake --build build --parallel

This generates HiGHS in the build directory and creates the [executable](@ref Executable) build/bin/highs, or build/bin/Release/highs.exe on Windows. To perform a quick test to see whether the compilation was successful, run ctest from within the build folder.

ctest 

On Windows, the configuration type must be specified:

ctest -C Release

Install

The default installation location may need administrative permissions. To install, after building and testing, run

cmake --install build 

form the root directory.

To install in a specified installation directory run CMake with the CMAKE_INSTALL_PREFIX flag set:

cmake -S. -B build -DCMAKE_INSTALL_PREFIX=/path/to/highs_install 
cmake --build build --parallel
cmake --install build

Windows

By default, CMake builds the debug version of the binaries. These are generated in a directory Debug. To build a release version, add the option --config Release

    cmake -S . -B build
    cmake --build build --config Release

It is also possible to specify a specific Visual studio version to build with:

    cmake -G "Visual Studio 17 2022" -S . -B build
    cmake --build build

When building under Windows, some extra options are available. One is building a 32 bit version or a 64 bit version. The default build is 64 bit. To build 32 bit, the following commands can be used from the HiGHS/ directory:

    cmake -A Win32 -S . -B buildWin32
    cmake --build buildWin32

Another thing specific for windows is the calling convention, particularly important for the HiGHS dynamic library (dll). The default calling convention in windows is cdecl calling convention, however, dlls are most often compiled with stdcall. Most applications which expect stdcall, can't access dlls with cdecl and vice versa. To change the default calling convention from cdecl to stdcall the following option can be added

    cmake -DSTDCALL=ON -S . -B build
    cmake --build build

CMake Options

There are several options that can be passed to CMake to modify how the code is built.
To set these options and parameters, use -D<Parameter_name>=<value>.

All CMake options are passed at configure time, i.e., by running
cmake -S. -B<your_chosen_build_directory> -DOPTION_ONE=ON -DOPTION_TWO=OFF ...
before running cmake --build <your_chosen_build_directory>

For example, to generate build files in a new subdirectory called 'build', run:

cmake -S. -Bbuild 

and then build with:

cmake --build build

Following is a list of available options:

CMake Option Default Value Note
CMAKE_BUILD_TYPE Release see CMake documentation here
BUILD_SHARED_LIBS ON(*) Build shared libraries (.so or .dyld). * OFF by default on Windows
BUILD_CXX ON Build C++
FORTRAN OFF Build Fortran interface
CSHARP OFF Build CSharp wrapper
BUILD_DOTNET OFF Build .Net package
PYTHON_BUILD_SETUP OFF Build Python bindings. Called at pip install from pyproject.toml
ZLIB ON Use ZLIB if available
ALL_TESTS OFF Run unit tests and extended instance test set

HiGHS can be integrated into other CMake-based projects.

Integrating HiGHS in your CMake Project

If you already have HiGHS installed on your system, you can use find_package() to include HiGHS in your C++ CMake project.

project(LOAD_HIGHS LANGUAGES CXX)

set(HIGHS_DIR path_to_highs_install/lib/cmake/highs)

find_package(HIGHS REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main highs::highs)

The line

set(HIGHS_DIR path_to_highs_install/lib/cmake/highs)

adds the HiGHS installation path to HIGHS_DIR. This is equivalent to building this project with

cmake -DHIGHS_DIR=path_to_highs_install/lib/cmake/highs ..

Alternatively, if you wish to include the code of HiGHS within your project, FetchContent is also available as follows:

project(LOAD_HIGHS LANGUAGES CXX)

include(FetchContent)

FetchContent_Declare(
    highs
    GIT_REPOSITORY "https://github.com/ERGO-Code/HiGHS.git"
    GIT_TAG        "latest"
)

FetchContent_MakeAvailable(highs)

add_executable(main call_from_cpp.cc)
target_link_libraries(main highs::highs)