diff --git a/build-support/cmake-format-modules.txt b/build-support/cmake-format-modules.txt index d2aa474c1..706d0011e 100644 --- a/build-support/cmake-format-modules.txt +++ b/build-support/cmake-format-modules.txt @@ -1,6 +1,6 @@ additional_commands: build_exec: - flags: [IGNORE_PCH] + flags: [IGNORE_PCH, STANDALONE] kwargs: EXECNAME : '1' EXECNAME_PREFIX : '1' diff --git a/build-support/cmake-format.txt b/build-support/cmake-format.txt index 891651910..8b925366e 100644 --- a/build-support/cmake-format.txt +++ b/build-support/cmake-format.txt @@ -1,6 +1,6 @@ additional_commands: build_exec: - flags: [IGNORE_PCH] + flags: [IGNORE_PCH, STANDALONE] kwargs: EXECNAME : '1' EXECNAME_PREFIX : '1' diff --git a/build-support/custom-modules/ns3-compiler-workarounds.cmake b/build-support/custom-modules/ns3-compiler-workarounds.cmake index 3c6a8236e..8b64ab8db 100644 --- a/build-support/custom-modules/ns3-compiler-workarounds.cmake +++ b/build-support/custom-modules/ns3-compiler-workarounds.cmake @@ -70,6 +70,3 @@ check_cxx_source_compiles( " FILESYSTEM_LIBRARY_IS_LINKED ) -if(NOT FILESYSTEM_LIBRARY_IS_LINKED) - link_libraries(-lstdc++fs) -endif() diff --git a/build-support/custom-modules/ns3-module-macros.cmake b/build-support/custom-modules/ns3-module-macros.cmake index 49f97d46d..844a74580 100644 --- a/build-support/custom-modules/ns3-module-macros.cmake +++ b/build-support/custom-modules/ns3-module-macros.cmake @@ -98,6 +98,10 @@ function(build_lib) ) endif() + if(NOT FILESYSTEM_LIBRARY_IS_LINKED) + list(APPEND BLIB_LIBRARIES_TO_LINK -lstdc++fs) + endif() + # Enable examples as tests suites if(${ENABLE_EXAMPLES} AND ${ENABLE_TESTS}) if(NOT ${XCODE}) diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 26a9a88cb..5634892be 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -1058,7 +1058,9 @@ macro(process_options) mark_as_advanced(MAKE) find_program(MAKE NAMES make mingw32-make) if(${MAKE} STREQUAL "MAKE-NOTFOUND") - message(FATAL_ERROR "Make was not found but it is required by Sphinx docs") + message( + FATAL_ERROR "Make was not found but it is required by Sphinx docs" + ) elseif(${MAKE} MATCHES "mingw32-make") # This is a super wild hack for MinGW # @@ -1253,7 +1255,10 @@ macro(process_options) set(PRECOMPILE_HEADERS_ENABLED OFF) if(${NS3_PRECOMPILE_HEADERS}) if(${NS3_CLANG_TIDY}) - message(${HIGHLIGHTED_STATUS} "Clang-tidy is incompatible with precompiled headers. Continuing without them.") + message( + ${HIGHLIGHTED_STATUS} + "Clang-tidy is incompatible with precompiled headers. Continuing without them." + ) elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0") set(PRECOMPILE_HEADERS_ENABLED ON) message(STATUS "Precompiled headers were enabled") @@ -1395,7 +1400,7 @@ endfunction(set_runtime_outputdirectory) function(build_exec) # Argument parsing - set(options IGNORE_PCH) + set(options IGNORE_PCH STANDALONE) set(oneValueArgs EXECNAME EXECNAME_PREFIX EXECUTABLE_DIRECTORY_PATH INSTALL_DIRECTORY_PATH ) @@ -1418,12 +1423,12 @@ function(build_exec) ) endif() - if(${NS3_STATIC}) + if(${NS3_STATIC} AND (NOT BEXEC_STANDALONE)) target_link_libraries( ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE_STATIC} ${lib-ns3-static} ) - elseif(${NS3_MONOLIB}) + elseif(${NS3_MONOLIB} AND (NOT BEXEC_STANDALONE)) target_link_libraries( ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE} ${lib-ns3-monolib} ${LIB_AS_NEEDED_POST} diff --git a/doc/manual/source/working-with-cmake.rst b/doc/manual/source/working-with-cmake.rst index f65daab03..57fb63cd6 100644 --- a/doc/manual/source/working-with-cmake.rst +++ b/doc/manual/source/working-with-cmake.rst @@ -1535,6 +1535,13 @@ The path is relative to the ``CMAKE_INSTALL_PREFIX`` (e.g. /usr). To set custom compiler defines for that specific executable, defines can be passed to the ``DEFINITIONS`` argument. +Add the ``STANDALONE`` option to prevent linking the ns-3 static library +(``NS3_STATIC``) and single shared library (``NS3_MONOLIB``) to the executable. +This may be necessary in case the executable redefine symbols which are part +of the ns-3 library. This is the case for the fd-net-device creators and the tap-creator, +which include the source file ``encode-decode.cc``, which is also part of fd-net-device module +and tap-bridge module, respectively. + Finally, to ignore precompiled headers, include ``IGNORE_PCH`` to the list of parameters. You can find more information about ``IGNORE_PCH`` at the `PCH side-effects`_ section. @@ -1551,6 +1558,7 @@ You can find more information about ``IGNORE_PCH`` at the `PCH side-effects`_ se EXECNAME_PREFIX scratch_subdir_prefix_ # target name = scratch_subdir_prefix_example INSTALL_DIRECTORY_PATH ${CMAKE_INSTALL_BIN}/ # e.g. /usr/bin/ns3.37-scratch_subdir_prefix_example-debug DEFINITIONS -DHAVE_FEATURE=1 # defines for this specific target + [STANDALONE] # set in case you don't want the executable to be linked to ns3-static/ns3-monolib IGNORE_PCH ) diff --git a/src/fd-net-device/CMakeLists.txt b/src/fd-net-device/CMakeLists.txt index 957a7a413..a2814b4e9 100644 --- a/src/fd-net-device/CMakeLists.txt +++ b/src/fd-net-device/CMakeLists.txt @@ -163,6 +163,7 @@ if(${ENABLE_FDNETDEV}) EXECUTABLE_DIRECTORY_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/src/fd-net-device/ INSTALL_DIRECTORY_PATH ${CMAKE_INSTALL_LIBEXECDIR}/ns3 + STANDALONE ) list( @@ -198,6 +199,7 @@ if(${ENABLE_FDNETDEV}) EXECUTABLE_DIRECTORY_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/src/fd-net-device/ INSTALL_DIRECTORY_PATH ${CMAKE_INSTALL_LIBEXECDIR}/ns3 + STANDALONE ) list( @@ -235,6 +237,7 @@ if(${ENABLE_FDNETDEV}) EXECUTABLE_DIRECTORY_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/src/fd-net-device/ INSTALL_DIRECTORY_PATH ${CMAKE_INSTALL_LIBEXECDIR}/ns3 + STANDALONE ) list( diff --git a/src/tap-bridge/CMakeLists.txt b/src/tap-bridge/CMakeLists.txt index 642e960ef..f1cf8a5c5 100644 --- a/src/tap-bridge/CMakeLists.txt +++ b/src/tap-bridge/CMakeLists.txt @@ -43,4 +43,5 @@ build_exec( model/tap-encode-decode.cc EXECUTABLE_DIRECTORY_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/src/tap-bridge/ INSTALL_DIRECTORY_PATH ${CMAKE_INSTALL_LIBEXECDIR}/ns3 + STANDALONE ) diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index 39b41a22c..5b0be5d2b 100644 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -1280,7 +1280,12 @@ class NS3ConfigureTestCase(NS3BaseTestCase): self.assertIn("Invalid library name: %s" % invalid_or_nonexistent_library, stderr) elif invalid_or_nonexistent_library in ["gsd", "libfi", "calibre"]: self.assertEqual(return_code, 2) # should fail due to missing library - self.assertIn("cannot find -l%s" % invalid_or_nonexistent_library, stderr) + # GCC's LD says cannot find + # LLVM's LLD says unable to find + if "lld" in stdout + stderr: + self.assertIn("unable to find library -l%s" % invalid_or_nonexistent_library, stderr) + else: + self.assertIn("cannot find -l%s" % invalid_or_nonexistent_library, stderr) else: pass @@ -1611,8 +1616,8 @@ class NS3ConfigureTestCase(NS3BaseTestCase): # Delete mold leftovers os.remove("./mold-1.4.2-x86_64-linux.tar.gz") - # Reconfigure to clean leftovers before the next test - NS3ConfigureTestCase.cleaned_once = False + # Clean leftovers before proceeding + run_ns3("clean") class NS3BuildBaseTestCase(NS3BaseTestCase):