build,test: fixing CMake and ns3 issues and adding a test case

Includes:
- refactoring lib prefix removal and library dependency checking (fixes #598)
- add new test case for test-ns3.py to test library names
- fix ns3 issue, not accepting to build contrib libraries
- ignore gitlab-ci-local directory in test-ns3.py
This commit is contained in:
Gabriel Ferreira
2022-03-16 22:44:30 -03:00
parent 7a3cf8ce8d
commit 6a6b785c5f
4 changed files with 141 additions and 30 deletions

View File

@@ -114,8 +114,10 @@ function(build_lib)
set(ns_libraries_to_link)
foreach(library ${BLIB_LIBRARIES_TO_LINK})
# Remove lib prefix from module name (e.g. libcore -> core)
string(REPLACE "lib" "" module_name "${library}")
remove_lib_prefix("${library}" module_name)
# Check if the module exists in the ns-3 modules list
# or if it is a 3rd-party library
if(${module_name} IN_LIST ns3-all-enabled-modules)
list(APPEND ns_libraries_to_link ${library})
else()
@@ -483,20 +485,7 @@ function(build_lib_example)
get_filename_component(FOLDER ${FOLDER} DIRECTORY)
# cmake-format: on
set(missing_dependencies)
foreach(lib ${BLIB_EXAMPLE_LIBRARIES_TO_LINK})
# skip check for ns-3 modules if its a path to a library
if(EXISTS ${lib})
continue()
endif()
# check if the example depends on disabled modules
string(REPLACE "lib" "" lib ${lib})
if(NOT (${lib} IN_LIST ns3-all-enabled-modules))
list(APPEND missing_dependencies ${lib})
endif()
endforeach()
check_for_missing_libraries(missing_dependencies "${BLIB_EXAMPLE_LIBRARIES_TO_LINK}")
if(NOT missing_dependencies)
# Create shared library with sources and headers
add_executable(

View File

@@ -1299,6 +1299,39 @@ function(copy_headers_before_building_lib libname outputdir headers visibility)
endforeach()
endfunction(copy_headers_before_building_lib)
function(remove_lib_prefix prefixed_library library)
# Check if we still have something remaining
# after removing the "lib" prefix
string(LENGTH ${prefixed_library} len)
if(${len} LESS 4)
message(FATAL_ERROR "Invalid library name: ${prefixed_library}")
endif()
# Remove lib prefix from module name (e.g. libcore -> core)
string(SUBSTRING "${prefixed_library}" 3 -1 lib)
set(${library} ${lib} PARENT_SCOPE)
endfunction()
function(check_for_missing_libraries output_variable_name libraries)
set(missing_dependencies)
foreach(lib ${libraries})
# skip check for ns-3 modules if its a path to a library
if(EXISTS ${lib})
continue()
endif()
# check if the example depends on disabled modules
remove_lib_prefix("${lib}" lib)
# Check if the module exists in the ns-3 modules list
# or if it is a 3rd-party library
if(NOT (${lib} IN_LIST ns3-all-enabled-modules))
list(APPEND missing_dependencies ${lib})
endif()
endforeach()
set(${output_variable_name} ${missing_dependencies} PARENT_SCOPE)
endfunction()
# Import macros used for modules and define specialized versions for src modules
include(build-support/custom-modules/ns3-module-macros.cmake)
@@ -1314,19 +1347,7 @@ macro(build_example)
"EXAMPLE" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
)
set(missing_dependencies)
foreach(lib ${EXAMPLE_LIBRARIES_TO_LINK})
# skip check for ns-3 modules if its a path to a library
if(EXISTS ${lib})
continue()
endif()
# check if the example depends on disabled modules
string(REPLACE "lib" "" lib ${lib})
if(NOT (${lib} IN_LIST ns3-all-enabled-modules))
list(APPEND missing_dependencies ${lib})
endif()
endforeach()
check_for_missing_libraries(missing_dependencies "${EXAMPLE_LIBRARIES_TO_LINK}")
if(NOT missing_dependencies)
# Create shared library with sources and headers