Skip to content

Commit

Permalink
tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
galabovaa committed May 20, 2024
1 parent 345e4a3 commit 4544e14
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cmake-linux-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: cmake-linux-cpp
on: [push, pull_request]

jobs:

release:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/cmake-macos-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: cmake-macos-cpp
on: [push, pull_request]

jobs:

release:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-csharp-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand All @@ -29,6 +30,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-csharp-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
Expand All @@ -28,6 +29,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-dotnet@v4
- uses: actions/checkout@v4

- name: Create Build Environment
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ option(BUILD_TESTING "Build Tests" ON)
option(FORTRAN "Build Fortran interface" OFF)
message(STATUS "Build Fortran: ${FORTRAN}")
option(CSHARP "Build CSharp interface" OFF)
message(STATUS "Build CSharp: ${CSHARP}")

if (FORTRAN OR CSHARP)
set(BUILD_SHARED_LIBS ON)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
- [Installation](#installation)
- [Build from source using CMake](#build-from-source-using-cmake)
- [Precompiled binaries](#precompiled-binaries)
- [Build with Nix](#build-with-nix)
- [Interfaces](#interfaces)
- [Python](#python)
- [CSharp](#csharp)
- [Python](#python)
- [CSharp](#csharp)
- [Reference](#reference)

## About HiGHS
Expand Down
153 changes: 153 additions & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,156 @@

<!--# ?branch=main -->

## Introduction
<nav for="cmake"> |
<a href="#requirement">Requirement</a> |
<a href="#build">C++</a> |
<a href="#cmake-options">Options</a> |
<a href="#integrating-highs-in-your-cmake-project">Integration</a> |
</nav>

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

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

This creates the [executable](@ref Executable) `build/bin/highs`. To perform a quick test to see whether the compilation was successful, run `ctest` from within the build folder.

``` bash
ctest
```

On Windows, the configuration type must be specified:
``` bash
ctest -C Release
```

## Install

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

``` bash
cmake --install build
```

form the root directory.

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

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

# CMake Options

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

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

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

```sh
cmake -S. -Bbuild
```
and then build with:

```sh
cmake --build build
```

Following is a list of available options:
| CMake Option | Default Value | Note |
|:-------------|:--------------|:-----|
| `CMAKE_BUILD_TYPE` | Release | see CMake documentation [here](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) |
| `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 |

<!-- Following is a list of available options, for the full list run:
```sh
cmake -S. -Bbuild -LH
``` -->

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)
```
22 changes: 14 additions & 8 deletions docs/src/interfaces/cpp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ the full sequence of commands required is as follows

``` bash
cd HiGHS
mkdir build
cd build
cmake -DFAST_BUILD=ON ..
cmake --build .
cmake -S. -B build
cmake --build build --parallel
```

This creates the [executable](@ref Executable) `build/bin/highs`.
Expand All @@ -38,20 +36,28 @@ To perform a quick test to see whether the compilation was successful, run `ctes
ctest
```

On Windows, the configuration type must be specified:

``` bash
ctest -C Release
```

### Install

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

``` bash
cmake --install .
cmake --install build
```

form the root directory.

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

``` bash
cmake -DFAST_BUILD=ON -DCMAKE_INSTALL_PREFIX=/path/to/highs_install ..
cmake --build .
cmake --install .
cmake -S. -B build -DCMAKE_INSTALL_PREFIX=/path/to/highs_install
cmake --build build --parallel
cmake --install build
```
4 changes: 1 addition & 3 deletions docs/src/interfaces/cpp/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ project(LOAD_HIGHS LANGUAGES CXX)
set(HIGHS_DIR path_to_highs_install/lib/cmake/highs)
find_package(HIGHS REQUIRED)
find_package(Threads REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main highs::highs)
Expand All @@ -48,9 +47,8 @@ include(FetchContent)
FetchContent_Declare(
highs
GIT_REPOSITORY "https://github.com/ERGO-Code/HiGHS.git"
GIT_TAG "bazel"
GIT_TAG "latest"
)
set(FAST_BUILD ON CACHE INTERNAL "Fast Build")
FetchContent_MakeAvailable(highs)
Expand Down

0 comments on commit 4544e14

Please sign in to comment.