From 7193cce35b27ab2c9429952a9545d7cd40a622ee Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Fri, 3 Feb 2023 22:28:16 -0300 Subject: [PATCH] build: fetch dependencies for Brite, Click and Openflow Signed-off-by: Gabriel Ferreira --- CMakeLists.txt | 3 + ...-fetch-optional-modules-dependencies.cmake | 75 +++++++++++++++++++ build-support/macros-and-definitions.cmake | 7 ++ src/CMakeLists.txt | 4 + src/brite/CMakeLists.txt | 12 ++- src/click/CMakeLists.txt | 9 +++ src/openflow/CMakeLists.txt | 8 ++ 7 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4151a6d26..83d262056 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,9 @@ option(NS3_NETANIM "Build netanim" OFF) option(NS3_ENABLE_BUILD_VERSION "Embed version info into libraries" OFF) option(NS3_CCACHE "Use Ccache to speed up recompilation" ON) option(NS3_FAST_LINKERS "Use Mold or LLD to speed up linking if available" ON) +option(NS3_FETCH_OPTIONAL_COMPONENTS + "Fetch Brite, Click and Openflow dependencies" OFF +) option(NS3_GSL "Build with GSL support" ON) option(NS3_GTK3 "Build with GTK3 support" ON) option(NS3_LINK_TIME_OPTIMIZATION "Build with link-time optimization" OFF) diff --git a/build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake b/build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake new file mode 100644 index 000000000..90f774361 --- /dev/null +++ b/build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake @@ -0,0 +1,75 @@ +include(ExternalProject) + +ExternalProject_Add( + brite_dep + URL https://code.nsnam.org/BRITE/archive/30338f4f63b9.zip + URL_HASH MD5=b36ecf8f6b5f2cfae936ba1f1bfcff5c + PREFIX brite_dep + BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND make + BUILD_COMMAND make + INSTALL_COMMAND make install PREFIX=${CMAKE_OUTPUT_DIRECTORY} +) + +ExternalProject_Add( + click_dep + GIT_REPOSITORY https://github.com/kohler/click.git + GIT_TAG 9197a594b1c314264935106297aff08d97cbe7ee + PREFIX click_dep + BUILD_IN_SOURCE TRUE + UPDATE_DISCONNECTED TRUE + CONFIGURE_COMMAND ./configure --disable-linuxmodule --enable-nsclick + --enable-wifi --prefix ${CMAKE_OUTPUT_DIRECTORY} + BUILD_COMMAND make -j${NumThreads} + INSTALL_COMMAND make install +) + +ExternalProject_Add( + openflow_dep + URL https://code.nsnam.org/openflow/archive/d45e7d184151.zip + URL_HASH MD5=a068cdaec5523586921b2f1f81f10916 + PREFIX openflow_dep + BUILD_IN_SOURCE TRUE + CONFIGURE_COMMAND ./waf configure --prefix ${CMAKE_OUTPUT_DIRECTORY} + BUILD_COMMAND ./waf build + INSTALL_COMMAND ./waf install +) + +install( + DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/include/openflow + DESTINATION ${CMAKE_INSTALL_PREFIX}/include + USE_SOURCE_PERMISSIONS + PATTERN "openflow/*" +) + +find_file( + BOOST_STATIC_ASSERT + NAMES static_assert.hpp + PATH_SUFFIXES boost + HINTS /usr/local +) +get_filename_component(boost_dir ${BOOST_STATIC_ASSERT} DIRECTORY) + +install( + DIRECTORY ${boost_dir} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + USE_SOURCE_PERMISSIONS + PATTERN "boost/*" +) +install( + DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/lib/ + DESTINATION ${CMAKE_INSTALL_LIBDIR} + USE_SOURCE_PERMISSIONS + PATTERN "lib/*" +) + +macro(add_dependency_to_optional_modules_dependencies) + add_dependencies(${libbrite} brite_dep) + add_dependencies(${libclick} click_dep) + add_dependencies(${libopenflow} openflow_dep) + if(NOT ${XCODE}) + add_dependencies(${libbrite}-obj brite_dep) + add_dependencies(${libclick}-obj click_dep) + add_dependencies(${libopenflow}-obj openflow_dep) + endif() +endmacro() diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 0d78da280..37e5621a3 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -141,6 +141,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}) set(CMAKE_HEADER_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/include/ns3) set(THIRD_PARTY_DIRECTORY ${PROJECT_SOURCE_DIR}/3rd-party) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +link_directories(${CMAKE_OUTPUT_DIRECTORY}/lib) # Get installation folder default values for each platform and include package # configuration macro @@ -1471,6 +1472,12 @@ macro(process_options) ) add_subdirectory(${netanim_SOURCE_DIR} ${netanim_BINARY_DIR}) endif() + + if(${NS3_FETCH_OPTIONAL_COMPONENTS}) + include( + build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake + ) + endif() endmacro() function(set_runtime_outputdirectory target_name output_directory target_prefix) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fc571b937..f2d041ee4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -87,3 +87,7 @@ if(${NS3_MONOLIB}) add_dependencies(timeTraceReport ${lib-ns3-monolib}) endif() endif() + +if(${NS3_FETCH_OPTIONAL_COMPONENTS}) + add_dependency_to_optional_modules_dependencies() +endif() diff --git a/src/brite/CMakeLists.txt b/src/brite/CMakeLists.txt index 8ca0d591b..99c7be210 100644 --- a/src/brite/CMakeLists.txt +++ b/src/brite/CMakeLists.txt @@ -18,8 +18,10 @@ find_external_library( if((NOT brite_FOUND) - OR (NOT - ${brite_FOUND}) + AND (NOT + ${brite_FOUND}) + AND (NOT + ${NS3_FETCH_OPTIONAL_COMPONENTS}) ) message( ${HIGHLIGHTED_STATUS} @@ -28,6 +30,12 @@ if((NOT return() endif() +if(${NS3_FETCH_OPTIONAL_COMPONENTS}) + set(brite_LIBRARIES + brite + ) +endif() + # Only process module if include folder and library have been found include_directories(${brite_INCLUDE_DIRS}) set(NS3_BRITE diff --git a/src/click/CMakeLists.txt b/src/click/CMakeLists.txt index bc81f650c..72cd22495 100644 --- a/src/click/CMakeLists.txt +++ b/src/click/CMakeLists.txt @@ -23,6 +23,8 @@ if((NOT click_FOUND) AND (NOT ${click_FOUND}) + AND (NOT + ${NS3_FETCH_OPTIONAL_COMPONENTS}) ) message( ${HIGHLIGHTED_STATUS} @@ -31,6 +33,13 @@ if((NOT return() endif() +if(${NS3_FETCH_OPTIONAL_COMPONENTS}) + set(click_LIBRARIES + click + nsclick + ) +endif() + include_directories(${click_INCLUDE_DIRS}) set(NS3_CLICK "ON" diff --git a/src/openflow/CMakeLists.txt b/src/openflow/CMakeLists.txt index 0a2c8c2c9..a6048c2ef 100644 --- a/src/openflow/CMakeLists.txt +++ b/src/openflow/CMakeLists.txt @@ -20,6 +20,8 @@ if((NOT openflow_FOUND) AND (NOT ${openflow_FOUND}) + AND (NOT + ${NS3_FETCH_OPTIONAL_COMPONENTS}) ) message( ${HIGHLIGHTED_STATUS} @@ -28,6 +30,12 @@ if((NOT return() endif() +if(${NS3_FETCH_OPTIONAL_COMPONENTS}) + set(openflow_LIBRARIES + openflow + ) +endif() + check_include_file_cxx( boost/static_assert.hpp BOOST_STATIC_ASSERT