Skip to main content

Building for Windows

This document describes the process to build Ocean for Windows. It covers:

  1. General requirements
  2. Building required third-party libraries
  3. Building Ocean

1 Prerequisites

  • General prerequisites listed on the main page
  • CMake 3.25 or higher is required (for CMake preset support)
  • Visual Studio 2019 or later is required (2022 recommended). By default, CMake will auto-detect the newest installed version.

Windows traditionally has a 260-character path limit (MAX_PATH). Ocean's build process can generate deeply nested paths that may exceed this limit. It is highly recommended to enable Long Path support before building.

To enable Long Path support, run this command in an elevated (Administrator) PowerShell:

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1

Alternatively, use the Group Policy Editor:

  1. Open gpedit.msc
  2. Navigate to: Computer Configuration > Administrative Templates > System > Filesystem
  3. Enable: "Enable Win32 long paths"

A system restart may be required after enabling this setting.

Note: The build scripts will automatically check for Long Path support and display a warning if it is not enabled.

2 Building the third-party libraries

The easiest way to build the third-party libraries is by using the provided PowerShell build script, build/cmake/build_thirdparty_windows.ps1. By default, this will build all third-party libraries in both debug and release configurations with static linking.

cd \path\to\ocean
.\build\cmake\build_thirdparty_windows.ps1

Once the build is complete, the compiled binaries can be found in bin/cmake/3rdparty/win/x64_vc145_static_debug and .../win/x64_vc145_static_release (where vc145 corresponds to the Visual Studio toolset version, e.g., vc143 for VS 2022, vc145 for VS 2026; or with arm64_ prefix on ARM64 systems).

The build script can be customized using command-line parameters. Use -Config to specify build configurations, -Link for linking type, -Build for build directory, and -Install for installation directory. For example:

cd \path\to\ocean
.\build\cmake\build_thirdparty_windows.ps1 -Config debug,release -Link static -Build C:\build_oceanTP -Install C:\install_oceanTP

It is advisable to place build and install directories as close to the root of a filesystem as possible, due to Windows limitations on path lengths. Build directories in particular can be very deep.

Run Get-Help .\build\cmake\build_thirdparty_windows.ps1 -Detailed to see all available options.

To use a specific Visual Studio version instead of the auto-detected one:

.\build\cmake\build_thirdparty_windows.ps1 -Generator "Visual Studio 16 2019"

Note: By default, the build scripts only display error messages. To see more detailed CMake output, use -LogLevel STATUS (for general progress information) or other levels like VERBOSE or DEBUG.

3 Building Ocean

Ocean uses CMake presets for build configuration. There are two options for building Ocean on Windows:

The easiest way to build all Ocean libraries and apps is by using the PowerShell script build/cmake/build_ocean.ps1. By default, it will look for third-party libraries in bin/cmake/3rdparty (the default output from the previous step).

cd \path\to\ocean
.\build\cmake\build_ocean.ps1

Once the build is complete, the compiled binaries can be found in bin/cmake/win/x64_vc145_static_debug and .../win/x64_vc145_static_release (where vc145 corresponds to the Visual Studio toolset version; or with arm64_ prefix on ARM64 systems).

The build script can be customized using command-line parameters. For example:

cd \path\to\ocean
.\build\cmake\build_ocean.ps1 -Config debug,release -Link static -Build C:\build_ocean -Install C:\install_ocean -ThirdParty C:\install_oceanTP

Run Get-Help .\build\cmake\build_ocean.ps1 -Detailed to see all available options.

To use a specific Visual Studio version instead of the auto-detected one:

.\build\cmake\build_ocean.ps1 -Generator "Visual Studio 16 2019"

Option B: Using Git Bash

You can also use the unified bash script via Git Bash:

cd /path/to/ocean
./build/cmake/build_ocean.sh

The bash script supports the same options as on other platforms. Run ./build/cmake/build_ocean.sh --help for details.

To use a specific Visual Studio version:

./build/cmake/build_ocean.sh -g "Visual Studio 16 2019"

Using CMake Presets Directly

Alternatively, you can use CMake presets directly without the build scripts:

# List all available presets
cmake --list-presets

# Configure using a preset
cmake --preset windows-x64-static-release -DCMAKE_PREFIX_PATH="C:\install_oceanTP\win\x64_static_release"

# Build and install
cmake --build --preset windows-x64-static-release --target install

To use a specific Visual Studio version with presets, add the -G flag:

cmake --preset windows-x64-static-release -G "Visual Studio 16 2019" -DCMAKE_PREFIX_PATH="C:\install_oceanTP\win\x64_static_release"

Building with Visual Studio

To open the project in Visual Studio after configuration:

# Configure the project
cmake --preset windows-x64-static-release -DCMAKE_PREFIX_PATH="C:\install_oceanTP\win\x64_static_release"

# Open in Visual Studio
start bin\cmake\tmp\win-x64-static-release\ocean.sln

Then build and run the desired targets from within Visual Studio.

tip

This documentation is also available on GitHub.