build: add STANDALONE option to build_exec and fix static builds

This commit is contained in:
Gabriel Ferreira
2022-09-24 13:16:05 -03:00
parent 7355065854
commit f8846d22ed
9 changed files with 36 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
additional_commands:
build_exec:
flags: [IGNORE_PCH]
flags: [IGNORE_PCH, STANDALONE]
kwargs:
EXECNAME : '1'
EXECNAME_PREFIX : '1'

View File

@@ -1,6 +1,6 @@
additional_commands:
build_exec:
flags: [IGNORE_PCH]
flags: [IGNORE_PCH, STANDALONE]
kwargs:
EXECNAME : '1'
EXECNAME_PREFIX : '1'

View File

@@ -70,6 +70,3 @@ check_cxx_source_compiles(
"
FILESYSTEM_LIBRARY_IS_LINKED
)
if(NOT FILESYSTEM_LIBRARY_IS_LINKED)
link_libraries(-lstdc++fs)
endif()

View File

@@ -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})

View File

@@ -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}

View File

@@ -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
)

View File

@@ -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(

View File

@@ -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
)

View File

@@ -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):