|
|
|
|
@@ -47,6 +47,40 @@ function(copy_headers_before_building_lib libname outputdir headers visibility)
|
|
|
|
|
endforeach()
|
|
|
|
|
endfunction(copy_headers_before_building_lib)
|
|
|
|
|
|
|
|
|
|
function(copy_headers)
|
|
|
|
|
# Argument parsing
|
|
|
|
|
set(options)
|
|
|
|
|
set(oneValueArgs PUBLIC_HEADER_OUTPUT_DIR DEPRECATED_HEADER_OUTPUT_DIR
|
|
|
|
|
PRIVATE_HEADER_OUTPUT_DIR
|
|
|
|
|
)
|
|
|
|
|
set(multiValueArgs PUBLIC_HEADER_FILES DEPRECATED_HEADER_FILES
|
|
|
|
|
PRIVATE_HEADER_FILES
|
|
|
|
|
)
|
|
|
|
|
cmake_parse_arguments(
|
|
|
|
|
"CP" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
|
|
|
|
|
)
|
|
|
|
|
if((DEFINED CP_PUBLIC_HEADER_OUTPUT_DIR) AND (DEFINED CP_PUBLIC_HEADER_FILES))
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
"" "${CP_PUBLIC_HEADER_OUTPUT_DIR}" "${CP_PUBLIC_HEADER_FILES}" public
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
if((DEFINED CP_DEPRECATED_HEADER_OUTPUT_DIR) AND (DEFINED
|
|
|
|
|
CP_DEPRECATED_HEADER_FILES)
|
|
|
|
|
)
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
"" "${CP_DEPRECATED_HEADER_OUTPUT_DIR}" "${CP_DEPRECATED_HEADER_FILES}"
|
|
|
|
|
deprecated
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
if((DEFINED CP_PRIVATE_HEADER_OUTPUT_DIR) AND (DEFINED CP_PRIVATE_HEADER_FILES
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
"" "${CP_PRIVATE_HEADER_OUTPUT_DIR}" "${CP_PRIVATE_HEADER_FILES}" private
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(remove_lib_prefix prefixed_library library)
|
|
|
|
|
# Check if there is a lib prefix
|
|
|
|
|
string(FIND "${prefixed_library}" "lib" lib_pos)
|
|
|
|
|
@@ -138,60 +172,27 @@ function(build_lib)
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT ${XCODE})
|
|
|
|
|
# Create object library with sources and headers, that will be used in
|
|
|
|
|
# lib-ns3-static and the shared library
|
|
|
|
|
add_library(
|
|
|
|
|
${BLIB_LIBNAME}-obj OBJECT "${BLIB_SOURCE_FILES}" "${BLIB_HEADER_FILES}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BLIB_IGNORE_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(${BLIB_LIBNAME} SHARED $<TARGET_OBJECTS:${BLIB_LIBNAME}-obj>)
|
|
|
|
|
else()
|
|
|
|
|
# Xcode and CMake don't play well when using object libraries, so we have a
|
|
|
|
|
# specific path for that
|
|
|
|
|
# Create the module shared library
|
|
|
|
|
add_library(${BLIB_LIBNAME} SHARED "${BLIB_SOURCE_FILES}")
|
|
|
|
|
|
|
|
|
|
# Set alias
|
|
|
|
|
add_library(ns3::${BLIB_LIBNAME} ALIAS ${BLIB_LIBNAME})
|
|
|
|
|
|
|
|
|
|
# Reuse PCH
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BLIB_IGNORE_PCH}))
|
|
|
|
|
target_precompile_headers(${BLIB_LIBNAME} REUSE_FROM stdlib_pch)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
add_library(ns3::${BLIB_LIBNAME} ALIAS ${BLIB_LIBNAME})
|
|
|
|
|
|
|
|
|
|
# Associate public headers with library for installation purposes
|
|
|
|
|
set(config_headers)
|
|
|
|
|
if("${BLIB_LIBNAME}" STREQUAL "core")
|
|
|
|
|
set(config_headers ${CMAKE_HEADER_OUTPUT_DIRECTORY}/config-store-config.h
|
|
|
|
|
${CMAKE_HEADER_OUTPUT_DIRECTORY}/core-config.h
|
|
|
|
|
)
|
|
|
|
|
if(${ENABLE_BUILD_VERSION})
|
|
|
|
|
list(APPEND config_headers
|
|
|
|
|
${CMAKE_HEADER_OUTPUT_DIRECTORY}/version-defines.h
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Enable examples as tests suites
|
|
|
|
|
if(${ENABLE_EXAMPLES} AND ${ENABLE_TESTS})
|
|
|
|
|
if(NOT ${XCODE})
|
|
|
|
|
target_compile_definitions(
|
|
|
|
|
${BLIB_LIBNAME}-obj PRIVATE NS3_ENABLE_EXAMPLES
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
target_compile_definitions(${BLIB_LIBNAME} PRIVATE NS3_ENABLE_EXAMPLES)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Associate public headers with library for installation purposes
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${BLIB_LIBNAME}
|
|
|
|
|
PROPERTIES
|
|
|
|
|
PUBLIC_HEADER
|
|
|
|
|
"${BLIB_HEADER_FILES};${BLIB_DEPRECATED_HEADER_FILES};${config_headers};${CMAKE_HEADER_OUTPUT_DIRECTORY}/${BLIB_LIBNAME}-module.h"
|
|
|
|
|
"${BLIB_HEADER_FILES};${BLIB_DEPRECATED_HEADER_FILES};${CMAKE_HEADER_OUTPUT_DIRECTORY}/${BLIB_LIBNAME}-module.h"
|
|
|
|
|
PRIVATE_HEADER "${BLIB_PRIVATE_HEADER_FILES}"
|
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} # set output
|
|
|
|
|
# directory for
|
|
|
|
|
@@ -202,35 +203,72 @@ function(build_lib)
|
|
|
|
|
add_dependencies(timeTraceReport ${BLIB_LIBNAME})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Split ns and non-ns libraries to manage their propagation properly
|
|
|
|
|
set(non_ns_libraries_to_link ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
|
|
|
|
|
|
set(ns_libraries_to_link)
|
|
|
|
|
|
|
|
|
|
foreach(library ${BLIB_LIBRARIES_TO_LINK})
|
|
|
|
|
remove_lib_prefix("${library}" module_name)
|
|
|
|
|
|
|
|
|
|
# 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}${CMAKE_SHARED_LIBRARY_SUFFIX}
|
|
|
|
|
build_lib_reexport_third_party_libraries(
|
|
|
|
|
"${BLIB_LIBNAME}" "${BLIB_LIBRARIES_TO_LINK}"
|
|
|
|
|
)
|
|
|
|
|
continue()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Check if the module exists in the ns-3 modules list or if it is a
|
|
|
|
|
# 3rd-party library
|
|
|
|
|
if(${module_name} IN_LIST ns3-all-enabled-modules)
|
|
|
|
|
list(APPEND ns_libraries_to_link ${library})
|
|
|
|
|
else()
|
|
|
|
|
list(APPEND non_ns_libraries_to_link ${library})
|
|
|
|
|
# set output name of library
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${BLIB_LIBNAME}
|
|
|
|
|
PROPERTIES OUTPUT_NAME ns${NS3_VER}-${BLIB_LIBNAME}${build_profile_suffix}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Export compile definitions as interface definitions, propagating local
|
|
|
|
|
# definitions to other modules and scratches
|
|
|
|
|
build_lib_export_definitions_as_interface_definitions(${BLIB_LIBNAME})
|
|
|
|
|
|
|
|
|
|
# Write a module header that includes all headers from that module
|
|
|
|
|
write_module_header("${BLIB_LIBNAME}" "${BLIB_HEADER_FILES}")
|
|
|
|
|
|
|
|
|
|
# Check if headers actually exist to prevent copying errors during
|
|
|
|
|
# installation (includes the module header created above)
|
|
|
|
|
build_lib_check_headers(${BLIB_LIBNAME})
|
|
|
|
|
|
|
|
|
|
# Copy all header files to outputfolder/include before each build
|
|
|
|
|
copy_headers(
|
|
|
|
|
PUBLIC_HEADER_OUTPUT_DIR ${CMAKE_HEADER_OUTPUT_DIRECTORY}
|
|
|
|
|
PUBLIC_HEADER_FILES ${BLIB_HEADER_FILES}
|
|
|
|
|
DEPRECATED_HEADER_OUTPUT_DIR ${CMAKE_HEADER_OUTPUT_DIRECTORY}
|
|
|
|
|
DEPRECATED_HEADER_FILES ${BLIB_DEPRECATED_HEADER_FILES}
|
|
|
|
|
PRIVATE_HEADER_OUTPUT_DIR ${CMAKE_HEADER_OUTPUT_DIRECTORY}
|
|
|
|
|
PRIVATE_HEADER_FILES ${BLIB_PRIVATE_HEADER_FILES}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Scan for C++ and Python examples and return a list of C++ examples (which
|
|
|
|
|
# can be set as dependencies of examples-as-test test suites)
|
|
|
|
|
build_lib_scan_examples(module_examples)
|
|
|
|
|
|
|
|
|
|
# Build tests if requested
|
|
|
|
|
build_lib_tests(
|
|
|
|
|
"${BLIB_LIBNAME}" "${BLIB_IGNORE_PCH}" "${FOLDER}" "${BLIB_TEST_SOURCES}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Handle package export
|
|
|
|
|
install(
|
|
|
|
|
TARGETS ${BLIB_LIBNAME}
|
|
|
|
|
EXPORT ns3ExportTargets
|
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ns3"
|
|
|
|
|
PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ns3"
|
|
|
|
|
)
|
|
|
|
|
if(${NS3_VERBOSE})
|
|
|
|
|
message(STATUS "Processed ${FOLDER}")
|
|
|
|
|
endif()
|
|
|
|
|
unset(module_name)
|
|
|
|
|
endforeach()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(build_lib_reexport_third_party_libraries libname libraries_to_link)
|
|
|
|
|
# Separate ns-3 and non-ns-3 libraries to manage their propagation properly
|
|
|
|
|
separate_ns3_from_non_ns3_libs(
|
|
|
|
|
"${libname}" "${libraries_to_link}" ns_libraries_to_link
|
|
|
|
|
non_ns_libraries_to_link
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(ns3-external-libs "${non_ns_libraries_to_link};${ns3-external-libs}"
|
|
|
|
|
CACHE INTERNAL
|
|
|
|
|
"list of non-ns libraries to link to NS3_STATIC and NS3_MONOLIB"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(NOT ${NS3_REEXPORT_THIRD_PARTY_LIBRARIES})
|
|
|
|
|
# ns-3 libraries are linked publicly, to make sure other modules can find
|
|
|
|
|
@@ -257,7 +295,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(${BLIB_LIBNAME} exported_include_directories)
|
|
|
|
|
get_target_includes(${libname} exported_include_directories)
|
|
|
|
|
|
|
|
|
|
string(REPLACE "-I" "" exported_include_directories
|
|
|
|
|
"${exported_include_directories}"
|
|
|
|
|
@@ -286,34 +324,22 @@ function(build_lib)
|
|
|
|
|
"${exported_include_directories}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${BLIB_LIBNAME} ${exported_libraries} ${private_libraries}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(NOT ${XCODE})
|
|
|
|
|
target_link_libraries(${BLIB_LIBNAME}-obj PRIVATE ${ns_libraries_to_link})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# set output name of library
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${BLIB_LIBNAME}
|
|
|
|
|
PROPERTIES OUTPUT_NAME ns${NS3_VER}-${BLIB_LIBNAME}${build_profile_suffix}
|
|
|
|
|
)
|
|
|
|
|
# Set public and private headers linked to the module library
|
|
|
|
|
target_link_libraries(${libname} ${exported_libraries} ${private_libraries})
|
|
|
|
|
|
|
|
|
|
# export include directories used by this library so that it can be used by
|
|
|
|
|
# 3rd-party consumers of ns-3 using find_package(ns3) this will automatically
|
|
|
|
|
# add the build/include path to them, so that they can ns-3 headers with
|
|
|
|
|
# <ns3/something.h>
|
|
|
|
|
target_include_directories(
|
|
|
|
|
${BLIB_LIBNAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_OUTPUT_DIRECTORY}/include>
|
|
|
|
|
${libname} PUBLIC $<BUILD_INTERFACE:${CMAKE_OUTPUT_DIRECTORY}/include>
|
|
|
|
|
$<INSTALL_INTERFACE:include>
|
|
|
|
|
INTERFACE ${exported_include_directories}
|
|
|
|
|
)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# Export definitions as interface definitions, propagating local definitions
|
|
|
|
|
# to other modules and scratches
|
|
|
|
|
get_target_property(target_definitions ${BLIB_LIBNAME} COMPILE_DEFINITIONS)
|
|
|
|
|
function(build_lib_export_definitions_as_interface_definitions libname)
|
|
|
|
|
get_target_property(target_definitions ${libname} COMPILE_DEFINITIONS)
|
|
|
|
|
if(${target_definitions} STREQUAL "target_definitions-NOTFOUND")
|
|
|
|
|
set(target_definitions)
|
|
|
|
|
endif()
|
|
|
|
|
@@ -322,167 +348,9 @@ function(build_lib)
|
|
|
|
|
list(REMOVE_DUPLICATES exported_definitions)
|
|
|
|
|
list(REMOVE_ITEM exported_definitions "")
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${BLIB_LIBNAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS
|
|
|
|
|
${libname} PROPERTIES INTERFACE_COMPILE_DEFINITIONS
|
|
|
|
|
"${exported_definitions}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(ns3-external-libs "${non_ns_libraries_to_link};${ns3-external-libs}"
|
|
|
|
|
CACHE INTERNAL
|
|
|
|
|
"list of non-ns libraries to link to NS3_STATIC and NS3_MONOLIB"
|
|
|
|
|
)
|
|
|
|
|
if(${NS3_STATIC} OR ${NS3_MONOLIB})
|
|
|
|
|
set(lib-ns3-static-objs
|
|
|
|
|
"$<TARGET_OBJECTS:${BLIB_LIBNAME}-obj>;${lib-ns3-static-objs}"
|
|
|
|
|
CACHE
|
|
|
|
|
INTERNAL
|
|
|
|
|
"list of object files from module used by NS3_STATIC and NS3_MONOLIB"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Write a module header that includes all headers from that module
|
|
|
|
|
write_module_header("${BLIB_LIBNAME}" "${BLIB_HEADER_FILES}")
|
|
|
|
|
|
|
|
|
|
# Check if headers actually exist to prevent copying errors during
|
|
|
|
|
# installation
|
|
|
|
|
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})
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
list(APPEND missing_headers ${header})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
if(missing_headers)
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR "Missing header files for ${BLIB_LIBNAME}: ${missing_headers}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Copy all header files to outputfolder/include before each build
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
${BLIB_LIBNAME} ${CMAKE_HEADER_OUTPUT_DIRECTORY} "${BLIB_HEADER_FILES}"
|
|
|
|
|
public
|
|
|
|
|
)
|
|
|
|
|
if(BLIB_PRIVATE_HEADER_FILES)
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
${BLIB_LIBNAME} ${CMAKE_HEADER_OUTPUT_DIRECTORY}
|
|
|
|
|
"${BLIB_PRIVATE_HEADER_FILES}" private
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(BLIB_DEPRECATED_HEADER_FILES)
|
|
|
|
|
copy_headers_before_building_lib(
|
|
|
|
|
${BLIB_LIBNAME} ${CMAKE_HEADER_OUTPUT_DIRECTORY}
|
|
|
|
|
"${BLIB_DEPRECATED_HEADER_FILES}" deprecated
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Build lib examples if requested
|
|
|
|
|
set(examples_before ${ns3-execs-clean})
|
|
|
|
|
foreach(example_folder example;examples)
|
|
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${example_folder})
|
|
|
|
|
if(${ENABLE_EXAMPLES})
|
|
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${example_folder}/CMakeLists.txt)
|
|
|
|
|
add_subdirectory(${example_folder})
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
scan_python_examples(${CMAKE_CURRENT_SOURCE_DIR}/${example_folder})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(module_examples ${ns3-execs-clean})
|
|
|
|
|
|
|
|
|
|
# Filter only module examples
|
|
|
|
|
foreach(example ${examples_before})
|
|
|
|
|
list(REMOVE_ITEM module_examples ${example})
|
|
|
|
|
endforeach()
|
|
|
|
|
unset(examples_before)
|
|
|
|
|
|
|
|
|
|
# Check if the module tests should be built
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
if(NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(filtered_in OFF)
|
|
|
|
|
if(${BLIB_LIBNAME} IN_LIST NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Build tests if requested
|
|
|
|
|
if(${ENABLE_TESTS} AND ${filtered_in})
|
|
|
|
|
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} ${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
|
|
|
|
|
if(WIN32)
|
|
|
|
|
set(ns3-libs-tests
|
|
|
|
|
"$<TARGET_OBJECTS:${test${BLIB_LIBNAME}}>;${ns3-libs-tests}"
|
|
|
|
|
CACHE INTERNAL "list of test libraries"
|
|
|
|
|
)
|
|
|
|
|
add_library(${test${BLIB_LIBNAME}} OBJECT "${BLIB_TEST_SOURCES}")
|
|
|
|
|
else()
|
|
|
|
|
set(ns3-libs-tests "${test${BLIB_LIBNAME}};${ns3-libs-tests}"
|
|
|
|
|
CACHE INTERNAL "list of test libraries"
|
|
|
|
|
)
|
|
|
|
|
add_library(${test${BLIB_LIBNAME}} SHARED "${BLIB_TEST_SOURCES}")
|
|
|
|
|
|
|
|
|
|
# Link test library to the module library
|
|
|
|
|
if(${NS3_MONOLIB})
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${test${BLIB_LIBNAME}} ${LIB_AS_NEEDED_PRE} ${lib-ns3-monolib}
|
|
|
|
|
${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${test${BLIB_LIBNAME}} ${LIB_AS_NEEDED_PRE} ${BLIB_LIBNAME}
|
|
|
|
|
"${BLIB_LIBRARIES_TO_LINK}" ${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${test${BLIB_LIBNAME}}
|
|
|
|
|
PROPERTIES OUTPUT_NAME
|
|
|
|
|
ns${NS3_VER}-${BLIB_LIBNAME}-test${build_profile_suffix}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
target_compile_definitions(
|
|
|
|
|
${test${BLIB_LIBNAME}} PRIVATE NS_TEST_SOURCEDIR="${FOLDER}/test"
|
|
|
|
|
)
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BLIB_IGNORE_PCH}))
|
|
|
|
|
target_precompile_headers(${test${BLIB_LIBNAME}} REUSE_FROM stdlib_pch)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Add dependency between tests and examples used as tests
|
|
|
|
|
if(${ENABLE_EXAMPLES})
|
|
|
|
|
foreach(source_file ${BLIB_TEST_SOURCES})
|
|
|
|
|
file(READ ${source_file} source_file_contents)
|
|
|
|
|
foreach(example_as_test ${module_examples})
|
|
|
|
|
string(FIND "${source_file_contents}" "${example_as_test}"
|
|
|
|
|
is_sub_string
|
|
|
|
|
)
|
|
|
|
|
if(NOT (${is_sub_string} EQUAL -1))
|
|
|
|
|
add_dependencies(test-runner-examples-as-tests ${example_as_test})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Handle package export
|
|
|
|
|
install(
|
|
|
|
|
TARGETS ${BLIB_LIBNAME}
|
|
|
|
|
EXPORT ns3ExportTargets
|
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/
|
|
|
|
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ns3"
|
|
|
|
|
PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ns3"
|
|
|
|
|
)
|
|
|
|
|
if(${NS3_VERBOSE})
|
|
|
|
|
message(STATUS "Processed ${FOLDER}")
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
@@ -512,13 +380,7 @@ function(build_lib_example)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if a module example should be built
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
if(NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(filtered_in OFF)
|
|
|
|
|
if(${BLIB_LIBNAME} IN_LIST NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
build_lib_check_examples_and_tests_filtered_in(${BLIB_LIBNAME} filtered_in)
|
|
|
|
|
|
|
|
|
|
if((NOT missing_dependencies) AND ${filtered_in})
|
|
|
|
|
# Convert boolean into text to forward argument
|
|
|
|
|
@@ -542,6 +404,184 @@ function(build_lib_example)
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# Check if module examples and tests should be built or not
|
|
|
|
|
#
|
|
|
|
|
# Arguments: libname (e.g. core, wifi), filtered_in (return boolean)
|
|
|
|
|
function(build_lib_check_examples_and_tests_filtered_in libname filtered_in)
|
|
|
|
|
set(in ON)
|
|
|
|
|
if(NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(in OFF)
|
|
|
|
|
if(${libname} IN_LIST NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(in ON)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
set(${filtered_in} ${in} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# Separate the LIBRARIES_TO_LINK list into ns-3 modules and external libraries
|
|
|
|
|
#
|
|
|
|
|
# Arguments: libname (e.g. core, wifi), libraries_to_link (input list),
|
|
|
|
|
# ns_libraries_to_link and non_ns_libraries_to_link (output lists)
|
|
|
|
|
function(separate_ns3_from_non_ns3_libs libname libraries_to_link
|
|
|
|
|
ns_libraries_to_link non_ns_libraries_to_link
|
|
|
|
|
)
|
|
|
|
|
set(non_ns_libs ${CMAKE_THREAD_LIBS_INIT})
|
|
|
|
|
set(ns_libs)
|
|
|
|
|
foreach(library ${libraries_to_link})
|
|
|
|
|
remove_lib_prefix("${library}" module_name)
|
|
|
|
|
|
|
|
|
|
# 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 "${libname}")
|
|
|
|
|
list(APPEND non_ns_libs ${library}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
|
|
|
continue()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Check if the module exists in the ns-3 modules list or if it is a
|
|
|
|
|
# 3rd-party library
|
|
|
|
|
if(${module_name} IN_LIST ns3-all-enabled-modules)
|
|
|
|
|
list(APPEND ns_libs ${library})
|
|
|
|
|
else()
|
|
|
|
|
list(APPEND non_ns_libs ${library})
|
|
|
|
|
endif()
|
|
|
|
|
unset(module_name)
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${ns_libraries_to_link} ${ns_libs} PARENT_SCOPE)
|
|
|
|
|
set(${non_ns_libraries_to_link} ${non_ns_libs} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# This macro scans for C++ and Python examples for a given module and return a
|
|
|
|
|
# list of C++ examples
|
|
|
|
|
#
|
|
|
|
|
# Arguments: module_cpp_examples = return list of C++ examples
|
|
|
|
|
function(build_lib_scan_examples module_cpp_examples)
|
|
|
|
|
# Build lib examples if requested
|
|
|
|
|
set(examples_before ${ns3-execs-clean})
|
|
|
|
|
foreach(example_folder example;examples)
|
|
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${example_folder})
|
|
|
|
|
if(${ENABLE_EXAMPLES})
|
|
|
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${example_folder}/CMakeLists.txt)
|
|
|
|
|
add_subdirectory(${example_folder})
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
scan_python_examples(${CMAKE_CURRENT_SOURCE_DIR}/${example_folder})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(module_examples ${ns3-execs-clean})
|
|
|
|
|
|
|
|
|
|
# Return a list of module c++ examples (current examples - previous examples)
|
|
|
|
|
list(REMOVE_ITEM module_examples ${examples_before})
|
|
|
|
|
set(${module_cpp_examples} ${module_examples} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# This macro builds the test library for the module library
|
|
|
|
|
#
|
|
|
|
|
# Arguments: libname (e.g. core), ignore_pch (TRUE/FALSE), folder (src/contrib),
|
|
|
|
|
# sources (list of .cc's)
|
|
|
|
|
function(build_lib_tests libname ignore_pch folder test_sources)
|
|
|
|
|
if(${ENABLE_TESTS})
|
|
|
|
|
# Check if the module tests should be built
|
|
|
|
|
build_lib_check_examples_and_tests_filtered_in(${libname} filtered_in)
|
|
|
|
|
if(NOT ${filtered_in})
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
list(LENGTH test_sources test_source_len)
|
|
|
|
|
if(${test_source_len} GREATER 0)
|
|
|
|
|
# Create libname of output library test of module
|
|
|
|
|
set(test${libname} ${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
|
|
|
|
|
if(WIN32)
|
|
|
|
|
set(ns3-libs-tests
|
|
|
|
|
"$<TARGET_OBJECTS:${test${libname}}>;${ns3-libs-tests}"
|
|
|
|
|
CACHE INTERNAL "list of test libraries"
|
|
|
|
|
)
|
|
|
|
|
add_library(${test${libname}} OBJECT "${test_sources}")
|
|
|
|
|
else()
|
|
|
|
|
set(ns3-libs-tests "${test${libname}};${ns3-libs-tests}"
|
|
|
|
|
CACHE INTERNAL "list of test libraries"
|
|
|
|
|
)
|
|
|
|
|
add_library(${test${libname}} SHARED "${test_sources}")
|
|
|
|
|
|
|
|
|
|
# Link test library to the module library
|
|
|
|
|
if(${NS3_MONOLIB})
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${test${libname}} ${LIB_AS_NEEDED_PRE} ${lib-ns3-monolib}
|
|
|
|
|
${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${test${libname}} ${LIB_AS_NEEDED_PRE} ${libname}
|
|
|
|
|
"${BLIB_LIBRARIES_TO_LINK}" ${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
set_target_properties(
|
|
|
|
|
${test${libname}}
|
|
|
|
|
PROPERTIES OUTPUT_NAME
|
|
|
|
|
ns${NS3_VER}-${libname}-test${build_profile_suffix}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
target_compile_definitions(
|
|
|
|
|
${test${libname}} PRIVATE NS_TEST_SOURCEDIR="${folder}/test"
|
|
|
|
|
)
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${ignore_pch}))
|
|
|
|
|
target_precompile_headers(${test${libname}} REUSE_FROM stdlib_pch)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Add dependency between tests and examples used as tests
|
|
|
|
|
examples_as_tests_dependencies("${module_examples}" "${test_sources}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# This macro scans for C++ examples used by examples-as-tests suites
|
|
|
|
|
#
|
|
|
|
|
# Arguments: module_cpp_examples = list of C++ example executable names,
|
|
|
|
|
# module_test_sources = list of C++ sources with tests
|
|
|
|
|
function(examples_as_tests_dependencies module_cpp_examples module_test_sources)
|
|
|
|
|
if(${ENABLE_EXAMPLES})
|
|
|
|
|
foreach(source_file ${module_test_sources})
|
|
|
|
|
file(READ ${source_file} source_file_contents)
|
|
|
|
|
foreach(example_as_test ${module_cpp_examples})
|
|
|
|
|
string(FIND "${source_file_contents}" "${example_as_test}"
|
|
|
|
|
is_sub_string
|
|
|
|
|
)
|
|
|
|
|
if(NOT (${is_sub_string} EQUAL -1))
|
|
|
|
|
add_dependencies(test-runner-examples-as-tests ${example_as_test})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# This macro checks if all headers from a module actually exist or are missing
|
|
|
|
|
#
|
|
|
|
|
# Arguments: target_name = module name (e.g. core, wifi)
|
|
|
|
|
function(build_lib_check_headers target_name)
|
|
|
|
|
# Retrieve target properties containing the public (which include deprecated)
|
|
|
|
|
# and private headers
|
|
|
|
|
get_target_property(headers_to_check ${target_name} PUBLIC_HEADER)
|
|
|
|
|
get_target_property(headers_to_check2 ${target_name} PRIVATE_HEADER)
|
|
|
|
|
list(APPEND headers_to_check ${headers_to_check2})
|
|
|
|
|
set(missing_headers)
|
|
|
|
|
foreach(header ${headers_to_check})
|
|
|
|
|
if(NOT ((EXISTS ${header}) OR (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${header})
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
list(APPEND missing_headers ${header})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
if(missing_headers)
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR "Missing header files for ${target_name}: ${missing_headers}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
# This macro processes a ns-3 module header file (module_name-module.h)
|
|
|
|
|
#
|
|
|
|
|
# Arguments: name = module name (e.g. core, wifi) HEADER_FILES =
|
|
|
|
|
|