diff --git a/build-support/custom-modules/ns3-module-macros.cmake b/build-support/custom-modules/ns3-module-macros.cmake index a64790840..f4cf3c98d 100644 --- a/build-support/custom-modules/ns3-module-macros.cmake +++ b/build-support/custom-modules/ns3-module-macros.cmake @@ -129,11 +129,11 @@ function(build_lib) # Add library to a global list of libraries if("${FOLDER}" MATCHES "src") - set(ns3-libs "${lib${BLIB_LIBNAME}};${ns3-libs}" + set(ns3-libs "${BLIB_LIBNAME};${ns3-libs}" CACHE INTERNAL "list of processed upstream modules" ) else() - set(ns3-contrib-libs "${lib${BLIB_LIBNAME}};${ns3-contrib-libs}" + set(ns3-contrib-libs "${BLIB_LIBNAME};${ns3-contrib-libs}" CACHE INTERNAL "list of processed contrib modules" ) endif() @@ -142,30 +142,27 @@ function(build_lib) # Create object library with sources and headers, that will be used in # lib-ns3-static and the shared library add_library( - ${lib${BLIB_LIBNAME}-obj} OBJECT "${BLIB_SOURCE_FILES}" - "${BLIB_HEADER_FILES}" + ${BLIB_LIBNAME}-obj OBJECT "${BLIB_SOURCE_FILES}" "${BLIB_HEADER_FILES}" ) if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BLIB_IGNORE_PCH})) - target_precompile_headers(${lib${BLIB_LIBNAME}-obj} REUSE_FROM stdlib_pch) + target_precompile_headers(${BLIB_LIBNAME}-obj REUSE_FROM stdlib_pch) endif() # Create shared library with previously created object library (saving # compilation time for static libraries) - add_library( - ${lib${BLIB_LIBNAME}} SHARED $ - ) + add_library(${BLIB_LIBNAME} SHARED $) else() # Xcode and CMake don't play well when using object libraries, so we have a # specific path for that - add_library(${lib${BLIB_LIBNAME}} SHARED "${BLIB_SOURCE_FILES}") + add_library(${BLIB_LIBNAME} SHARED "${BLIB_SOURCE_FILES}") if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BLIB_IGNORE_PCH})) - target_precompile_headers(${lib${BLIB_LIBNAME}} REUSE_FROM stdlib_pch) + target_precompile_headers(${BLIB_LIBNAME} REUSE_FROM stdlib_pch) endif() endif() - add_library(ns3::${lib${BLIB_LIBNAME}} ALIAS ${lib${BLIB_LIBNAME}}) + add_library(ns3::${BLIB_LIBNAME} ALIAS ${BLIB_LIBNAME}) # Associate public headers with library for installation purposes set(config_headers) @@ -183,17 +180,15 @@ function(build_lib) if(${ENABLE_EXAMPLES} AND ${ENABLE_TESTS}) if(NOT ${XCODE}) target_compile_definitions( - ${lib${BLIB_LIBNAME}}-obj PRIVATE NS3_ENABLE_EXAMPLES + ${BLIB_LIBNAME}-obj PRIVATE NS3_ENABLE_EXAMPLES ) else() - target_compile_definitions( - ${lib${BLIB_LIBNAME}} PRIVATE NS3_ENABLE_EXAMPLES - ) + target_compile_definitions(${BLIB_LIBNAME} PRIVATE NS3_ENABLE_EXAMPLES) endif() endif() endif() set_target_properties( - ${lib${BLIB_LIBNAME}} + ${BLIB_LIBNAME} PROPERTIES PUBLIC_HEADER "${BLIB_HEADER_FILES};${BLIB_DEPRECATED_HEADER_FILES};${config_headers};${CMAKE_HEADER_OUTPUT_DIRECTORY}/${BLIB_LIBNAME}-module.h" @@ -204,7 +199,7 @@ function(build_lib) ) if(${NS3_CLANG_TIMETRACE}) - add_dependencies(timeTraceReport ${lib${BLIB_LIBNAME}}) + add_dependencies(timeTraceReport ${BLIB_LIBNAME}) endif() # Split ns and non-ns libraries to manage their propagation properly @@ -215,12 +210,15 @@ function(build_lib) foreach(library ${BLIB_LIBRARIES_TO_LINK}) remove_lib_prefix("${library}" module_name) - # Ignore the case where the library dependency name match the ns-3 module - # since it is most likely is due to brite, click and openflow collisions. - # All the ns-3 module targets should be prefixed with 'lib' to be - # differentiable. + # In case the dependency library matches the ns-3 module, we are most likely + # dealing with brite, click and openflow collisions. All the ns-3 module + # targets used to be prefixed with 'lib' to be differentiable, but now we + # are dropping it. To disambiguate them two, we assume these external + # libraries are shared libraries by adding suffixes. if("${library}" STREQUAL "${BLIB_LIBNAME}") - list(APPEND non_ns_libraries_to_link ${library}) + list(APPEND non_ns_libraries_to_link + ${library}${CMAKE_SHARED_LIBRARY_SUFFIX} + ) continue() endif() @@ -259,7 +257,7 @@ function(build_lib) # with NS3_REEXPORT_THIRD_PARTY_LIBRARIES, we export all 3rd-party library # include directories, allowing consumers of this module to include and link # the 3rd-party code with no additional setup - get_target_includes(${lib${BLIB_LIBNAME}} exported_include_directories) + get_target_includes(${BLIB_LIBNAME} exported_include_directories) string(REPLACE "-I" "" exported_include_directories "${exported_include_directories}" @@ -290,18 +288,16 @@ function(build_lib) endif() target_link_libraries( - ${lib${BLIB_LIBNAME}} ${exported_libraries} ${private_libraries} + ${BLIB_LIBNAME} ${exported_libraries} ${private_libraries} ) if(NOT ${XCODE}) - target_link_libraries( - ${lib${BLIB_LIBNAME}}-obj PRIVATE ${ns_libraries_to_link} - ) + target_link_libraries(${BLIB_LIBNAME}-obj PRIVATE ${ns_libraries_to_link}) endif() # set output name of library set_target_properties( - ${lib${BLIB_LIBNAME}} + ${BLIB_LIBNAME} PROPERTIES OUTPUT_NAME ns${NS3_VER}-${BLIB_LIBNAME}${build_profile_suffix} ) @@ -310,17 +306,14 @@ function(build_lib) # add the build/include path to them, so that they can ns-3 headers with # target_include_directories( - ${lib${BLIB_LIBNAME}} - PUBLIC $ - $ + ${BLIB_LIBNAME} PUBLIC $ + $ INTERFACE ${exported_include_directories} ) # Export definitions as interface definitions, propagating local definitions # to other modules and scratches - get_target_property( - target_definitions ${lib${BLIB_LIBNAME}} COMPILE_DEFINITIONS - ) + get_target_property(target_definitions ${BLIB_LIBNAME} COMPILE_DEFINITIONS) if(${target_definitions} STREQUAL "target_definitions-NOTFOUND") set(target_definitions) endif() @@ -329,8 +322,8 @@ function(build_lib) list(REMOVE_DUPLICATES exported_definitions) list(REMOVE_ITEM exported_definitions "") set_target_properties( - ${lib${BLIB_LIBNAME}} PROPERTIES INTERFACE_COMPILE_DEFINITIONS - "${exported_definitions}" + ${BLIB_LIBNAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS + "${exported_definitions}" ) set(ns3-external-libs "${non_ns_libraries_to_link};${ns3-external-libs}" @@ -339,7 +332,7 @@ function(build_lib) ) if(${NS3_STATIC} OR ${NS3_MONOLIB}) set(lib-ns3-static-objs - "$;${lib-ns3-static-objs}" + "$;${lib-ns3-static-objs}" CACHE INTERNAL "list of object files from module used by NS3_STATIC and NS3_MONOLIB" @@ -351,7 +344,7 @@ function(build_lib) # Check if headers actually exist to prevent copying errors during # installation - get_target_property(headers_to_check ${lib${BLIB_LIBNAME}} PUBLIC_HEADER) + get_target_property(headers_to_check ${BLIB_LIBNAME} PUBLIC_HEADER) set(missing_headers) foreach(header ${headers_to_check}) if(NOT ((EXISTS ${header}) OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${header}) @@ -419,7 +412,7 @@ function(build_lib) list(LENGTH BLIB_TEST_SOURCES test_source_len) if(${test_source_len} GREATER 0) # Create BLIB_LIBNAME of output library test of module - set(test${BLIB_LIBNAME} lib${BLIB_LIBNAME}-test CACHE INTERNAL "") + set(test${BLIB_LIBNAME} ${BLIB_LIBNAME}-test CACHE INTERNAL "") # Create shared library containing tests of the module on UNIX and just # the object file that will be part of test-runner on Windows @@ -443,7 +436,7 @@ function(build_lib) ) else() target_link_libraries( - ${test${BLIB_LIBNAME}} ${LIB_AS_NEEDED_PRE} ${lib${BLIB_LIBNAME}} + ${test${BLIB_LIBNAME}} ${LIB_AS_NEEDED_PRE} ${BLIB_LIBNAME} "${BLIB_LIBRARIES_TO_LINK}" ${LIB_AS_NEEDED_POST} ) endif() @@ -479,7 +472,7 @@ function(build_lib) # Handle package export install( - TARGETS ${lib${BLIB_LIBNAME}} + TARGETS ${BLIB_LIBNAME} EXPORT ns3ExportTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ @@ -540,7 +533,7 @@ function(build_lib_example) SOURCE_FILES ${BLIB_EXAMPLE_SOURCE_FILES} HEADER_FILES ${BLIB_EXAMPLE_HEADER_FILES} LIBRARIES_TO_LINK - ${lib${BLIB_LIBNAME}} ${BLIB_EXAMPLE_LIBRARIES_TO_LINK} + ${BLIB_LIBNAME} ${BLIB_EXAMPLE_LIBRARIES_TO_LINK} ${ns3-optional-visualizer-lib} EXECUTABLE_DIRECTORY_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${FOLDER}/ ${IGNORE_PCH} diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 0afd9b8cf..12f052bfb 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -92,7 +92,7 @@ macro(SUBDIRLIST result curdir) endmacro() macro(library_target_name libname targetname) - set(${targetname} lib${libname}) + set(${targetname} ${libname}) endmacro() macro(clear_global_cached_variables) @@ -199,7 +199,8 @@ macro(process_options) set(ENABLE_TESTS OFF) if(${NS3_TESTS} OR ${ns3rc_tests_enabled}) set(ENABLE_TESTS ON) - enable_testing() + # CTest creates a TEST target that conflicts with ns-3 test library + # enable_testing() else() list(REMOVE_ITEM libs_to_build test) endif() diff --git a/ns3 b/ns3 index 7862ee990..9a1b4c088 100755 --- a/ns3 +++ b/ns3 @@ -1303,7 +1303,7 @@ def build_step( # Build targets in the list for target in args.build: if target in ns3_modules: - target = "lib" + target + pass elif target not in non_executable_targets: target = get_target_to_build(target, ns3_version, build_profile) else: diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index 3bbf73873..a27a65cfe 100755 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -23,6 +23,7 @@ Test suite for the ns3 wrapper script import glob import os +import platform import re import shutil import subprocess @@ -54,6 +55,7 @@ cmake_build_target_command = partial( win32 = sys.platform == "win32" platform_makefiles = "MinGW Makefiles" if win32 else "Unix Makefiles" ext = ".exe" if win32 else "" +arch = platform.machine() def run_ns3(args, env=None, generator=platform_makefiles): @@ -695,7 +697,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase): # Build core to check if profile suffixes match the expected. return_code, stdout, stderr = run_ns3("build core") self.assertEqual(return_code, 0) - self.assertIn("Built target libcore", stdout) + self.assertIn("Built target core", stdout) libraries = get_libraries_list() self.assertGreater(len(libraries), 0) @@ -726,7 +728,7 @@ class NS3ConfigureBuildProfileTestCase(unittest.TestCase): # Build core to check if profile suffixes match the expected return_code, stdout, stderr = run_ns3("build core") self.assertEqual(return_code, 0) - self.assertIn("Built target libcore", stdout) + self.assertIn("Built target core", stdout) libraries = get_libraries_list() self.assertGreater(len(libraries), 0) @@ -888,7 +890,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # If nothing went wrong, this should have worked self.assertEqual(return_code, 0) - self.assertIn("Built target libcore-test", stdout) + self.assertIn("Built target core-test", stdout) # Now we disabled the tests return_code, stdout, stderr = run_ns3('configure -G "{generator}" --disable-tests') @@ -1079,7 +1081,9 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertLess(len(get_enabled_modules()), len(self.ns3_modules)) self.assertIn("ns3-lte", enabled_modules) self.assertTrue(get_test_enabled()) - self.assertLessEqual(len(get_programs_list()), len(self.ns3_executables)) + self.assertLessEqual( + len(get_programs_list()), len(self.ns3_executables) + (1 if win32 else 0) + ) # Replace the ns3rc file with the wifi module, enabling examples and disabling tests with open(ns3rc_script, "w", encoding="utf-8") as f: @@ -1359,6 +1363,14 @@ class NS3ConfigureTestCase(NS3BaseTestCase): f.write("") # Reload the cmake cache to pick them up + # It will fail because the empty scratch has no main function + return_code, stdout, stderr = run_ns3('configure -G "{generator}"') + self.assertEqual(return_code, 1) + + # Remove the empty.cc file and try again + empty = "scratch/empty.cc" + os.remove(empty) + test_files.remove(empty) return_code, stdout, stderr = run_ns3('configure -G "{generator}"') self.assertEqual(return_code, 0) @@ -1388,7 +1400,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertEqual(return_code, 1) run_ns3("clean") - with DockerContainerManager(self, "ubuntu:20.04") as container: + with DockerContainerManager(self, "ubuntu:22.04") as container: container.execute("apt-get update") container.execute("apt-get install -y python3 cmake g++ ninja-build") try: @@ -1632,7 +1644,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Check if we can build this library return_code, stdout, stderr = run_ns3("build calibre") self.assertEqual(return_code, 0) - self.assertIn(cmake_build_target_command(target="libcalibre"), stdout) + self.assertIn(cmake_build_target_command(target="calibre"), stdout) shutil.rmtree("contrib/calibre", ignore_errors=True) @@ -1816,12 +1828,12 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertTrue(False, "Build with lld failed") # Now add mold to the PATH - if not os.path.exists("./mold-1.4.2-x86_64-linux.tar.gz"): + if not os.path.exists(f"./mold-1.4.2-{arch}-linux.tar.gz"): container.execute( - "wget https://github.com/rui314/mold/releases/download/v1.4.2/mold-1.4.2-x86_64-linux.tar.gz" + f"wget https://github.com/rui314/mold/releases/download/v1.4.2/mold-1.4.2-{arch}-linux.tar.gz" ) container.execute( - "tar xzfC mold-1.4.2-x86_64-linux.tar.gz /usr/local --strip-components=1" + f"tar xzfC mold-1.4.2-{arch}-linux.tar.gz /usr/local --strip-components=1" ) # Configure should detect and use mold @@ -1842,7 +1854,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertTrue(False, "Build with mold failed") # Delete mold leftovers - os.remove("./mold-1.4.2-x86_64-linux.tar.gz") + os.remove(f"./mold-1.4.2-{arch}-linux.tar.gz") # Disable use of fast linkers container.execute("./ns3 configure -G Ninja -- -DNS3_FAST_LINKERS=OFF") @@ -1862,14 +1874,14 @@ class NS3ConfigureTestCase(NS3BaseTestCase): """ run_ns3("clean") - with DockerContainerManager(self, "ubuntu:20.04") as container: + with DockerContainerManager(self, "ubuntu:22.04") as container: container.execute("apt-get update") - container.execute("apt-get install -y python3 ninja-build cmake clang-10") + container.execute("apt-get install -y python3 ninja-build cmake clang-12") # Enable ClangTimeTrace without git (it should fail) try: container.execute( - "./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 -DNS3_CLANG_TIMETRACE=ON" + "./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DNS3_CLANG_TIMETRACE=ON" ) except DockerException as e: self.assertIn("could not find git for clone of ClangBuildAnalyzer", e.stderr) @@ -1879,7 +1891,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Enable ClangTimeTrace without git (it should succeed) try: container.execute( - "./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-10 -DNS3_CLANG_TIMETRACE=ON" + "./ns3 configure -G Ninja --enable-modules=core --enable-examples --enable-tests -- -DCMAKE_CXX_COMPILER=/usr/bin/clang++-12 -DNS3_CLANG_TIMETRACE=ON" ) except DockerException as e: self.assertIn("could not find git for clone of ClangBuildAnalyzer", e.stderr) @@ -1901,7 +1913,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Now try with GCC, which should fail during the configuration run_ns3("clean") container.execute("apt-get install -y g++") - container.execute("apt-get remove -y clang-10") + container.execute("apt-get remove -y clang-12") try: container.execute( @@ -2008,18 +2020,6 @@ class NS3ConfigureTestCase(NS3BaseTestCase): run_ns3("clean") - # Ubuntu 20.04 ships with: - # - cmake 3.16: does support PCH - # - ccache 3.7: incompatible with pch - with DockerContainerManager(self, "ubuntu:20.04") as container: - container.execute("apt-get update") - container.execute("apt-get install -y python3 cmake ccache g++") - try: - container.execute("./ns3 configure") - except DockerException as e: - self.assertIn("incompatible with ccache", e.stderr) - run_ns3("clean") - # Ubuntu 22.04 ships with: # - cmake 3.22: does support PCH # - ccache 4.5: compatible with pch @@ -2054,7 +2054,7 @@ class NS3ConfigureTestCase(NS3BaseTestCase): run_ns3("clean") - with DockerContainerManager(self, "ubuntu:20.04") as container: + with DockerContainerManager(self, "ubuntu:22.04") as container: container.execute("apt-get update") container.execute("apt-get install -y python3 cmake g++") return_code = 0 @@ -2089,7 +2089,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): """ return_code, stdout, stderr = run_ns3("build core") self.assertEqual(return_code, 0) - self.assertIn("Built target libcore", stdout) + self.assertIn("Built target core", stdout) def test_02_BuildNonExistingTargets(self): """! @@ -2340,8 +2340,8 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): # Import ns-3 libraries with as a CMake package cmake_find_package_import = """ list(APPEND CMAKE_PREFIX_PATH ./{lib}/cmake/ns3) - find_package(ns3 {version} COMPONENTS libcore) - target_link_libraries(test PRIVATE ns3::libcore) + find_package(ns3 {version} COMPONENTS core) + target_link_libraries(test PRIVATE ns3::core) """.format( lib=("lib64" if lib64 else "lib"), version=version ) @@ -2394,7 +2394,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): stderr.replace("\n", ""), ) elif import_method == pkgconfig_import: - self.assertIn("A required package was not found", stderr.replace("\n", "")) + self.assertIn("not found", stderr.replace("\n", "")) else: raise Exception("Unknown import type") else: @@ -2405,7 +2405,7 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): return_code, stdout, stderr = run_program("cmake", "--build .", cwd=install_prefix) if version == "3.00": - self.assertEqual(return_code, 2) + self.assertEqual(return_code, 2, msg=stdout + stderr) self.assertGreater(len(stderr), 0) else: self.assertEqual(return_code, 0) @@ -2524,6 +2524,14 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): Test if we can build a static ns-3 library and link it to static programs @return None """ + if (not win32) and (arch == "aarch64"): + if platform.libc_ver()[0] == "glibc": + from packaging.version import Version + + if Version(platform.libc_ver()[1]) < Version("2.37"): + self.skipTest( + "Static linking on ARM64 requires glibc 2.37 where fPIC was enabled (fpic is limited in number of GOT entries)" + ) # First enable examples and static build return_code, stdout, stderr = run_ns3( @@ -3150,6 +3158,7 @@ class NS3ExpectedUseTestCase(NS3BaseTestCase): return_code, stdout, stderr = run_ns3("clean") self.assertEqual(return_code, 0) + if arch != "aarch64": # Install VcPkg dependencies container.execute("apt-get install -y zip unzip tar curl")