Skip to content

Commit

Permalink
Let cmake supply default build type (#286)
Browse files Browse the repository at this point in the history
- In CMakeLists.txt, define default CMAKE_BUILD_TYPE after
  project() command. Provide list of valid build types for
  user interface tools.

- In make-all.sh, don't define CMAKE_BUILD_TYPE if type is not
  explicitly specified.

- In make-cross-ovs.sh and config-cross-recipe.sh, don't define
  default CMAKE_BUILD_TYPE.

- Separate Path options in the config-cross-recipe.sh help text
  and user guide into Host and Target categories.

Signed-off-by: Derek G Foster <[email protected]>
  • Loading branch information
ffoulkes authored Sep 21, 2023
1 parent 3860bdd commit 049134f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 51 deletions.
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# Version 3.15 is the baseline for P4 Control Plane.
cmake_minimum_required(VERSION 3.15)

# CMAKE_BUILD_TYPE must be set before the first project() command.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Type of build to perform")

project(networking-recipe VERSION 23.07 LANGUAGES C CXX)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
Expand All @@ -19,9 +16,17 @@ include(CTest)
include(FindPkgConfig)
include(GNUInstallDirs)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the build type"
FORCE)
endif()

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug;MinSizeRel;Release;RelWithDebInfo")

cmake_print_variables(CMAKE_STAGING_PREFIX)
cmake_print_variables(CMAKE_SYSROOT)
cmake_print_variables(CMAKE_TOOLCHAIN_FILE)
cmake_print_variables(CMAKE_STAGING_PREFIX)

#############################
# Symbolic path definitions #
Expand Down
41 changes: 22 additions & 19 deletions docs/scripts/config-cross-recipe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ General
``--help``, ``-h``
Displays usage information and exits.

Paths
-----
Host paths
----------

``--build=BLDDIR``, ``-B BLDDIR``
Directory that CMake will use to perform the build.
Expand All @@ -65,16 +65,6 @@ Paths
cross-compiled builds.
Defaults to ``build``.

``--deps=DEPS``, ``-D DEPS`` *(see note)*
Directory in which the Stratum dependencies for the runtime system
are installed.

P4 Control Plane will be linked with these libraries.
Supplies the value of the ``DEPEND_INSTALL_DIR`` listfile variable.
Defaults to the value of the ``DEPEND_INSTALL`` environment variable,
if defined.
Otherwise, defaults to ``//opt/deps``.

``--host=HOST``, ``-H HOST``
Directory in which the Stratum dependencies for the development
system are installed.
Expand All @@ -85,6 +75,26 @@ Paths
if defined.
Otherwise, defaults to ``setup/hostdeps``.

``--toolchain=FILE``, ``-T FILE``
Path to the CMake toolchain file.

Specifies the value of the ``CMAKE_TOOLCHAIN_FILE`` variable.
Defaults to the value of the ``CMAKE_TOOLCHAIN_FILE`` environment
variable.

Target paths
------------

``--deps=DEPS``, ``-D DEPS`` *(see note)*
Directory in which the Stratum dependencies for the runtime system
are installed.

P4 Control Plane will be linked with these libraries.
Supplies the value of the ``DEPEND_INSTALL_DIR`` listfile variable.
Defaults to the value of the ``DEPEND_INSTALL`` environment variable,
if defined.
Otherwise, defaults to ``//opt/deps``.

``--ovs=OVS``, ``-O OVS`` *(see note)*
Directory in which Open vSwitch is installed.

Expand Down Expand Up @@ -114,13 +124,6 @@ Paths
if defined.
Otherwise, defaults to ``//opt/p4sde``.

``--toolchain=FILE``, ``-T FILE``
Path to the CMake toolchain file.

Specifies the value of the ``CMAKE_TOOLCHAIN_FILE`` variable.
Defaults to the value of the ``CMAKE_TOOLCHAIN_FILE`` environment
variable.

.. note::
``//`` at the beginning of the directory path will be replaced with
the *sysroot* directory path.
Expand Down
26 changes: 13 additions & 13 deletions make-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2022-2023 Intel Corporation
# SPDX-License-Identifier: Apache 2.0
#
# Sample script to configure and build the P4 Control Plane software.
# Sample script to configure and build P4 Control Plane.
#

# Abort on error.
Expand All @@ -13,7 +13,6 @@ set -e
# Default values #
##################

_BLD_TYPE="RelWithDebInfo"
_DEPS_DIR=${DEPEND_INSTALL}
_HOST_DIR=${HOST_INSTALL}
_NJOBS=8
Expand All @@ -36,7 +35,11 @@ _WITH_OVS=1

print_help() {
echo ""
echo "Configure and build P4 Control Plane software"
echo "Configure and build P4 Control Plane"
echo ""
echo "General:"
echo " --dry-run -n Display cmake parameters and exit"
echo " --help -h Display help text and exit"
echo ""
echo "Paths:"
echo " --deps=DIR -D Target dependencies directory [${_DEPS_DIR}]"
Expand All @@ -50,8 +53,6 @@ print_help() {
echo "Options:"
echo " --coverage Instrument build to measure code coverage"
echo " --cxx-std=STD C++ standard (11|14|17) [$_CXX_STD])"
echo " --dry-run -n Display cmake parameter values and exit"
echo " --help -h Display this help text"
echo " --jobs=NJOBS -j Number of build threads [${_NJOBS}]"
echo " --no-build Configure without building"
echo " --no-krnlmon Exclude Kernel Monitor"
Expand All @@ -61,11 +62,9 @@ print_help() {
echo "Configurations:"
echo " --debug Debug configuration"
echo " --minsize MinSizeRel configuration"
echo " --reldeb RelWithDebInfo configuration (default)"
echo " --reldeb RelWithDebInfo configuration"
echo " --release Release configuration"
echo ""
echo " Default config is RelWithDebInfo (--reldeb)"
echo ""
echo "Environment variables:"
echo " CMAKE_TOOLCHAIN_FILE - Default toolchain file"
echo " DEPEND_INSTALL - Default target dependencies directory"
Expand All @@ -82,7 +81,7 @@ print_help() {
print_cmake_params() {
echo ""
[ -n "${_GENERATOR}" ] && echo "${_GENERATOR}"
echo "CMAKE_BUILD_TYPE=${_BLD_TYPE}"
[ -n "${_BUILD_TYPE}" ] && echo "${_BUILD_TYPE:2}"
echo "CMAKE_INSTALL_PREFIX=${_PREFIX}"
[ -n "${_STAGING_PREFIX}" ] && echo "${_STAGING_PREFIX:2}"
[ -n "${_TOOLCHAIN_FILE}" ] && echo "${_TOOLCHAIN_FILE:2}"
Expand Down Expand Up @@ -113,7 +112,7 @@ print_cmake_params() {
config_ovs() {
# shellcheck disable=SC2086
cmake -S ovs -B ${_OVS_BLD} \
-DCMAKE_BUILD_TYPE=${_BLD_TYPE} \
${_BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX="${_OVS_DIR}" \
${_TOOLCHAIN_FILE} \
-DP4OVS=ON
Expand All @@ -135,7 +134,7 @@ config_recipe() {
# shellcheck disable=SC2086
cmake -S . -B ${_BLD_DIR} \
${_GENERATOR} \
-DCMAKE_BUILD_TYPE=${_BLD_TYPE} \
${_BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX="${_PREFIX}" \
${_STAGING_PREFIX} \
${_TOOLCHAIN_FILE} \
Expand All @@ -144,7 +143,8 @@ config_recipe() {
${_HOST_DEPEND_DIR} \
-DOVS_INSTALL_DIR="${_OVS_DIR}" \
-DSDE_INSTALL_DIR="${_SDE_DIR}" \
${_WITH_KRNLMON} ${_WITH_OVSP4RT} \
${_WITH_KRNLMON} \
${_WITH_OVSP4RT} \
${_COVERAGE} \
${_SET_RPATH} \
${_TARGET_TYPE}
Expand Down Expand Up @@ -175,7 +175,6 @@ LONGOPTS=${LONGOPTS},no-build,no-krnlmon,no-ovs,no-rpath
GETOPTS=$(getopt -o ${SHORTOPTS} --long ${LONGOPTS} -- "$@")
eval set -- "${GETOPTS}"

# Process command-line options.
while true ; do
case "$1" in
# Paths
Expand Down Expand Up @@ -270,6 +269,7 @@ if [ -z "${_SDE_DIR}" ]; then
exit 1
fi

[ -n "${_BLD_TYPE}" ] && _BUILD_TYPE="-DCMAKE_BUILD_TYPE=${_BLD_TYPE}"
[ -n "${_CXX_STD}" ] && _CXX_STANDARD="-DCMAKE_CXX_STANDARD=${_CXX_STD}"
[ -n "${_HOST_DIR}" ] && _HOST_DEPEND_DIR="-DHOST_DEPEND_DIR=${_HOST_DIR}"
[ -n "${_RPATH}" ] && _SET_RPATH="-DSET_RPATH=${_RPATH}"
Expand Down
12 changes: 12 additions & 0 deletions ovs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ include(GNUInstallDirs)
option(P4OVS "Build OVS with P4Runtime support" OFF)
option(WITH_RUNDIRS "Build with OVS runtime directories" OFF)

##############
# Build type #
##############

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose the build type" FORCE)
endif()

set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug;MinSizeRel;Release;RelWithDebInfo")

####################
# Path definitions #
####################
Expand Down
24 changes: 12 additions & 12 deletions scripts/es2k/config-cross-recipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ _SYSROOT=${SDKTARGETSYSROOT}
# Default values #
##################

_BLD_TYPE=RelWithDebInfo
_DEPS_DIR="${DEPEND_INSTALL:-//opt/deps}"
_HOST_DIR="${HOST_INSTALL:-setup/host-deps}"
_OVS_DIR="${OVS_INSTALL:-//opt/ovs}"
Expand All @@ -41,20 +40,24 @@ _DRY_RUN=0

print_help() {
echo ""
echo "Configure P4 Control Plane build"
echo "Configure P4 Control Plane build for ACC"
echo ""
echo "Paths:"
echo "General:"
echo " --dry-run -n Display cmake parameters and exit"
echo " --help -h Display help text and exit"
echo ""
echo "Host paths:"
echo " --build=DIR -B Build directory path [${_BLD_DIR}]"
echo " --host=DIR -H Host dependencies directory [${_HOST_DIR}]"
echo " --toolchain=FILE -T CMake toolchain file"
echo ""
echo "Target paths:"
echo " --deps=DIR* -D Target dependencies directory [${_DEPS_DIR}]"
echo " --host=DIR* -H Host dependencies directory [${_HOST_DIR}]"
echo " --ovs=DIR* -O OVS install directory [${_OVS_DIR}]"
echo " --prefix=DIR* -P Install directory prefix [${_PREFIX}]"
echo " --sde=DIR* -S SDE install directory [${_SDE_DIR}]"
echo " --toolchain=FILE -T CMake toolchain file"
echo ""
echo "Options:"
echo " --dry-run -n Display cmake parameter values and exit"
echo " --help -h Display this help text"
echo " --no-krnlmon Exclude Kernel Monitor"
echo " --no-ovs Exclude OVS support"
echo ""
Expand All @@ -77,7 +80,6 @@ print_help() {

print_cmake_params() {
echo ""
echo "CMAKE_BUILD_TYPE=${_BLD_TYPE}"
echo "CMAKE_INSTALL_PREFIX=${_PREFIX}"
echo "CMAKE_TOOLCHAIN_FILE=${_TOOLFILE}"
echo "DEPEND_INSTALL_DIR=${_DEPS_DIR}"
Expand Down Expand Up @@ -160,7 +162,6 @@ done
[ "${_PREFIX:0:2}" = "//" ] && _PREFIX=${_SYSROOT}/${_PREFIX:2}
[ "${_SDE_DIR:0:2}" = "//" ] && _SDE_DIR=${_SYSROOT}/${_SDE_DIR:2}

# Expand WITH_KRNLMON and WITH_OVSP4RT if not empty
[ -n "${_WITH_KRNLMON}" ] && _WITH_KRNLMON=-DWITH_KRNLMON=${_WITH_KRNLMON}
[ -n "${_WITH_OVSP4RT}" ] && _WITH_OVSP4RT=-DWITH_OVSP4RT=${_WITH_OVSP4RT}

Expand All @@ -176,9 +177,8 @@ fi

rm -fr "${_BLD_DIR}"

# shellcheck disable=SC2086
cmake -S . -B "${_BLD_DIR}" \
-DCMAKE_BUILD_TYPE=${_BLD_TYPE} \
# shellcheck disable=SC2086
cmake -S . -B "${_BLD_DIR}" \
-DCMAKE_INSTALL_PREFIX="${_PREFIX}" \
-DCMAKE_TOOLCHAIN_FILE="${_TOOLFILE}" \
-DDEPEND_INSTALL_DIR="${_DEPS_DIR}" \
Expand Down
3 changes: 0 additions & 3 deletions scripts/es2k/make-cross-ovs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ _SYSROOT=${SDKTARGETSYSROOT}
##################

_BLD_DIR=ovs/build
_BLD_TYPE=RelWithDebInfo
_DRY_RUN=0
_NJOBS=8
_PREFIX=//opt/ovs
Expand Down Expand Up @@ -65,7 +64,6 @@ print_help() {

print_cmake_params() {
echo ""
echo "CMAKE_BUILD_TYPE=${_BLD_TYPE}"
echo "CMAKE_INSTALL_PREFIX=${_PREFIX}"
echo "CMAKE_TOOLCHAIN_FILE=${_TOOLFILE}"
echo "JOBS=${_NJOBS}"
Expand Down Expand Up @@ -136,7 +134,6 @@ fi
rm -fr "${_BLD_DIR}"

cmake -S ovs -B "${_BLD_DIR}" \
-DCMAKE_BUILD_TYPE=${_BLD_TYPE} \
-DCMAKE_INSTALL_PREFIX="${_PREFIX}" \
-DCMAKE_TOOLCHAIN_FILE="${_TOOLFILE}" \
-DP4OVS=TRUE
Expand Down

0 comments on commit 049134f

Please sign in to comment.