build: prevent usage of uninitialized variables set inside src modules

This commit is contained in:
Gabriel Ferreira
2024-02-14 23:56:51 +01:00
parent 2209a5abd1
commit 69442e97c3
2 changed files with 36 additions and 1 deletions

View File

@@ -21,6 +21,38 @@ foreach(libname ${libs})
endif()
endforeach()
# Scan for disabled modules that define settings prefixed with NS3_ or ENABLE_
# so that we can initialize them as turned off (setting as temporary variables
# not to affect the cached variables that are set when normally processed)
subdirlist(modules ${CMAKE_CURRENT_SOURCE_DIR})
foreach(libname ${modules})
if(NOT (${libname} IN_LIST libs))
# Skip module directories without CMakeLists.txt files
if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${libname}/CMakeLists.txt))
continue()
endif()
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/${libname}/CMakeLists.txt
lib_cmakelists_contents
)
string(REGEX MATCHALL "(NS3_[a-zA-Z0-9_]*)|(ENABLE_[a-zA-Z0-9_]*)" flags
"${lib_cmakelists_contents}"
)
foreach(flag ${flags})
# Skip reason flags
if(${flag} MATCHES "REASON")
continue()
endif()
# Skip flags already defined
if(DEFINED ${flag})
continue()
endif()
# Set flag to off
set(${flag} OFF PARENT_SCOPE)
endforeach()
endif()
endforeach()
# Prevents link errors due to symbol collisions if the same library is linked
# multiple times
list(REMOVE_DUPLICATES ns3-external-libs)

View File

@@ -1064,7 +1064,10 @@ class NS3ConfigureTestCase(NS3BaseTestCase):
f.write(ns3rc_template.format(modules="'lte'", examples="False", tests="True"))
# Reconfigure.
return_code, stdout, stderr = run_ns3('configure -G "{generator}"')
run_ns3("clean")
return_code, stdout, stderr = run_ns3(
'configure -G "{generator}" -d release --enable-verbose'
)
self.config_ok(return_code, stdout, stderr)
# Check.