From 6473b7ec98d35d7429b917de784397284cbef11d Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Fri, 13 May 2022 16:40:15 -0300 Subject: [PATCH] build: rollback linking to globally searched libraries --- build-support/macros-and-definitions.cmake | 11 ----------- examples/stats/wifi-example-sim.cc | 4 ++-- src/CMakeLists.txt | 9 +++++++++ src/brite/examples/CMakeLists.txt | 1 + src/config-store/CMakeLists.txt | 16 ++++++++++++++-- src/core/CMakeLists.txt | 12 +++++++++++- src/core/examples/CMakeLists.txt | 1 + src/mpi/CMakeLists.txt | 6 ++++-- src/mpi/examples/CMakeLists.txt | 2 ++ src/point-to-point/CMakeLists.txt | 1 + src/stats/CMakeLists.txt | 5 +++++ src/visualizer/CMakeLists.txt | 1 + src/wifi/CMakeLists.txt | 8 ++++++++ utils/tests/test-ns3.py | 21 +++++++++++++++++++++ 14 files changed, 80 insertions(+), 18 deletions(-) diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 34b577785..04c790f12 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -538,7 +538,6 @@ macro(process_options) set(ENABLE_SQLITE True) add_definitions(-DHAVE_SQLITE3) include_directories(${SQLite3_INCLUDE_DIRS}) - link_libraries(${SQLite3_LIBRARIES}) else() message(${HIGHLIGHTED_STATUS} "SQLite was not found") endif() @@ -638,11 +637,7 @@ macro(process_options) ) else() message(STATUS "GTK3 was found.") - if(${GCC}) - add_definitions(-Wno-parentheses) - endif() include_directories(${GTK3_INCLUDE_DIRS} ${HarfBuzz_INCLUDE_DIRS}) - link_libraries(${GTK3_LIBRARIES}) endif() endif() @@ -669,7 +664,6 @@ macro(process_options) message(STATUS "LibXML2 was found.") add_definitions(-DHAVE_LIBXML2) include_directories(${LIBXML2_INCLUDE_DIR}) - link_libraries(${LIBXML2_LIBRARIES}) endif() # LibRT @@ -688,7 +682,6 @@ macro(process_options) message(STATUS "LibRT was found.") set(ENABLE_REALTIME TRUE) set(HAVE_RT TRUE) # for core-config.h - link_libraries(${LIBRT_LIBRARIES}) endif() endif() endif() @@ -747,7 +740,6 @@ macro(process_options) endif() endif() include_directories(${Python3_INCLUDE_DIRS}) - link_libraries(${Python3_LIBRARIES}) else() message(${HIGHLIGHTED_STATUS} "Python: development libraries were not found" @@ -877,7 +869,6 @@ macro(process_options) message(STATUS "MPI was found.") add_definitions(-DNS3_MPI) include_directories(${MPI_CXX_INCLUDE_DIRS}) - link_libraries(${MPI_CXX_LIBRARIES}) set(ENABLE_MPI TRUE) endif() endif() @@ -907,7 +898,6 @@ macro(process_options) message(STATUS "GSL was found.") add_definitions(-DHAVE_GSL) include_directories(${GSL_INCLUDE_DIRS}) - link_libraries(${GSL_LIBRARIES}) endif() endif() @@ -2096,7 +2086,6 @@ endfunction() function(get_target_includes target output) set(include_directories) get_target_property(include_dirs ${target} INCLUDE_DIRECTORIES) - list(REMOVE_DUPLICATES include_dirs) foreach(include_dir ${include_dirs}) if(include_dir MATCHES "<") # Skip CMake build and install interface includes diff --git a/examples/stats/wifi-example-sim.cc b/examples/stats/wifi-example-sim.cc index fc8a813a6..f2d65769a 100644 --- a/examples/stats/wifi-example-sim.cc +++ b/examples/stats/wifi-example-sim.cc @@ -94,7 +94,7 @@ int main (int argc, char *argv[]) { return -1; } - #ifndef HAVE_SQLITE3 + #ifndef STATS_HAS_SQLITE3 if (format == "db") { NS_LOG_ERROR ("sqlite support not compiled in."); return -1; @@ -300,7 +300,7 @@ int main (int argc, char *argv[]) { NS_LOG_INFO ("Creating omnet formatted data output."); output = CreateObject(); } else if (format == "db") { - #ifdef HAVE_SQLITE3 + #ifdef STATS_HAS_SQLITE3 NS_LOG_INFO ("Creating sqlite formatted data output."); output = CreateObject(); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4b1d41659..7d1def183 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,10 @@ foreach(libname ${libs}) endif() endforeach() +# Prevents link errors due to symbol collisions if the same library is linked +# multiple times +list(REMOVE_DUPLICATES ns3-external-libs) + # Build the lib-ns3-static (ns3.x-static-buildtype.a/.lib) with all sublibraries if(${NS3_STATIC}) add_library( @@ -48,6 +52,11 @@ if(${NS3_STATIC}) endif() endforeach() + # Required by some static libraries, such as sqlite, for some odd reason + if(LINUX) + list(APPEND ns3-external-static-libs -ldl) + endif() + target_link_libraries( ${lib-ns3-static} -static diff --git a/src/brite/examples/CMakeLists.txt b/src/brite/examples/CMakeLists.txt index 5ac00d54b..1440b6f20 100644 --- a/src/brite/examples/CMakeLists.txt +++ b/src/brite/examples/CMakeLists.txt @@ -20,5 +20,6 @@ if(${ENABLE_MPI}) ${libnix-vector-routing} ${libapplications} ${libmpi} + ${MPI_CXX_LIBRARIES} ) endif() diff --git a/src/config-store/CMakeLists.txt b/src/config-store/CMakeLists.txt index a271264b7..4a2931264 100644 --- a/src/config-store/CMakeLists.txt +++ b/src/config-store/CMakeLists.txt @@ -9,12 +9,21 @@ if(${GTK3_FOUND}) set(gtk3_headers model/gtk-config-store.h ) + set(gtk_libraries + ${GTK3_LIBRARIES} + ) + if(${GCC}) + add_definitions(-Wno-parentheses) + endif() endif() if(${LIBXML2_FOUND}) set(xml2_sources model/xml-config.cc ) + set(xml2_libraries + ${LIBXML2_LIBRARIES} + ) endif() build_lib( @@ -31,6 +40,9 @@ build_lib( ${gtk3_headers} model/file-config.h model/config-store.h - LIBRARIES_TO_LINK ${libcore} - ${libnetwork} + LIBRARIES_TO_LINK + ${libcore} + ${libnetwork} + ${xml2_libraries} + ${gtk_libraries} ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 23f160abf..9621e944e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,8 +1,14 @@ # Set lib core link dependencies -set(libraries_to_link) +set(libraries_to_link + ${CMAKE_THREAD_LIBS_INIT} +) set(gsl_test_sources) if(${GSL_FOUND}) + set(libraries_to_link + ${libraries_to_link} + ${GSL_LIBRARIES} + ) set(gsl_test_sources test/rng-test-suite.cc test/random-variable-stream-test-suite.cc @@ -69,6 +75,10 @@ if(${ENABLE_REALTIME}) model/realtime-simulator-impl.h model/wall-clock-synchronizer.h ) + set(libraries_to_link + ${libraries_to_link} + ${LIBRT} + ) endif() set(osclock_sources diff --git a/src/core/examples/CMakeLists.txt b/src/core/examples/CMakeLists.txt index 17824b7ab..986927680 100644 --- a/src/core/examples/CMakeLists.txt +++ b/src/core/examples/CMakeLists.txt @@ -47,6 +47,7 @@ if(${ENABLE_REALTIME}) NAME main-test-sync SOURCE_FILES main-test-sync.cc LIBRARIES_TO_LINK ${libnetwork} + ${CMAKE_THREAD_LIBS_INIT} ) endif() diff --git a/src/mpi/CMakeLists.txt b/src/mpi/CMakeLists.txt index cc5ddb158..f5184e8ed 100644 --- a/src/mpi/CMakeLists.txt +++ b/src/mpi/CMakeLists.txt @@ -21,7 +21,9 @@ build_lib( model/mpi-interface.h model/mpi-receiver.h model/parallel-communication-interface.h - LIBRARIES_TO_LINK ${libcore} - ${libnetwork} + LIBRARIES_TO_LINK + ${libcore} + ${libnetwork} + ${MPI_CXX_LIBRARIES} TEST_SOURCES ${example_as_test_suite} ) diff --git a/src/mpi/examples/CMakeLists.txt b/src/mpi/examples/CMakeLists.txt index 70c2e21b4..7688d4c6a 100644 --- a/src/mpi/examples/CMakeLists.txt +++ b/src/mpi/examples/CMakeLists.txt @@ -1,3 +1,5 @@ +link_libraries(${MPI_CXX_LIBRARIES}) + set(base_examples simple-distributed simple-distributed-mpi-comm diff --git a/src/point-to-point/CMakeLists.txt b/src/point-to-point/CMakeLists.txt index 2c2871db7..f5dc99635 100644 --- a/src/point-to-point/CMakeLists.txt +++ b/src/point-to-point/CMakeLists.txt @@ -11,6 +11,7 @@ if(${ENABLE_MPI}) ) set(mpi_libraries ${libmpi} + ${MPI_CXX_LIBRARIES} ) endif() diff --git a/src/stats/CMakeLists.txt b/src/stats/CMakeLists.txt index c6dd1477a..e525e0b2f 100644 --- a/src/stats/CMakeLists.txt +++ b/src/stats/CMakeLists.txt @@ -1,5 +1,6 @@ set(sqlite_sources) set(sqlite_header) +set(sqlite_libraries) if(${ENABLE_SQLITE}) set(sqlite_sources model/sqlite-data-output.cc @@ -9,6 +10,9 @@ if(${ENABLE_SQLITE}) model/sqlite-data-output.h model/sqlite-output.h ) + set(sqlite_libraries + ${SQLite3_LIBRARIES} + ) endif() set(source_files @@ -69,6 +73,7 @@ build_lib( SOURCE_FILES ${source_files} HEADER_FILES ${header_files} LIBRARIES_TO_LINK ${libcore} + ${sqlite_libraries} TEST_SOURCES test/average-test-suite.cc test/basic-data-calculators-test-suite.cc diff --git a/src/visualizer/CMakeLists.txt b/src/visualizer/CMakeLists.txt index 0330bf85c..97f662d52 100644 --- a/src/visualizer/CMakeLists.txt +++ b/src/visualizer/CMakeLists.txt @@ -4,6 +4,7 @@ build_lib( model/visual-simulator-impl.cc HEADER_FILES model/pyviz.h LIBRARIES_TO_LINK + ${Python3_LIBRARIES} ${libcore} ${libinternet} ${libwifi} diff --git a/src/wifi/CMakeLists.txt b/src/wifi/CMakeLists.txt index ec5d5e9ed..9062a3816 100644 --- a/src/wifi/CMakeLists.txt +++ b/src/wifi/CMakeLists.txt @@ -1,3 +1,10 @@ +set(gsl_libraries) +if(${GSL_FOUND}) + set(gsl_libraries + ${GSL_LIBRARIES} + ) +endif() + set(source_files helper/athstats-helper.cc helper/spectrum-wifi-helper.cc @@ -283,6 +290,7 @@ build_lib( ${libspectrum} ${libantenna} ${libmobility} + ${gsl_libraries} TEST_SOURCES test/block-ack-test-suite.cc test/channel-access-manager-test.cc diff --git a/utils/tests/test-ns3.py b/utils/tests/test-ns3.py index 1d9db6a9b..87313425f 100644 --- a/utils/tests/test-ns3.py +++ b/utils/tests/test-ns3.py @@ -1679,6 +1679,27 @@ class NS3BuildBaseTestCase(NS3BaseTestCase): # Remove second os.remove("./scratch/second.cc") + NS3BuildBaseTestCase.cleaned_once = False + + def test_12_StaticBuilds(self): + """! + Test if we can build a static ns-3 library and link it to static programs + @return None + """ + # First enable examples and static build + return_code, stdout, stderr = run_ns3("configure -G \"Unix Makefiles\" --enable-examples --disable-gtk --enable-static") + + # If configuration passes, we are half way done + self.assertEqual(return_code, 0) + + # Then try to build one example + return_code, stdout, stderr = run_ns3('build sample-simulator') + self.assertEqual(return_code, 0) + self.assertIn("Built target", stdout) + + # Maybe check the built binary for shared library references? Using objdump, otool, etc + NS3BuildBaseTestCase.cleaned_once = False + class NS3ExpectedUseTestCase(NS3BaseTestCase): """!