Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake sample scripts #703

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
build/
install/

# CMakeUserPresets.json is user-specific.
# It should never be checked in.
CMakeUserPresets.json
# CMake pre-load scripts
/dpdk.cmake
/es2k.cmake

# CMake user presets
/CMakeUserPresets.json
3 changes: 2 additions & 1 deletion scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# CMake build file for script files
#
# Copyright 2023 Intel Corporation
# Copyright 2023-2024 Intel Corporation
# SPDX-License-Identifier: Apache 2.0
#

set(GENSCRIPT_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen/genscript.py CACHE PATH
"Command to generate a script file using a template")
mark_as_advanced(GENSCRIPT_COMMAND)

add_subdirectory(cmake)
add_subdirectory(common)

if(DPDK_TARGET)
Expand Down
12 changes: 12 additions & 0 deletions scripts/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Intel Corporation
# SPDX-License-Identifier: Apache 2.0

install(
FILES
CMakeUserPresets.json
dpdk.cmake
es2k.cmake
README.md
DESTINATION
${CMAKE_INSTALL_PREFIX}/share/p4cp/cmake
)
50 changes: 50 additions & 0 deletions scripts/cmake/CMakeUserPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"version": 4,
"configurePresets": [
{
"name": "dpdk",
"displayName": "DPDK target (P4OVS mode)",
"inherits": [
"base-dpdk-target",
"install-path-presets",
"ovs-legacy-mode"
]
},
{
"name": "dpdk-ovsp4rt",
"displayName": "DPDK target (OVSP4RT mode)",
"inherits": [
"base-dpdk-target",
"install-path-presets",
"ovs-ovsp4rt-mode"
]
},
{
"name": "es2k",
"displayName": "ES2K target (P4OVS mode)",
"inherits": [
"base-es2k-target",
"install-path-presets",
"ovs-legacy-mode"
]
},
{
"name": "es2k-ovsp4rt",
"displayName": "ES2K target (OVSP4RT mode)",
"inherits": [
"base-es2k-target",
"install-path-presets",
"ovs-ovsp4rt-mode"
]
},
{
"name": "tofino",
"displayName": "Tofino target (no OVS)",
"inherits": [
"base-tofino-target",
"install-path-presets"
]

}
]
}
98 changes: 98 additions & 0 deletions scripts/cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Sample CMake Scripts

This folder contains sample scripts that may be customized and added
to your build environment.

## Pre-load scripts

- `dpdk.cmake`
- `es2k.cmake`

### About pre-load scripts

These scripts allow you to specify one or more sets of parameters to be
applied at cmake configuration time.

Each file defines one or more cmake variables to be loaded into the cache
after the command line is processed and before the first CMakeLists.txt
file is read.

To use a sample script, copy it to the top-level folder and make any
changes you wish. You can create as many pre-load scripts as you want.

Pre-load scripts are customer-specific and are not stored in the
repository.

### Configure with a pre-load script

```bash
cmake -B build -C dpdk.cmake [more options]
```

### Override an option

```bash
cmake -B build -C es2k.cmake -DCMAKE_INSTALL_PREFIX=/opt/p4cp
```

## Preset files

- `CMakeUserPresets.json`

### About presets

This file defines user presets that can be used to configure cmake.
It makes use of hidden presets that are defined in `CMakePresets.json`,
which is stored in the repository.

To use it, copy the file to the top-level (networking-recipe) directory
and make any changes you want. Deleting targets you don't plan to use
would be a good place to start.

User presets are customer-specific and are not stored in the repository.
The `.gitignore` file instructs git to ignore the file if it is in the
top-level directory.

Presets were introduced in cmake 3.19. This file uses schema version 4,
which requires cmake 3.23.0 or later.

See the [cmake-presets guide](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)
for more information.

### List available presets

```text
frodo@bagend:~/networking-recipe$ cmake --list-presets
Available configure presets:

"dpdk" - DPDK target (P4OVS mode)
"dpdk-ovsp4rt" - DPDK target (OVSP4RT mode)
"es2k" - ES2K target (P4OVS mode)
"es2k-ovsp4rt" - ES2K target (OVSP4RT mode)
"tofino" - Tofino target (no OVS)
```

### Configure using a preset

```text
frodo@bagend:~/networking-recipe$ cmake --preset dpdk
Preset CMake variables:

CMAKE_BUILD_TYPE="RelWithDebInfo"
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE"
CMAKE_INSTALL_PREFIX:PATH="/home/dfoster/work/latest/install"
DEPEND_INSTALL_DIR:PATH="/opt/deps"
OVS_INSTALL_DIR:PATH="/home/dfoster/work/latest/ovs/install"
P4OVS_MODE="P4OVS"
SDE_INSTALL_DIR:PATH="/home/dfoster/SDE/install"
SET_RPATH:BOOL="TRUE"
TDI_TARGET="dpdk"

-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
.
.
-- Configuring done (2.4s)
-- Generating done (0.4s)
-- Build files have been written to: /home/bilbo/networking-recipe/build
```
9 changes: 9 additions & 0 deletions scripts/cmake/dpdk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configures CMake for a DPDK build.
# Usage: cmake -B <build-dir> -C dpdk.cmake

set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "p4cp install directory")
set(DEPEND_INSTALL_DIR "$ENV{DEPEND_INSTALL}" CACHE PATH "stratum-deps install directory")
set(OVS_INSTALL_DIR "${CMAKE_SOURCE_DIR}/ovs/install" CACHE PATH "ovs install directory")
set(SDE_INSTALL_DIR "$ENV{SDE_INSTALL}" CACHE PATH "SDE install directory")
set(SET_RPATH YES CACHE BOOL "Whether to set RPATH in binary artifacts")
set(TDI_TARGET "DPDK" CACHE STRING "TDI target to build")
9 changes: 9 additions & 0 deletions scripts/cmake/es2k.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configures CMake for an ES2K build.
# Usage: cmake -B <build-dir> -C es2k.cmake

set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "p4cp install directory")
set(DEPEND_INSTALL_DIR "$ENV{DEPEND_INSTALL}" CACHE PATH "stratum-deps install directory")
set(OVS_INSTALL_DIR "${CMAKE_SOURCE_DIR}/ovs/install" CACHE PATH "ovs install directory")
set(SDE_INSTALL_DIR "$ENV{SDE_INSTALL}" CACHE PATH "SDE install directory")
set(SET_RPATH YES CACHE BOOL "Whether to set RPATH in binary artifacts")
set(TDI_TARGET "ES2K" CACHE STRING "TDI target to build")
Loading