Write NB_ANTENNAS_RX/TX to header file and use in stack

Prior to this commit, constants NB_ANTENNAS_RX/TX are provided on the
command line to each compiler invocation. This has the drawback (1) that
also files that don't need that get the constants, and (2) it is not
easy to find them using ctags or similar, as the only definition is in
CMakeLists.txt (where it is not found).

In this commit, use cmake configure_file() to write a header file with
these constants. The file will be generated during cmake invocation, and
written to <build-dir>/common/cmake_defs.h. The relevant files that
need this definition will pick it from the header.

This has been used previously also in a commit to write git information.

See-also: 8bffd1666d ("Avoid complete rebuild on cmake run with git info change")
This commit is contained in:
Robert Schmidt
2026-02-20 19:14:28 +01:00
committed by francescomani
parent 0a79dce24b
commit 448f273248
13 changed files with 44 additions and 15 deletions

View File

@@ -549,8 +549,10 @@ endif()
# Hardware dependant options
###################################
add_list1_option(NB_ANTENNAS_RX "4" "Number of antennas in reception" "1" "2" "4")
add_list1_option(NB_ANTENNAS_TX "4" "Number of antennas in transmission" "1" "2" "4")
set(NB_ANTENNAS_RX "4" CACHE STRING "Number of antennas in reception")
set_property(CACHE NB_ANTENNAS_RX PROPERTY STRINGS "1" "2" "4" "8")
set(NB_ANTENNAS_TX "4" CACHE STRING "Number of antennas in transmission")
set_property(CACHE NB_ANTENNAS_TX PROPERTY STRINGS "1" "2" "4" "8")
set (CONFIG_ROOTDIR ${OPENAIR_DIR}/common/config)
add_library(config_internals OBJECT

View File

@@ -34,19 +34,6 @@ macro(add_integer_option name val helpstr)
add_definitions("-D${name}=${value}")
endmacro(add_integer_option)
macro(add_list1_option name val helpstr)
if(DEFINED ${name})
set(value ${${name}})
else(DEFINED ${name})
set(value ${val})
endif()
set(${name} ${value} CACHE STRING "${helpstr}")
set_property(CACHE ${name} PROPERTY STRINGS ${ARGN})
if(NOT "${value}" STREQUAL "False")
add_definitions("-D${name}=${value}")
endif()
endmacro(add_list1_option)
macro(add_list2_option name val helpstr)
if(DEFINED ${name})
set(value ${${name}})

View File

@@ -1,6 +1,7 @@
add_subdirectory(utils)
add_subdirectory(config/yaml)
configure_file(cmake_defs.h.in cmake_defs.h @ONLY)
configure_file(oai_version.h.in oai_version.h @ONLY)
add_library(instrumentation INTERFACE)

30
common/cmake_defs.h.in Normal file
View File

@@ -0,0 +1,30 @@
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef CMAKE_DEFS_H_
#define CMAKE_DEFS_H_
// Note: this file is automatically generated from common/cmake_defs.h.in
// please don't modify and change defines such as NB_ANTENNAS_RX/TX in cmake
#define NB_ANTENNAS_RX @NB_ANTENNAS_RX@
#define NB_ANTENNAS_TX @NB_ANTENNAS_TX@
#endif /* CMAKE_DEFS_H_ */

View File

@@ -56,6 +56,7 @@
#include <math.h>
#include "common_lib.h"
#include "common/cmake_defs.h"
#include "defs_common.h"
#include "impl_defs_top.h"

View File

@@ -39,6 +39,7 @@
#endif
#endif
#include "common/cmake_defs.h"
#include "defs_nr_common.h"
#include "CODING/nrPolar_tools/nr_polar_pbch_defs.h"
#include "PHY/defs_nr_sl_UE.h"

View File

@@ -34,6 +34,7 @@
#define __PHY_IMPLEMENTATION_DEFS_NB_IOT_H__
#include "common/openairinterface5g_limits.h"
#include "common/cmake_defs.h"
#define NUMBER_OF_SUBBANDS_MAX_NB_IoT 13
typedef enum {no_relay_NB_IoT=1,unicast_relay_type1_NB_IoT,unicast_relay_type2_NB_IoT, multicast_relay_NB_IoT} relaying_type_t_NB_IoT;

View File

@@ -35,6 +35,7 @@
#include <unistd.h>
#include <execinfo.h>
#include <signal.h>
#include "common/cmake_defs.h"
#include "common/config/config_load_configmodule.h"
#include "common/utils/LOG/log.h"
#include "common/utils/var_array.h"

View File

@@ -30,6 +30,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include "common/cmake_defs.h"
#include "SIMULATION/TOOLS/defs.h"
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"

View File

@@ -33,6 +33,7 @@
#include <string.h>
#include <math.h>
#include <unistd.h>
#include "common/cmake_defs.h"
#include "common/utils/var_array.h"
#include "PHY/types.h"
#include "PHY/defs_common.h"

View File

@@ -24,6 +24,7 @@
#include <stdint.h>
#include <stdio.h>
#include "common/cmake_defs.h"
#include "SIMULATION/TOOLS/sim.h"
#include "SIMULATION/RF/rf.h"
#include "PHY/phy_extern_ue.h"

View File

@@ -35,6 +35,7 @@
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include "common/cmake_defs.h"
#include <openair1/PHY/TOOLS/tools_defs.h>
#include "record_player.h"
#include "common/utils/threadPool/notified_fifo.h"

View File

@@ -27,6 +27,7 @@
#include <pthread.h>
#include <stdint.h>
#include "common/cmake_defs.h"
#include "xran_fh_o_du.h"
#include "openair1/PHY/impl_defs_nr.h"
#include "openair1/PHY/TOOLS/tools_defs.h"