From 448f27324812a31c14df895ca5c8cdf3c5d57881 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 20 Feb 2026 19:14:28 +0100 Subject: [PATCH] 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 /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: 8bffd1666df6 ("Avoid complete rebuild on cmake run with git info change") --- CMakeLists.txt | 6 +++-- cmake_targets/macros.cmake | 13 ----------- common/CMakeLists.txt | 1 + common/cmake_defs.h.in | 30 +++++++++++++++++++++++++ openair1/PHY/defs_UE.h | 1 + openair1/PHY/defs_nr_UE.h | 1 + openair1/PHY/impl_defs_top_NB_IoT.h | 1 + openair1/SIMULATION/LTE_PHY/dlsim.c | 1 + openair1/SIMULATION/LTE_PHY/syncsim.c | 1 + openair1/SIMULATION/LTE_PHY/ulsim.c | 1 + openair1/SIMULATION/TOOLS/channel_sim.c | 1 + radio/COMMON/common_lib.h | 1 + radio/fhi_72/oran_isolate.h | 1 + 13 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 common/cmake_defs.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 46016431aa..d0b9f17a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake_targets/macros.cmake b/cmake_targets/macros.cmake index eafee3a0c1..cc59e12a90 100644 --- a/cmake_targets/macros.cmake +++ b/cmake_targets/macros.cmake @@ -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}}) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index f58880b04a..be079b874d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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) diff --git a/common/cmake_defs.h.in b/common/cmake_defs.h.in new file mode 100644 index 0000000000..c2221bf5e5 --- /dev/null +++ b/common/cmake_defs.h.in @@ -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_ */ diff --git a/openair1/PHY/defs_UE.h b/openair1/PHY/defs_UE.h index cd8ce75906..82cc747581 100644 --- a/openair1/PHY/defs_UE.h +++ b/openair1/PHY/defs_UE.h @@ -56,6 +56,7 @@ #include #include "common_lib.h" +#include "common/cmake_defs.h" #include "defs_common.h" #include "impl_defs_top.h" diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h index 5511d8ed0d..c14751a050 100644 --- a/openair1/PHY/defs_nr_UE.h +++ b/openair1/PHY/defs_nr_UE.h @@ -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" diff --git a/openair1/PHY/impl_defs_top_NB_IoT.h b/openair1/PHY/impl_defs_top_NB_IoT.h index a6409839a4..8d05e9a05e 100644 --- a/openair1/PHY/impl_defs_top_NB_IoT.h +++ b/openair1/PHY/impl_defs_top_NB_IoT.h @@ -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; diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c index d6e8482919..a09b3558cb 100644 --- a/openair1/SIMULATION/LTE_PHY/dlsim.c +++ b/openair1/SIMULATION/LTE_PHY/dlsim.c @@ -35,6 +35,7 @@ #include #include #include +#include "common/cmake_defs.h" #include "common/config/config_load_configmodule.h" #include "common/utils/LOG/log.h" #include "common/utils/var_array.h" diff --git a/openair1/SIMULATION/LTE_PHY/syncsim.c b/openair1/SIMULATION/LTE_PHY/syncsim.c index 456bc53a2c..c29b16e041 100644 --- a/openair1/SIMULATION/LTE_PHY/syncsim.c +++ b/openair1/SIMULATION/LTE_PHY/syncsim.c @@ -30,6 +30,7 @@ #include #include +#include "common/cmake_defs.h" #include "SIMULATION/TOOLS/defs.h" #include "SIMULATION/RF/defs.h" #include "PHY/types.h" diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c index 7a442a4082..92b9d58f48 100644 --- a/openair1/SIMULATION/LTE_PHY/ulsim.c +++ b/openair1/SIMULATION/LTE_PHY/ulsim.c @@ -33,6 +33,7 @@ #include #include #include +#include "common/cmake_defs.h" #include "common/utils/var_array.h" #include "PHY/types.h" #include "PHY/defs_common.h" diff --git a/openair1/SIMULATION/TOOLS/channel_sim.c b/openair1/SIMULATION/TOOLS/channel_sim.c index 9f196b02ec..5115587bfc 100644 --- a/openair1/SIMULATION/TOOLS/channel_sim.c +++ b/openair1/SIMULATION/TOOLS/channel_sim.c @@ -24,6 +24,7 @@ #include #include +#include "common/cmake_defs.h" #include "SIMULATION/TOOLS/sim.h" #include "SIMULATION/RF/rf.h" #include "PHY/phy_extern_ue.h" diff --git a/radio/COMMON/common_lib.h b/radio/COMMON/common_lib.h index f21a1ffff4..693ca0e3c7 100644 --- a/radio/COMMON/common_lib.h +++ b/radio/COMMON/common_lib.h @@ -35,6 +35,7 @@ #include #include #include +#include "common/cmake_defs.h" #include #include "record_player.h" #include "common/utils/threadPool/notified_fifo.h" diff --git a/radio/fhi_72/oran_isolate.h b/radio/fhi_72/oran_isolate.h index 4f62ff5340..44c9bee51d 100644 --- a/radio/fhi_72/oran_isolate.h +++ b/radio/fhi_72/oran_isolate.h @@ -27,6 +27,7 @@ #include #include +#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"