2021-11-10 22:28:44 -03:00
|
|
|
# Copyright (c) 2017-2021 Universidade de Brasília
|
|
|
|
|
#
|
2021-12-05 21:53:49 +00:00
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
|
# the terms of the GNU General Public License version 2 as published by the Free
|
|
|
|
|
# Software Foundation;
|
2021-11-10 22:28:44 -03:00
|
|
|
#
|
2021-12-05 21:53:49 +00:00
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
|
# details.
|
2021-11-10 22:28:44 -03:00
|
|
|
#
|
2021-12-05 21:53:49 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
|
# Place, Suite 330, Boston, MA 02111-1307 USA
|
2021-11-10 22:28:44 -03:00
|
|
|
#
|
|
|
|
|
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
|
|
|
|
|
|
|
|
|
|
# Export compile time variable setting the directory to the NS3 root folder
|
|
|
|
|
add_definitions(-DPROJECT_SOURCE_PATH="${PROJECT_SOURCE_DIR}")
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
# Set INT128 as the default option for INT64X64 and register alternative
|
|
|
|
|
# implementations
|
2021-12-10 02:13:43 +00:00
|
|
|
set(NS3_INT64X64 "INT128" CACHE STRING "Int64x64 implementation")
|
|
|
|
|
set_property(CACHE NS3_INT64X64 PROPERTY STRINGS INT128 CAIRO DOUBLE)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2022-01-26 11:51:50 -03:00
|
|
|
# Purposefully hidden options:
|
|
|
|
|
|
|
|
|
|
# for ease of use, export all libraries and include directories to ns-3 module
|
|
|
|
|
# consumers by default
|
|
|
|
|
option(NS3_REEXPORT_THIRD_PARTY_LIBRARIES "Export all third-party libraries
|
|
|
|
|
and include directories to ns-3 module consumers" ON
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# since we can't really do that safely from the CMake side
|
2022-01-08 23:09:57 -03:00
|
|
|
option(NS3_ENABLE_SUDO
|
|
|
|
|
"Set executables ownership to root and enable the SUID flag" OFF
|
|
|
|
|
)
|
|
|
|
|
|
2022-03-19 12:57:05 -03:00
|
|
|
# Replace default CMake messages (logging) with custom colored messages as early
|
|
|
|
|
# as possible
|
|
|
|
|
include(${PROJECT_SOURCE_DIR}/build-support/3rd-party/colored-messages.cmake)
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# WSLv1 doesn't support tap features
|
|
|
|
|
if(EXISTS "/proc/version")
|
|
|
|
|
file(READ "/proc/version" CMAKE_LINUX_DISTRO)
|
2022-09-01 18:42:39 -03:00
|
|
|
string(FIND "${CMAKE_LINUX_DISTRO}" "Microsoft" res)
|
2021-11-10 22:28:44 -03:00
|
|
|
if(res EQUAL -1)
|
|
|
|
|
set(WSLv1 False)
|
|
|
|
|
else()
|
|
|
|
|
set(WSLv1 True)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Set Linux flag if on Linux
|
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
|
set(LINUX TRUE)
|
|
|
|
|
add_definitions(-D__LINUX__)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
|
add_definitions(-D__APPLE__)
|
2022-11-24 10:52:39 -03:00
|
|
|
# cmake-format: off
|
|
|
|
|
# Configure find_program to search for AppBundles only if programs are not found in PATH.
|
|
|
|
|
# This prevents Doxywizard from being launched when the Doxygen.app is installed.
|
|
|
|
|
# https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindDoxygen.cmake
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
set(CMAKE_FIND_APPBUNDLE "LAST")
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-09-20 16:00:03 -03:00
|
|
|
if(WIN32)
|
|
|
|
|
set(NS3_PRECOMPILE_HEADERS OFF
|
|
|
|
|
CACHE BOOL "Precompile module headers to speed up compilation" FORCE
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
set(cat_command cat)
|
|
|
|
|
|
|
|
|
|
if(CMAKE_XCODE_BUILD_SYSTEM)
|
|
|
|
|
set(XCODE True)
|
|
|
|
|
else()
|
|
|
|
|
set(XCODE False)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Check the number of threads
|
|
|
|
|
include(ProcessorCount)
|
|
|
|
|
ProcessorCount(NumThreads)
|
|
|
|
|
|
|
|
|
|
# Output folders
|
2021-12-05 21:53:49 +00:00
|
|
|
if("${NS3_OUTPUT_DIRECTORY}" STREQUAL "")
|
|
|
|
|
message(STATUS "Using default output directory ${PROJECT_SOURCE_DIR}/build")
|
|
|
|
|
set(CMAKE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build) # default output
|
|
|
|
|
# folder
|
|
|
|
|
else()
|
2021-12-10 02:13:43 +00:00
|
|
|
# Check if NS3_OUTPUT_DIRECTORY is a relative path
|
|
|
|
|
set(absolute_ns3_output_directory "${NS3_OUTPUT_DIRECTORY}")
|
|
|
|
|
if(NOT IS_ABSOLUTE ${NS3_OUTPUT_DIRECTORY})
|
|
|
|
|
set(absolute_ns3_output_directory
|
|
|
|
|
"${PROJECT_SOURCE_DIR}/${NS3_OUTPUT_DIRECTORY}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-09-20 16:00:03 -03:00
|
|
|
|
|
|
|
|
# Transform backward slash into forward slash Not the best way to do it since
|
|
|
|
|
# \ is a scape thing and can be used before whitespaces
|
|
|
|
|
string(REPLACE "\\" "/" absolute_ns3_output_directory
|
|
|
|
|
"${absolute_ns3_output_directory}"
|
|
|
|
|
)
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
if(NOT (EXISTS ${absolute_ns3_output_directory}))
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
STATUS
|
|
|
|
|
"User-defined output directory \"${NS3_OUTPUT_DIRECTORY}\" doesn't exist. Trying to create it"
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
file(MAKE_DIRECTORY ${absolute_ns3_output_directory})
|
|
|
|
|
if(NOT (EXISTS ${absolute_ns3_output_directory}))
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
2021-12-10 02:13:43 +00:00
|
|
|
"User-defined output directory \"${absolute_ns3_output_directory}\" could not be created. "
|
2021-12-05 21:53:49 +00:00
|
|
|
"Try changing the value of NS3_OUTPUT_DIRECTORY"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# If this directory is not inside the ns-3-dev folder, alert users tests may
|
|
|
|
|
# break
|
2021-12-10 02:13:43 +00:00
|
|
|
if(NOT ("${absolute_ns3_output_directory}" MATCHES "${PROJECT_SOURCE_DIR}"))
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
WARNING
|
2021-12-10 02:13:43 +00:00
|
|
|
"User-defined output directory \"${absolute_ns3_output_directory}\" is outside "
|
2021-12-05 21:53:49 +00:00
|
|
|
" of the ns-3 directory ${PROJECT_SOURCE_DIR}, which will break some tests"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
message(
|
|
|
|
|
STATUS
|
2021-12-10 02:13:43 +00:00
|
|
|
"User-defined output directory \"${absolute_ns3_output_directory}\" will be used"
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(CMAKE_OUTPUT_DIRECTORY ${absolute_ns3_output_directory})
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/lib)
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/lib)
|
|
|
|
|
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)
|
2022-01-31 13:55:48 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2023-02-03 22:28:16 -03:00
|
|
|
link_directories(${CMAKE_OUTPUT_DIRECTORY}/lib)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Get installation folder default values for each platform and include package
|
|
|
|
|
# configuration macro
|
2021-11-10 22:28:44 -03:00
|
|
|
include(GNUInstallDirs)
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-cmake-package.cmake)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
if(${XCODE})
|
2021-12-05 21:53:49 +00:00
|
|
|
# Is that so hard not to break people's CI, AAPL? Why would you output the
|
|
|
|
|
# targets to a Debug/Release subfolder? Why?
|
2021-11-10 22:28:44 -03:00
|
|
|
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
|
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
|
2021-12-05 21:53:49 +00:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
|
|
|
|
|
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
|
|
|
|
|
)
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
|
|
|
|
|
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
|
|
|
|
|
)
|
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG}
|
|
|
|
|
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# fPIC (position-independent code) and fPIE (position-independent executable)
|
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
|
2021-12-10 21:08:23 -03:00
|
|
|
# do not create a file-level dependency with shared libraries reducing
|
|
|
|
|
# unnecessary relinking
|
|
|
|
|
set(CMAKE_LINK_DEPENDS_NO_SHARED TRUE)
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
# Identify compiler and check version
|
|
|
|
|
set(below_minimum_msg "compiler is below the minimum required version")
|
2021-11-10 22:28:44 -03:00
|
|
|
set(CLANG FALSE)
|
2021-12-10 02:13:43 +00:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")
|
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${AppleClang_MinVersion})
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Apple Clang ${CMAKE_CXX_COMPILER_VERSION} ${below_minimum_msg} ${AppleClang_MinVersion}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
set(CLANG TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if((NOT CLANG) AND ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
|
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${Clang_MinVersion})
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Clang ${CMAKE_CXX_COMPILER_VERSION} ${below_minimum_msg} ${Clang_MinVersion}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
set(CLANG TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-03-19 12:57:05 -03:00
|
|
|
if(CLANG)
|
|
|
|
|
if(${NS3_COLORED_OUTPUT} OR "$ENV{CLICOLOR}")
|
|
|
|
|
add_definitions(-fcolor-diagnostics) # colorize clang++ output
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
set(GCC FALSE)
|
2023-04-15 11:48:06 -03:00
|
|
|
set(GCC8 FALSE)
|
2021-11-10 22:28:44 -03:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
2021-12-10 02:13:43 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${GNU_MinVersion})
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"GNU ${CMAKE_CXX_COMPILER_VERSION} ${below_minimum_msg} ${GNU_MinVersion}"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2023-04-15 11:48:06 -03:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0")
|
|
|
|
|
# This block is used to identify if GCC8 is being used. In this case, we
|
|
|
|
|
# want to explicitly link stdc++fs, which is done in
|
|
|
|
|
# ns3-module-macros.cmake.
|
|
|
|
|
set(GCC8 TRUE)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
set(GCC TRUE)
|
2021-11-15 01:03:54 -03:00
|
|
|
add_definitions(-fno-semantic-interposition)
|
2022-03-19 12:57:05 -03:00
|
|
|
if(${NS3_COLORED_OUTPUT} OR "$ENV{CLICOLOR}")
|
|
|
|
|
add_definitions(-fdiagnostics-color=always) # colorize g++ output
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2021-12-10 02:13:43 +00:00
|
|
|
unset(below_minimum_msg)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Set compiler options and get command to force unused function linkage (useful
|
|
|
|
|
# for libraries)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(CXX_UNSUPPORTED_STANDARDS 98 11 14)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_MINIMUM 17)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2023-04-07 21:31:38 -03:00
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(LIB_AS_NEEDED_PRE)
|
|
|
|
|
set(LIB_AS_NEEDED_POST)
|
2022-09-05 02:19:30 +00:00
|
|
|
set(STATIC_LINK_FLAGS -static -static-libstdc++ -static-libgcc)
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${GCC} AND NOT APPLE)
|
|
|
|
|
# using GCC
|
|
|
|
|
set(LIB_AS_NEEDED_PRE -Wl,--no-as-needed)
|
|
|
|
|
set(LIB_AS_NEEDED_POST -Wl,--as-needed)
|
|
|
|
|
set(LIB_AS_NEEDED_PRE_STATIC -Wl,--whole-archive,-Bstatic)
|
|
|
|
|
set(LIB_AS_NEEDED_POST_STATIC -Wl,--no-whole-archive)
|
|
|
|
|
set(LIB_AS_NEEDED_POST_STATIC_DYN -Wl,-Bdynamic,--no-whole-archive)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${CLANG} AND APPLE)
|
|
|
|
|
# using Clang set(LIB_AS_NEEDED_PRE -all_load)
|
|
|
|
|
set(LIB_AS_NEEDED_POST)
|
2022-09-05 02:19:30 +00:00
|
|
|
set(LIB_AS_NEEDED_PRE_STATIC -Wl,-all_load)
|
|
|
|
|
set(STATIC_LINK_FLAGS)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-11-30 12:35:51 -03:00
|
|
|
if(${NS3_FAST_LINKERS})
|
|
|
|
|
# Search for faster linkers mold and lld, and use them if available
|
|
|
|
|
mark_as_advanced(MOLD LLD)
|
|
|
|
|
find_program(MOLD mold)
|
|
|
|
|
find_program(LLD ld.lld)
|
|
|
|
|
|
|
|
|
|
# USING_FAST_LINKER will be defined if a fast linker is being used and its
|
|
|
|
|
# content will correspond to the fast linker name
|
|
|
|
|
|
|
|
|
|
# Mold support was added in GCC 12.1.0
|
|
|
|
|
if(NOT USING_FAST_LINKER
|
|
|
|
|
AND NOT (${MOLD} STREQUAL "MOLD-NOTFOUND")
|
|
|
|
|
AND LINUX
|
|
|
|
|
AND ${GCC}
|
|
|
|
|
AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1.0)
|
|
|
|
|
)
|
|
|
|
|
set(USING_FAST_LINKER MOLD)
|
|
|
|
|
add_link_options("-fuse-ld=mold")
|
|
|
|
|
endif()
|
2022-09-20 17:08:57 -03:00
|
|
|
|
2022-11-30 12:35:51 -03:00
|
|
|
if(NOT USING_FAST_LINKER AND NOT (${LLD} STREQUAL "LLD-NOTFOUND")
|
|
|
|
|
AND (${GCC} OR ${CLANG})
|
|
|
|
|
)
|
|
|
|
|
set(USING_FAST_LINKER LLD)
|
|
|
|
|
add_link_options("-fuse-ld=lld")
|
|
|
|
|
if(WIN32)
|
|
|
|
|
# Clear unsupported linker flags on Windows
|
|
|
|
|
set(LIB_AS_NEEDED_PRE)
|
|
|
|
|
endif()
|
2022-09-20 17:08:57 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-11 12:18:33 -03:00
|
|
|
# Include CMake files used for compiler checks
|
|
|
|
|
include(CheckIncludeFile) # Used to check a single C header at a time
|
|
|
|
|
include(CheckIncludeFileCXX) # Used to check a single C++ header at a time
|
|
|
|
|
include(CheckIncludeFiles) # Used to check multiple headers at once
|
|
|
|
|
include(CheckFunctionExists)
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
macro(SUBDIRLIST result curdir)
|
|
|
|
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
|
|
|
|
set(dirlist "")
|
|
|
|
|
foreach(child ${children})
|
|
|
|
|
if(IS_DIRECTORY ${curdir}/${child})
|
|
|
|
|
list(APPEND dirlist ${child})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${result} ${dirlist})
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
macro(library_target_name libname targetname)
|
|
|
|
|
set(${targetname} lib${libname})
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
macro(clear_global_cached_variables)
|
|
|
|
|
# clear cache variables
|
|
|
|
|
unset(build_profile CACHE)
|
|
|
|
|
unset(build_profile_suffix CACHE)
|
|
|
|
|
unset(lib-ns3-static-objs CACHE)
|
|
|
|
|
unset(ns3-contrib-libs CACHE)
|
|
|
|
|
unset(ns3-example-folders CACHE)
|
|
|
|
|
unset(ns3-execs CACHE)
|
2022-10-25 10:19:01 -03:00
|
|
|
unset(ns3-execs-clean CACHE)
|
2022-01-26 01:53:28 -03:00
|
|
|
unset(ns3-execs-py CACHE)
|
2021-11-10 22:28:44 -03:00
|
|
|
unset(ns3-external-libs CACHE)
|
2022-01-26 01:53:28 -03:00
|
|
|
unset(ns3-headers-to-module-map CACHE)
|
2021-11-10 22:28:44 -03:00
|
|
|
unset(ns3-libs CACHE)
|
|
|
|
|
unset(ns3-libs-tests CACHE)
|
|
|
|
|
unset(ns3-python-bindings-modules CACHE)
|
2021-12-05 21:53:49 +00:00
|
|
|
mark_as_advanced(
|
|
|
|
|
build_profile
|
|
|
|
|
build_profile_suffix
|
|
|
|
|
lib-ns3-static-objs
|
|
|
|
|
ns3-contrib-libs
|
|
|
|
|
ns3-example-folders
|
|
|
|
|
ns3-execs
|
2022-10-25 10:19:01 -03:00
|
|
|
ns3-execs-clean
|
2022-01-26 01:53:28 -03:00
|
|
|
ns3-execs-py
|
2021-12-05 21:53:49 +00:00
|
|
|
ns3-external-libs
|
2022-01-26 01:53:28 -03:00
|
|
|
ns3-headers-to-module-map
|
2021-12-05 21:53:49 +00:00
|
|
|
ns3-libs
|
|
|
|
|
ns3-libs-tests
|
|
|
|
|
ns3-python-bindings-modules
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endmacro()
|
|
|
|
|
|
2022-11-24 10:52:39 -03:00
|
|
|
# Include CMake file with common find_program HINTS
|
|
|
|
|
include(build-support/3rd-party/find-program-hints.cmake)
|
|
|
|
|
|
2022-01-08 23:09:57 -03:00
|
|
|
# function used to search for package and program dependencies than store list
|
|
|
|
|
# of missing dependencies in the list whose name is stored in missing_deps
|
|
|
|
|
function(check_deps package_deps program_deps missing_deps)
|
|
|
|
|
set(local_missing_deps)
|
|
|
|
|
# Search for package dependencies
|
|
|
|
|
foreach(package ${package_deps})
|
|
|
|
|
find_package(${package})
|
|
|
|
|
if(NOT ${${package}_FOUND})
|
|
|
|
|
list(APPEND local_missing_deps ${package})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# And for program dependencies
|
|
|
|
|
foreach(program ${program_deps})
|
|
|
|
|
# CMake likes to cache find_* to speed things up, so we can't reuse names
|
|
|
|
|
# here or it won't check other dependencies
|
|
|
|
|
string(TOUPPER ${program} upper_${program})
|
2022-01-23 17:30:08 -03:00
|
|
|
mark_as_advanced(${upper_${program}})
|
2022-11-24 10:52:39 -03:00
|
|
|
find_program(
|
|
|
|
|
${upper_${program}} ${program} HINTS ${3RD_PARTY_FIND_PROGRAM_HINTS}
|
|
|
|
|
)
|
2022-04-03 23:56:07 -03:00
|
|
|
if("${${upper_${program}}}" STREQUAL "${upper_${program}}-NOTFOUND")
|
2022-01-08 23:09:57 -03:00
|
|
|
list(APPEND local_missing_deps ${program})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Store list of missing dependencies in the parent scope
|
|
|
|
|
set(${missing_deps} ${local_missing_deps} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# process all options passed in main cmakeLists
|
|
|
|
|
macro(process_options)
|
|
|
|
|
clear_global_cached_variables()
|
|
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
# make sure to default to RelWithDebInfo if no build type is specified
|
2021-12-10 00:16:05 -03:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2022-03-02 11:51:53 -03:00
|
|
|
set(CMAKE_BUILD_TYPE "default" CACHE STRING "Choose the type of build."
|
|
|
|
|
FORCE
|
|
|
|
|
)
|
|
|
|
|
set(NS3_ASSERT ON CACHE BOOL "Enable assert on failure" FORCE)
|
|
|
|
|
set(NS3_LOG ON CACHE BOOL "Enable logging to be built" FORCE)
|
|
|
|
|
set(NS3_WARNINGS_AS_ERRORS OFF
|
|
|
|
|
CACHE BOOL "Treat warnings as errors. Requires NS3_WARNINGS=ON" FORCE
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# process debug switch Used in build-profile-test-suite
|
|
|
|
|
string(TOLOWER ${CMAKE_BUILD_TYPE} cmakeBuildType)
|
|
|
|
|
set(build_profile "${cmakeBuildType}" CACHE INTERNAL "")
|
|
|
|
|
if(${cmakeBuildType} STREQUAL "debug")
|
2022-03-02 11:51:53 -03:00
|
|
|
add_definitions(-DNS3_BUILD_PROFILE_DEBUG)
|
|
|
|
|
elseif(${cmakeBuildType} STREQUAL "relwithdebinfo" OR ${cmakeBuildType}
|
|
|
|
|
STREQUAL "default"
|
|
|
|
|
)
|
|
|
|
|
set(cmakeBuildType relwithdebinfo)
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEFAULT ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
|
2021-11-10 22:28:44 -03:00
|
|
|
add_definitions(-DNS3_BUILD_PROFILE_DEBUG)
|
|
|
|
|
elseif(${cmakeBuildType} STREQUAL "release")
|
|
|
|
|
if(${NS3_NATIVE_OPTIMIZATIONS})
|
2022-03-02 11:51:53 -03:00
|
|
|
add_definitions(-DNS3_BUILD_PROFILE_OPTIMIZED)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(build_profile "optimized" CACHE INTERNAL "")
|
2022-03-02 11:51:53 -03:00
|
|
|
else()
|
|
|
|
|
add_definitions(-DNS3_BUILD_PROFILE_RELEASE)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
else()
|
2022-03-02 11:51:53 -03:00
|
|
|
add_definitions(-DNS3_BUILD_PROFILE_RELEASE)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Enable examples if activated via command line (NS3_EXAMPLES) or ns3rc config
|
|
|
|
|
# file
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_EXAMPLES OFF)
|
2021-12-05 21:53:49 +00:00
|
|
|
if(${NS3_EXAMPLES} OR ${ns3rc_examples_enabled})
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_EXAMPLES ON)
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Enable examples if activated via command line (NS3_TESTS) or ns3rc config
|
|
|
|
|
# file
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_TESTS OFF)
|
2021-12-05 21:53:49 +00:00
|
|
|
if(${NS3_TESTS} OR ${ns3rc_tests_enabled})
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_TESTS ON)
|
2022-01-31 20:02:10 -03:00
|
|
|
enable_testing()
|
2023-04-01 17:02:06 -03:00
|
|
|
else()
|
|
|
|
|
list(REMOVE_ITEM libs_to_build test)
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
set(profiles_without_suffixes release)
|
|
|
|
|
set(build_profile_suffix "" CACHE INTERNAL "")
|
|
|
|
|
if(NOT (${build_profile} IN_LIST profiles_without_suffixes))
|
|
|
|
|
set(build_profile_suffix -${build_profile} CACHE INTERNAL "")
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-06-09 17:07:41 -03:00
|
|
|
if(${NS3_VERBOSE})
|
|
|
|
|
set_property(GLOBAL PROPERTY TARGET_MESSAGES TRUE)
|
|
|
|
|
set(CMAKE_FIND_DEBUG_MODE TRUE)
|
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE INTERNAL "")
|
|
|
|
|
else()
|
|
|
|
|
set_property(GLOBAL PROPERTY TARGET_MESSAGES OFF)
|
|
|
|
|
unset(CMAKE_FIND_DEBUG_MODE)
|
|
|
|
|
unset(CMAKE_VERBOSE_MAKEFILE CACHE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# Set warning level and warning as errors
|
2021-12-05 21:53:49 +00:00
|
|
|
if(${NS3_WARNINGS})
|
|
|
|
|
if(MSVC)
|
2021-11-10 22:28:44 -03:00
|
|
|
add_compile_options(/W3) # /W4 = -Wall + -Wextra
|
2021-12-05 21:53:49 +00:00
|
|
|
if(${NS3_WARNINGS_AS_ERRORS})
|
2021-11-10 22:28:44 -03:00
|
|
|
add_compile_options(/WX)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
add_compile_options(-Wall) # -Wextra
|
2021-12-05 21:53:49 +00:00
|
|
|
if(${NS3_WARNINGS_AS_ERRORS})
|
2022-04-01 19:33:41 -03:00
|
|
|
add_compile_options(-Werror -Wno-error=deprecated-declarations)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-versioning.cmake)
|
2022-01-31 22:50:10 -03:00
|
|
|
set(ENABLE_BUILD_VERSION False)
|
2022-01-10 22:36:50 -03:00
|
|
|
configure_embedded_version()
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
if(${NS3_CLANG_FORMAT})
|
|
|
|
|
find_program(CLANG_FORMAT clang-format)
|
2022-04-03 23:56:07 -03:00
|
|
|
if("${CLANG_FORMAT}" STREQUAL "CLANG_FORMAT-NOTFOUND")
|
2022-10-10 19:42:07 -03:00
|
|
|
message(FATAL_ERROR "Clang-format was not found")
|
2022-04-03 23:56:07 -03:00
|
|
|
else()
|
2021-11-10 22:28:44 -03:00
|
|
|
file(
|
|
|
|
|
GLOB_RECURSE
|
|
|
|
|
ALL_CXX_SOURCE_FILES
|
|
|
|
|
src/*.cc
|
|
|
|
|
src/*.h
|
|
|
|
|
examples/*.cc
|
|
|
|
|
examples/*.h
|
|
|
|
|
utils/*.cc
|
|
|
|
|
utils/*.h
|
|
|
|
|
scratch/*.cc
|
|
|
|
|
scratch/*.h
|
|
|
|
|
)
|
2021-12-05 21:53:49 +00:00
|
|
|
add_custom_target(
|
2022-10-10 19:42:07 -03:00
|
|
|
clang-format COMMAND ${CLANG_FORMAT} -style=file -i
|
2021-12-05 21:53:49 +00:00
|
|
|
${ALL_CXX_SOURCE_FILES}
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
unset(ALL_CXX_SOURCE_FILES)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_CLANG_TIDY})
|
2022-10-10 19:42:07 -03:00
|
|
|
find_program(
|
|
|
|
|
CLANG_TIDY NAMES clang-tidy clang-tidy-14 clang-tidy-15 clang-tidy-16
|
|
|
|
|
)
|
2022-04-03 23:56:07 -03:00
|
|
|
if("${CLANG_TIDY}" STREQUAL "CLANG_TIDY-NOTFOUND")
|
2022-10-10 19:42:07 -03:00
|
|
|
message(FATAL_ERROR "Clang-tidy was not found")
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
2022-12-23 20:08:16 -03:00
|
|
|
if((${CMAKE_VERSION} VERSION_LESS "3.12.0") AND ${NS3_CCACHE}
|
|
|
|
|
AND (NOT ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND"))
|
|
|
|
|
)
|
|
|
|
|
# CMake <3.12 puts CMAKE_CXX_COMPILER_LAUNCHER in the incorrect place
|
|
|
|
|
# and CCache ends up being unable to cache anything if calling
|
|
|
|
|
# clang-tidy https://gitlab.kitware.com/cmake/cmake/-/issues/18266
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"The current CMake ${CMAKE_VERSION} won't ccache objects correctly when running with clang-tidy."
|
|
|
|
|
"Update CMake to at least version 3.12, or disable either ccache or clang-tidy to continue."
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-10-10 19:42:07 -03:00
|
|
|
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}")
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2022-09-20 16:00:03 -03:00
|
|
|
else()
|
|
|
|
|
unset(CMAKE_CXX_CLANG_TIDY)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_CLANG_TIMETRACE})
|
|
|
|
|
if(${CLANG})
|
|
|
|
|
# Fetch and build clang build analyzer
|
|
|
|
|
include(ExternalProject)
|
|
|
|
|
ExternalProject_Add(
|
|
|
|
|
ClangBuildAnalyzer
|
|
|
|
|
GIT_REPOSITORY "https://github.com/aras-p/ClangBuildAnalyzer.git"
|
2022-01-21 19:56:55 -03:00
|
|
|
GIT_TAG "47406981a1c5a89e8f8c62802b924c3e163e7cb4"
|
2022-11-12 18:21:32 -03:00
|
|
|
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
2021-12-05 21:53:49 +00:00
|
|
|
INSTALL_COMMAND cmake -E copy_if_different ClangBuildAnalyzer
|
|
|
|
|
${PROJECT_BINARY_DIR}
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Add compiler flag and create target to do everything automatically
|
|
|
|
|
add_definitions(-ftime-trace)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
timeTraceReport
|
2021-12-05 21:53:49 +00:00
|
|
|
COMMAND
|
|
|
|
|
${PROJECT_BINARY_DIR}/ClangBuildAnalyzer --all ${PROJECT_BINARY_DIR}
|
|
|
|
|
${PROJECT_BINARY_DIR}/clangBuildAnalyzerReport.bin
|
|
|
|
|
COMMAND
|
|
|
|
|
${PROJECT_BINARY_DIR}/ClangBuildAnalyzer --analyze
|
|
|
|
|
${PROJECT_BINARY_DIR}/clangBuildAnalyzerReport.bin >
|
|
|
|
|
${PROJECT_SOURCE_DIR}/ClangBuildAnalyzerReport.txt
|
2021-11-10 22:28:44 -03:00
|
|
|
DEPENDS ClangBuildAnalyzer
|
|
|
|
|
)
|
|
|
|
|
else()
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"TimeTrace is a Clang feature, but you're using a different compiler."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
mark_as_advanced(CMAKE_FORMAT_PROGRAM)
|
2021-11-10 22:28:44 -03:00
|
|
|
find_program(CMAKE_FORMAT_PROGRAM cmake-format HINTS ~/.local/bin)
|
2022-04-03 23:56:07 -03:00
|
|
|
if("${CMAKE_FORMAT_PROGRAM}" STREQUAL "CMAKE_FORMAT_PROGRAM-NOTFOUND")
|
|
|
|
|
message(${HIGHLIGHTED_STATUS} "Proceeding without cmake-format")
|
|
|
|
|
else()
|
2022-02-09 20:59:27 -03:00
|
|
|
file(GLOB_RECURSE MODULES_CMAKE_FILES src/**/CMakeLists.txt
|
|
|
|
|
contrib/**/CMakeLists.txt examples/**/CMakeLists.txt
|
2023-01-30 15:54:35 -03:00
|
|
|
scratch/**/CMakeLists.txt
|
2022-02-09 20:59:27 -03:00
|
|
|
)
|
|
|
|
|
file(
|
|
|
|
|
GLOB
|
|
|
|
|
INTERNAL_CMAKE_FILES
|
|
|
|
|
CMakeLists.txt
|
|
|
|
|
utils/**/CMakeLists.txt
|
|
|
|
|
src/CMakeLists.txt
|
2022-01-31 20:02:10 -03:00
|
|
|
build-support/**/*.cmake
|
|
|
|
|
build-support/*.cmake
|
2022-02-09 20:59:27 -03:00
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(
|
2021-12-05 21:53:49 +00:00
|
|
|
cmake-format
|
|
|
|
|
COMMAND
|
|
|
|
|
${CMAKE_FORMAT_PROGRAM} -c
|
2022-01-31 20:02:10 -03:00
|
|
|
${PROJECT_SOURCE_DIR}/build-support/cmake-format.txt -i
|
2022-01-27 11:40:41 -03:00
|
|
|
${INTERNAL_CMAKE_FILES}
|
|
|
|
|
COMMAND
|
|
|
|
|
${CMAKE_FORMAT_PROGRAM} -c
|
2022-01-31 20:02:10 -03:00
|
|
|
${PROJECT_SOURCE_DIR}/build-support/cmake-format-modules.txt -i
|
2022-01-27 11:40:41 -03:00
|
|
|
${MODULES_CMAKE_FILES}
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
2022-01-27 11:40:41 -03:00
|
|
|
unset(MODULES_CMAKE_FILES)
|
|
|
|
|
unset(INTERNAL_CMAKE_FILES)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# If the user has not set a CXX standard version, assume the minimum
|
|
|
|
|
if(NOT "${CMAKE_CXX_STANDARD}")
|
|
|
|
|
set(CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD_MINIMUM})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Search standard provided by the user in the unsupported standards list
|
|
|
|
|
list(FIND CXX_UNSUPPORTED_STANDARDS ${CMAKE_CXX_STANDARD} unsupported)
|
|
|
|
|
if(${unsupported} GREATER -1)
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"You're trying to use the unsupported C++ ${CMAKE_CXX_STANDARD}.\n"
|
|
|
|
|
"Try -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD_MINIMUM}."
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-08-30 20:30:07 +00:00
|
|
|
# Honor CMAKE_CXX_STANDARD in check_cxx_source_compiles
|
|
|
|
|
# https://cmake.org/cmake/help/latest/policy/CMP0067.html
|
|
|
|
|
cmake_policy(SET CMP0066 NEW)
|
|
|
|
|
cmake_policy(SET CMP0067 NEW)
|
|
|
|
|
|
|
|
|
|
# After setting the correct CXX version, we can proceed to check for compiler
|
|
|
|
|
# workarounds
|
|
|
|
|
include(build-support/custom-modules/ns3-compiler-workarounds.cmake)
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_DES_METRICS})
|
|
|
|
|
add_definitions(-DENABLE_DES_METRICS)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_SANITIZE} AND ${NS3_SANITIZE_MEMORY})
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"The memory sanitizer can't be used with other sanitizers. Disable one of them."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_SANITIZE})
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,leak,undefined")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_SANITIZE_MEMORY})
|
|
|
|
|
if(${CLANG})
|
|
|
|
|
set(blacklistfile ${PROJECT_SOURCE_DIR}/memory-sanitizer-blacklist.txt)
|
|
|
|
|
if(EXISTS ${blacklistfile})
|
2021-12-05 21:53:49 +00:00
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
|
"${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-blacklist=${blacklistfile}"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT ($ENV{MSAN_OPTIONS} MATCHES "strict_memcmp=0"))
|
|
|
|
|
message(
|
2021-12-05 21:53:49 +00:00
|
|
|
WARNING
|
|
|
|
|
"Please export MSAN_OPTIONS=strict_memcmp=0 "
|
|
|
|
|
"and call the generated buildsystem directly to proceed.\n"
|
|
|
|
|
"Trying to build with cmake or IDEs will probably fail since"
|
|
|
|
|
"CMake can't export environment variables to its parent process."
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
unset(blacklistfile)
|
|
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "The memory sanitizer is only supported by Clang")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-28 14:08:53 -03:00
|
|
|
set(ENABLE_SQLITE False)
|
|
|
|
|
if(${NS3_SQLITE})
|
2022-02-09 20:59:27 -03:00
|
|
|
# find_package(SQLite3 QUIET) # unsupported in CMake 3.10 We emulate the
|
|
|
|
|
# behavior of find_package below
|
2022-01-28 19:31:35 -03:00
|
|
|
find_external_library(
|
2022-02-09 20:59:27 -03:00
|
|
|
DEPENDENCY_NAME SQLite3 HEADER_NAME sqlite3.h LIBRARY_NAME sqlite3
|
2022-01-28 14:08:53 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(${SQLite3_FOUND})
|
|
|
|
|
set(ENABLE_SQLITE True)
|
2022-05-12 12:58:19 -03:00
|
|
|
add_definitions(-DHAVE_SQLITE3)
|
|
|
|
|
include_directories(${SQLite3_INCLUDE_DIRS})
|
2022-01-28 14:08:53 -03:00
|
|
|
else()
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS} "SQLite was not found")
|
2022-01-28 14:08:53 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_NATIVE_OPTIMIZATIONS} AND ${GCC})
|
|
|
|
|
add_compile_options(-march=native -mtune=native)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_LINK_TIME_OPTIMIZATION})
|
|
|
|
|
# Link-time optimization (LTO) if available
|
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
|
check_ipo_supported(RESULT LTO_AVAILABLE OUTPUT output)
|
|
|
|
|
if(LTO_AVAILABLE)
|
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
2021-12-05 21:53:49 +00:00
|
|
|
message(STATUS "Link-time optimization (LTO) is supported.")
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
STATUS "Link-time optimization (LTO) is not supported: ${output}."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_LINK_WHAT_YOU_USE})
|
|
|
|
|
set(CMAKE_LINK_WHAT_YOU_USE TRUE)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_LINK_WHAT_YOU_USE FALSE)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_INCLUDE_WHAT_YOU_USE})
|
2021-12-05 21:53:49 +00:00
|
|
|
# Before using, install iwyu, run "strings /usr/bin/iwyu | grep LLVM" to
|
|
|
|
|
# find the appropriate clang version and install it. If you don't do that,
|
|
|
|
|
# it will fail. Worse than that: it will fail silently. We use the wrapper
|
|
|
|
|
# to get a iwyu.log file in the ns-3-dev folder.
|
2021-11-10 22:28:44 -03:00
|
|
|
find_program(INCLUDE_WHAT_YOU_USE_PROG iwyu)
|
2022-04-03 23:56:07 -03:00
|
|
|
if("${INCLUDE_WHAT_YOU_USE_PROG}" STREQUAL
|
|
|
|
|
"INCLUDE_WHAT_YOU_USE_PROG-NOTFOUND"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
message(FATAL_ERROR "iwyu (include-what-you-use) was not found.")
|
|
|
|
|
endif()
|
|
|
|
|
message(STATUS "iwyu is enabled")
|
2021-12-05 21:53:49 +00:00
|
|
|
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
|
2022-01-31 20:02:10 -03:00
|
|
|
${PROJECT_SOURCE_DIR}/build-support/iwyu-wrapper.sh;${PROJECT_SOURCE_DIR}
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
unset(CMAKE_CXX_INCLUDE_WHAT_YOU_USE)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${XCODE})
|
|
|
|
|
if(${NS3_STATIC} OR ${NS3_MONOLIB})
|
|
|
|
|
message(
|
2021-12-05 21:53:49 +00:00
|
|
|
FATAL_ERROR
|
|
|
|
|
"Xcode doesn't play nicely with CMake object libraries,"
|
|
|
|
|
"and those are used for NS3_STATIC and NS3_MONOLIB.\n"
|
|
|
|
|
"Disable them or try a different generator"
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
set(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY ON)
|
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
|
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
|
|
|
|
else()
|
|
|
|
|
unset(CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY)
|
|
|
|
|
unset(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED)
|
|
|
|
|
unset(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Set common include folder (./build/include, where we find ns3/core-module.h)
|
|
|
|
|
include_directories(${CMAKE_OUTPUT_DIRECTORY}/include)
|
|
|
|
|
|
|
|
|
|
# find required dependencies
|
2021-12-05 21:53:49 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH
|
2022-01-31 20:02:10 -03:00
|
|
|
"${PROJECT_SOURCE_DIR}/build-support/custom-modules"
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2022-01-31 20:02:10 -03:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/build-support/3rd-party")
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2023-02-13 19:53:51 +01:00
|
|
|
set(ENABLE_EIGEN False)
|
|
|
|
|
if(${NS3_EIGEN})
|
|
|
|
|
find_package(Eigen3 QUIET)
|
|
|
|
|
|
|
|
|
|
if(${EIGEN3_FOUND})
|
|
|
|
|
set(ENABLE_EIGEN True)
|
|
|
|
|
add_definitions(-DHAVE_EIGEN3)
|
2023-02-22 12:40:11 +01:00
|
|
|
add_definitions(-DEIGEN_MPL2_ONLY)
|
2023-02-13 19:53:51 +01:00
|
|
|
include_directories(${EIGEN3_INCLUDE_DIR})
|
|
|
|
|
else()
|
|
|
|
|
message(${HIGHLIGHTED_STATUS} "Eigen was not found")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# GTK3 Don't search for it if you don't have it installed, as it take an
|
|
|
|
|
# insane amount of time
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_GTK3})
|
|
|
|
|
find_package(HarfBuzz QUIET)
|
|
|
|
|
if(NOT ${HarfBuzz_FOUND})
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Harfbuzz is required by GTK3 and was not found."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "")
|
|
|
|
|
find_package(GTK3 QUIET)
|
|
|
|
|
unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS CACHE)
|
|
|
|
|
if(NOT ${GTK3_FOUND})
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"GTK3 was not found. Continuing without it."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
2022-01-08 23:09:57 -03:00
|
|
|
if(${GTK3_VERSION} VERSION_LESS 3.22)
|
|
|
|
|
set(GTK3_FOUND FALSE)
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"GTK3 found with incompatible version ${GTK3_VERSION}"
|
|
|
|
|
)
|
2022-01-08 23:09:57 -03:00
|
|
|
else()
|
|
|
|
|
message(STATUS "GTK3 was found.")
|
2022-05-12 12:58:19 -03:00
|
|
|
include_directories(${GTK3_INCLUDE_DIRS} ${HarfBuzz_INCLUDE_DIRS})
|
2022-01-08 23:09:57 -03:00
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2022-01-08 23:09:57 -03:00
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_STATIC})
|
2021-12-05 21:53:49 +00:00
|
|
|
# Warn users that they may be using shared libraries, which won't produce a
|
|
|
|
|
# standalone static library
|
|
|
|
|
message(
|
2022-04-20 19:10:11 -03:00
|
|
|
WARNING "Statically linking 3rd party libraries have not been tested.\n"
|
|
|
|
|
"Disable Brite, Click, Gtk, GSL, Mpi, Openflow and SQLite"
|
|
|
|
|
" if you want a standalone static ns-3 library."
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
2022-09-20 16:00:03 -03:00
|
|
|
if(WIN32)
|
|
|
|
|
message(FATAL_ERROR "Static builds are unsupported on Windows"
|
|
|
|
|
"\nSocket libraries cannot be linked statically"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
find_package(LibXml2 QUIET)
|
|
|
|
|
if(NOT ${LIBXML2_FOUND})
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"LibXML2 was not found. Continuing without it."
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
message(STATUS "LibXML2 was found.")
|
|
|
|
|
add_definitions(-DHAVE_LIBXML2)
|
2022-05-12 12:58:19 -03:00
|
|
|
include_directories(${LIBXML2_INCLUDE_DIR})
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-04-22 00:03:49 -03:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG)
|
|
|
|
|
find_package(Threads QUIET)
|
2021-11-17 02:02:02 +00:00
|
|
|
if(NOT ${Threads_FOUND})
|
|
|
|
|
message(FATAL_ERROR Threads are required by ns-3)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
set(Python3_LIBRARIES)
|
|
|
|
|
set(Python3_EXECUTABLE)
|
|
|
|
|
set(Python3_FOUND FALSE)
|
|
|
|
|
set(Python3_INCLUDE_DIRS)
|
2022-11-11 23:18:53 -03:00
|
|
|
if(${NS3_PYTHON_BINDINGS})
|
|
|
|
|
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
|
|
|
|
|
find_package(Python3 COMPONENTS Interpreter Development)
|
|
|
|
|
else()
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
set(Python_ADDITIONAL_VERSIONS 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9)
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
find_package(PythonInterp)
|
|
|
|
|
find_package(PythonLibs)
|
|
|
|
|
|
|
|
|
|
# Move deprecated results into the FindPython3 resulting variables
|
|
|
|
|
set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND})
|
|
|
|
|
set(Python3_Development_FOUND ${PYTHONLIBS_FOUND})
|
|
|
|
|
if(${PYTHONINTERP_FOUND})
|
|
|
|
|
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
|
|
|
|
|
set(Python3_FOUND TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
if(${PYTHONLIBS_FOUND})
|
|
|
|
|
set(Python3_LIBRARIES ${PYTHON_LIBRARIES})
|
|
|
|
|
set(Python3_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS})
|
|
|
|
|
endif()
|
2022-03-02 11:51:53 -03:00
|
|
|
endif()
|
2022-11-11 23:18:53 -03:00
|
|
|
else()
|
|
|
|
|
# If Python was not set yet, use the version found by check_deps
|
|
|
|
|
check_deps("" "python3" python3_deps)
|
|
|
|
|
if(python3_deps)
|
|
|
|
|
message(FATAL_ERROR "Python3 was not found")
|
|
|
|
|
else()
|
|
|
|
|
set(Python3_EXECUTABLE ${PYTHON3})
|
2022-03-02 11:51:53 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Check if both Python interpreter and development libraries were found
|
|
|
|
|
if(${Python3_Interpreter_FOUND})
|
|
|
|
|
if(${Python3_Development_FOUND})
|
|
|
|
|
set(Python3_FOUND TRUE)
|
2022-04-27 18:08:32 -03:00
|
|
|
if(APPLE)
|
|
|
|
|
# Apple is very weird and there could be a lot of conflicting python
|
|
|
|
|
# versions which can generate conflicting rpaths preventing the python
|
|
|
|
|
# bindings from working
|
|
|
|
|
|
|
|
|
|
# To work around, we extract the /path/to/Frameworks from the library
|
|
|
|
|
# path
|
|
|
|
|
list(GET Python3_LIBRARIES 0 pylib)
|
|
|
|
|
string(REGEX REPLACE "(.*Frameworks)/Python(3.|.)framework.*" "\\1"
|
|
|
|
|
DEVELOPER_DIR ${pylib}
|
|
|
|
|
)
|
|
|
|
|
if("${DEVELOPER_DIR}" MATCHES "Frameworks")
|
|
|
|
|
set(CMAKE_BUILD_RPATH "${DEVELOPER_DIR}" CACHE STRING "")
|
|
|
|
|
set(CMAKE_INSTALL_RPATH "${DEVELOPER_DIR}" CACHE STRING "")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2022-05-12 12:58:19 -03:00
|
|
|
include_directories(${Python3_INCLUDE_DIRS})
|
2022-02-09 20:59:27 -03:00
|
|
|
else()
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Python: development libraries were not found"
|
|
|
|
|
)
|
2022-01-26 11:51:50 -03:00
|
|
|
endif()
|
2022-02-09 20:59:27 -03:00
|
|
|
else()
|
2023-03-18 00:03:56 -03:00
|
|
|
if(${NS3_PYTHON_BINDINGS})
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Python: an incompatible version of Python was found, python bindings will be disabled"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-01-26 01:53:28 -03:00
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_PYTHON_BINDINGS OFF)
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_PYTHON_BINDINGS})
|
2022-03-02 11:51:53 -03:00
|
|
|
if(NOT ${Python3_FOUND})
|
2022-01-26 11:51:50 -03:00
|
|
|
message(
|
2022-06-06 06:44:42 -07:00
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Bindings: python bindings require Python, but it could not be found"
|
2022-01-26 11:51:50 -03:00
|
|
|
)
|
|
|
|
|
else()
|
2022-06-06 06:44:42 -07:00
|
|
|
check_python_packages("cppyy" missing_packages)
|
2022-01-26 11:51:50 -03:00
|
|
|
if(missing_packages)
|
|
|
|
|
message(
|
2022-06-06 06:44:42 -07:00
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Bindings: python bindings disabled due to the following missing dependencies: ${missing_packages}"
|
2022-01-26 11:51:50 -03:00
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
set(ENABLE_PYTHON_BINDINGS ON)
|
|
|
|
|
endif()
|
2022-08-04 15:21:11 -03:00
|
|
|
|
|
|
|
|
# Copy the bindings file if we have python, which will prevent python
|
|
|
|
|
# scripts from failing due to the missing ns package
|
|
|
|
|
set(destination_dir ${CMAKE_OUTPUT_DIRECTORY}/bindings/python/ns)
|
|
|
|
|
configure_file(
|
|
|
|
|
bindings/python/ns__init__.py ${destination_dir}/__init__.py COPYONLY
|
|
|
|
|
)
|
2022-08-23 18:08:14 -03:00
|
|
|
|
|
|
|
|
# And create an install target for the bindings
|
|
|
|
|
if(NOT NS3_BINDINGS_INSTALL_DIR)
|
|
|
|
|
# If the installation directory for the python bindings is not set,
|
|
|
|
|
# suggest the user site-packages directory
|
|
|
|
|
execute_process(
|
|
|
|
|
COMMAND python3 -m site --user-site
|
|
|
|
|
OUTPUT_VARIABLE SUGGESTED_BINDINGS_INSTALL_DIR
|
|
|
|
|
)
|
|
|
|
|
string(STRIP "${SUGGESTED_BINDINGS_INSTALL_DIR}"
|
|
|
|
|
SUGGESTED_BINDINGS_INSTALL_DIR
|
|
|
|
|
)
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"NS3_BINDINGS_INSTALL_DIR was not set. The python bindings won't be installed with ./ns3 install."
|
2023-03-24 14:09:34 -03:00
|
|
|
"This setting is meant for packaging and redistribution."
|
2022-08-23 18:08:14 -03:00
|
|
|
)
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Set NS3_BINDINGS_INSTALL_DIR=\"${SUGGESTED_BINDINGS_INSTALL_DIR}\" to install it to the default location."
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
install(FILES bindings/python/ns__init__.py
|
|
|
|
|
DESTINATION ${NS3_BINDINGS_INSTALL_DIR}/ns RENAME __init__.py
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
uninstall_bindings COMMAND rm -R ${NS3_BINDINGS_INSTALL_DIR}/ns
|
|
|
|
|
)
|
|
|
|
|
add_dependencies(uninstall uninstall_bindings)
|
|
|
|
|
endif()
|
2022-01-26 11:51:50 -03:00
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-11-12 12:27:47 -03:00
|
|
|
if(${NS3_NINJA_TRACING})
|
|
|
|
|
if(${CMAKE_GENERATOR} STREQUAL Ninja)
|
|
|
|
|
include(ExternalProject)
|
|
|
|
|
ExternalProject_Add(
|
|
|
|
|
NinjaTracing
|
|
|
|
|
GIT_REPOSITORY "https://github.com/nico/ninjatracing.git"
|
|
|
|
|
GIT_TAG "f9d21e973cfdeafa913b83a927fef56258f70b9a"
|
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
|
BUILD_COMMAND ""
|
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
|
)
|
|
|
|
|
ExternalProject_Get_Property(NinjaTracing SOURCE_DIR)
|
|
|
|
|
set(embed_time_trace)
|
|
|
|
|
if(${NS3_CLANG_TIMETRACE} AND ${CLANG})
|
|
|
|
|
set(embed_time_trace --embed-time-trace)
|
|
|
|
|
endif()
|
|
|
|
|
add_custom_target(
|
|
|
|
|
ninjaTrace
|
|
|
|
|
COMMAND
|
|
|
|
|
${Python3_EXECUTABLE} ${SOURCE_DIR}/ninjatracing -a
|
|
|
|
|
${embed_time_trace} ${PROJECT_BINARY_DIR}/.ninja_log >
|
|
|
|
|
${PROJECT_SOURCE_DIR}/ninja_performance_trace.json
|
|
|
|
|
DEPENDS NinjaTracing
|
|
|
|
|
)
|
|
|
|
|
unset(embed_time_trace)
|
|
|
|
|
unset(SOURCE_DIR)
|
|
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "Ninjatracing requires the Ninja generator")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-04-29 16:09:18 -07:00
|
|
|
# Disable the below warning from bindings built in debug mode with clang++:
|
2022-05-02 14:23:17 -03:00
|
|
|
# "expression with side effects will be evaluated despite being used as an
|
|
|
|
|
# operand to 'typeid'"
|
2022-04-29 16:09:18 -07:00
|
|
|
if(${ENABLE_PYTHON_BINDINGS} AND ${CLANG})
|
|
|
|
|
add_compile_options(-Wno-potentially-evaluated-expression)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-26 01:53:28 -03:00
|
|
|
set(ENABLE_VISUALIZER FALSE)
|
|
|
|
|
if(${NS3_VISUALIZER})
|
2022-03-02 11:51:53 -03:00
|
|
|
if((NOT ${ENABLE_PYTHON_BINDINGS}) OR (NOT ${Python3_FOUND}))
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS} "Visualizer requires Python bindings")
|
2022-01-26 01:53:28 -03:00
|
|
|
else()
|
|
|
|
|
set(ENABLE_VISUALIZER TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${NS3_COVERAGE} AND (NOT ${ENABLE_TESTS} OR NOT ${ENABLE_EXAMPLES}))
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
2022-03-19 12:57:05 -03:00
|
|
|
"Code coverage requires examples and tests.\nTry reconfiguring CMake with -DNS3_TESTS=ON -DNS3_EXAMPLES=ON"
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${ENABLE_TESTS})
|
2022-10-25 10:19:01 -03:00
|
|
|
add_custom_target(test-runner-examples-as-tests)
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(all-test-targets)
|
|
|
|
|
|
2022-01-08 23:09:57 -03:00
|
|
|
# Create a custom target to run test.py --no-build Target is also used to
|
2021-12-05 21:53:49 +00:00
|
|
|
# produce code coverage output
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(
|
|
|
|
|
run_test_py
|
2022-03-02 11:51:53 -03:00
|
|
|
COMMAND ${Python3_EXECUTABLE} test.py --no-build
|
2021-11-10 22:28:44 -03:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
|
DEPENDS all-test-targets
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${ENABLE_EXAMPLES})
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-coverage.cmake)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Process config-store-config
|
2021-12-05 21:53:49 +00:00
|
|
|
configure_file(
|
2022-01-31 20:02:10 -03:00
|
|
|
build-support/config-store-config-template.h
|
2021-12-05 21:53:49 +00:00
|
|
|
${CMAKE_HEADER_OUTPUT_DIRECTORY}/config-store-config.h
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
set(ENABLE_MPI FALSE)
|
|
|
|
|
if(${NS3_MPI})
|
|
|
|
|
find_package(MPI QUIET)
|
|
|
|
|
if(NOT ${MPI_FOUND})
|
2022-04-16 23:49:59 -03:00
|
|
|
message(FATAL_ERROR "MPI was not found.")
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
message(STATUS "MPI was found.")
|
|
|
|
|
add_definitions(-DNS3_MPI)
|
2022-05-12 12:58:19 -03:00
|
|
|
include_directories(${MPI_CXX_INCLUDE_DIRS})
|
2021-11-10 22:28:44 -03:00
|
|
|
set(ENABLE_MPI TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
mark_as_advanced(Boost_INCLUDE_DIR)
|
|
|
|
|
find_package(Boost)
|
|
|
|
|
if(${Boost_FOUND})
|
2021-11-10 22:28:44 -03:00
|
|
|
include_directories(${Boost_INCLUDE_DIRS})
|
|
|
|
|
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_GSL})
|
|
|
|
|
find_package(GSL QUIET)
|
|
|
|
|
if(NOT ${GSL_FOUND})
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS} "GSL was not found. Continuing without it.")
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
message(STATUS "GSL was found.")
|
2022-02-27 12:51:35 -08:00
|
|
|
add_definitions(-DHAVE_GSL)
|
2022-05-12 12:58:19 -03:00
|
|
|
include_directories(${GSL_INCLUDE_DIRS})
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-08 23:09:57 -03:00
|
|
|
# checking for documentation dependencies and creating targets
|
|
|
|
|
|
|
|
|
|
# First we check for doxygen dependencies
|
|
|
|
|
mark_as_advanced(DOXYGEN)
|
2022-09-20 16:00:03 -03:00
|
|
|
check_deps("" "doxygen;dot;dia;python3" doxygen_docs_missing_deps)
|
2022-01-08 23:09:57 -03:00
|
|
|
if(doxygen_docs_missing_deps)
|
|
|
|
|
message(
|
2022-03-19 12:57:05 -03:00
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"docs: doxygen documentation not enabled due to missing dependencies: ${doxygen_docs_missing_deps}"
|
2022-01-08 23:09:57 -03:00
|
|
|
)
|
2022-02-09 20:59:27 -03:00
|
|
|
# cmake-format: off
|
|
|
|
|
set(doxygen_missing_msg
|
|
|
|
|
echo The following Doxygen dependencies are missing: ${doxygen_docs_missing_deps}.
|
|
|
|
|
Reconfigure the project after installing them.
|
|
|
|
|
)
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
|
|
|
|
|
# Create stub targets to inform users about missing dependencies
|
|
|
|
|
add_custom_target(
|
|
|
|
|
run-print-introspected-doxygen COMMAND ${doxygen_missing_msg}
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
run-introspected-command-line COMMAND ${doxygen_missing_msg}
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
assemble-introspected-command-line COMMAND ${doxygen_missing_msg}
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(update_doxygen_version COMMAND ${doxygen_missing_msg})
|
|
|
|
|
add_custom_target(doxygen COMMAND ${doxygen_missing_msg})
|
|
|
|
|
add_custom_target(doxygen-no-build COMMAND ${doxygen_missing_msg})
|
2022-01-08 23:09:57 -03:00
|
|
|
else()
|
|
|
|
|
# We checked this already exists, but we need the path to the executable
|
2022-11-02 15:35:57 -03:00
|
|
|
set(DOXYGEN_EXECUTABLE ${DOXYGEN})
|
2022-01-08 23:09:57 -03:00
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(
|
2022-01-08 23:09:57 -03:00
|
|
|
update_doxygen_version
|
2022-09-20 16:00:03 -03:00
|
|
|
COMMAND bash ${PROJECT_SOURCE_DIR}/doc/ns3_html_theme/get_version.sh
|
2021-11-10 22:28:44 -03:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
|
)
|
2022-01-08 23:09:57 -03:00
|
|
|
add_custom_target(
|
|
|
|
|
doxygen-no-build
|
|
|
|
|
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/doc/doxygen.conf
|
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
|
DEPENDS update_doxygen_version
|
2022-03-19 12:19:50 -03:00
|
|
|
USES_TERMINAL
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2023-02-06 11:35:34 -03:00
|
|
|
# The `doxygen` target only really works if we have tests enabled, so emit a
|
|
|
|
|
# warning to use `doxygen-no-build` instead.
|
|
|
|
|
if((NOT ${ENABLE_TESTS}) AND (NOT ${ENABLE_EXAMPLES}))
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
set(doxygen_target_requires_tests_msg
|
|
|
|
|
echo The \\'doxygen\\' target called by \\'./ns3 docs doxygen\\' or \\'./ns3 docs all\\' commands
|
|
|
|
|
require examples and tests to generate introspected documentation.
|
|
|
|
|
Enable examples and tests, or use \\'doxygen-no-build\\'.
|
|
|
|
|
)
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
add_custom_target(doxygen COMMAND ${doxygen_target_requires_tests_msg})
|
|
|
|
|
unset(doxygen_target_requires_tests_msg)
|
|
|
|
|
else()
|
|
|
|
|
# Get introspected doxygen
|
|
|
|
|
add_custom_target(
|
|
|
|
|
run-print-introspected-doxygen
|
|
|
|
|
COMMAND
|
|
|
|
|
${CMAKE_OUTPUT_DIRECTORY}/utils/ns${NS3_VER}-print-introspected-doxygen${build_profile_suffix}
|
|
|
|
|
> ${PROJECT_SOURCE_DIR}/doc/introspected-doxygen.h
|
|
|
|
|
COMMAND
|
|
|
|
|
${CMAKE_OUTPUT_DIRECTORY}/utils/ns${NS3_VER}-print-introspected-doxygen${build_profile_suffix}
|
|
|
|
|
--output-text > ${PROJECT_SOURCE_DIR}/doc/ns3-object.txt
|
|
|
|
|
DEPENDS print-introspected-doxygen
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
run-introspected-command-line
|
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E env NS_COMMANDLINE_INTROSPECTION=..
|
|
|
|
|
${Python3_EXECUTABLE} ./test.py --no-build --constrain=example
|
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
|
DEPENDS all-test-targets # all-test-targets only exists if ENABLE_TESTS
|
|
|
|
|
# is set to ON
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
file(
|
|
|
|
|
WRITE ${CMAKE_BINARY_DIR}/introspected-command-line-preamble.h
|
|
|
|
|
"/* This file is automatically generated by
|
|
|
|
|
CommandLine::PrintDoxygenUsage() from the CommandLine configuration
|
|
|
|
|
in various example programs. Do not edit this file! Edit the
|
|
|
|
|
CommandLine configuration in those files instead.
|
|
|
|
|
*/\n"
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
assemble-introspected-command-line
|
|
|
|
|
# works on CMake 3.18 or newer > COMMAND ${CMAKE_COMMAND} -E cat
|
|
|
|
|
# ${PROJECT_SOURCE_DIR}/testpy-output/*.command-line >
|
|
|
|
|
# ${PROJECT_SOURCE_DIR}/doc/introspected-command-line.h
|
|
|
|
|
COMMAND
|
|
|
|
|
${cat_command}
|
|
|
|
|
${CMAKE_BINARY_DIR}/introspected-command-line-preamble.h
|
|
|
|
|
${PROJECT_SOURCE_DIR}/testpy-output/*.command-line >
|
|
|
|
|
${PROJECT_SOURCE_DIR}/doc/introspected-command-line.h 2> NULL
|
|
|
|
|
DEPENDS run-introspected-command-line
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
|
doxygen
|
|
|
|
|
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_SOURCE_DIR}/doc/doxygen.conf
|
|
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
|
|
|
DEPENDS update_doxygen_version run-print-introspected-doxygen
|
|
|
|
|
assemble-introspected-command-line
|
|
|
|
|
USES_TERMINAL
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-01-08 23:09:57 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Now we check for sphinx dependencies
|
|
|
|
|
mark_as_advanced(
|
|
|
|
|
SPHINX_EXECUTABLE SPHINX_OUTPUT_HTML SPHINX_OUTPUT_MAN
|
|
|
|
|
SPHINX_WARNINGS_AS_ERRORS
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check deps accepts a list of packages, list of programs and name of the
|
|
|
|
|
# return variable
|
|
|
|
|
check_deps(
|
|
|
|
|
"Sphinx" "epstopdf;pdflatex;latexmk;convert;dvipng"
|
|
|
|
|
sphinx_docs_missing_deps
|
|
|
|
|
)
|
|
|
|
|
if(sphinx_docs_missing_deps)
|
|
|
|
|
message(
|
2022-03-19 12:57:05 -03:00
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"docs: sphinx documentation not enabled due to missing dependencies: ${sphinx_docs_missing_deps}"
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
2022-02-09 20:59:27 -03:00
|
|
|
# cmake-format: off
|
|
|
|
|
set(sphinx_missing_msg
|
|
|
|
|
echo The following Sphinx dependencies are missing: ${sphinx_docs_missing_deps}.
|
|
|
|
|
Reconfigure the project after installing them.
|
|
|
|
|
)
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
|
|
|
|
|
# Create stub targets to inform users about missing dependencies
|
|
|
|
|
add_custom_target(sphinx COMMAND ${sphinx_missing_msg})
|
|
|
|
|
add_custom_target(sphinx_manual COMMAND ${sphinx_missing_msg})
|
|
|
|
|
add_custom_target(sphinx_models COMMAND ${sphinx_missing_msg})
|
|
|
|
|
add_custom_target(sphinx_tutorial COMMAND ${sphinx_missing_msg})
|
|
|
|
|
add_custom_target(sphinx_contributing COMMAND ${sphinx_missing_msg})
|
2023-03-07 21:15:34 -08:00
|
|
|
add_custom_target(sphinx_installation COMMAND ${sphinx_missing_msg})
|
2022-01-08 23:09:57 -03:00
|
|
|
else()
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(sphinx COMMENT "Building sphinx documents")
|
2022-09-20 16:00:03 -03:00
|
|
|
mark_as_advanced(MAKE)
|
|
|
|
|
find_program(MAKE NAMES make mingw32-make)
|
|
|
|
|
if(${MAKE} STREQUAL "MAKE-NOTFOUND")
|
2022-09-24 13:16:05 -03:00
|
|
|
message(
|
|
|
|
|
FATAL_ERROR "Make was not found but it is required by Sphinx docs"
|
|
|
|
|
)
|
2022-09-20 16:00:03 -03:00
|
|
|
elseif(${MAKE} MATCHES "mingw32-make")
|
|
|
|
|
# This is a super wild hack for MinGW
|
|
|
|
|
#
|
|
|
|
|
# For some reason make is shipped as mingw32-make instead of make, but
|
|
|
|
|
# tons of software rely on it being called make
|
|
|
|
|
#
|
|
|
|
|
# We could technically create an alias, using doskey make=mingw32-make,
|
|
|
|
|
# but we need to redefine that for every new shell or make registry
|
|
|
|
|
# changes to make it permanent
|
|
|
|
|
#
|
|
|
|
|
# Symlinking requires administrative permissions for some reason, so we
|
|
|
|
|
# just copy the entire thing
|
|
|
|
|
get_filename_component(make_directory ${MAKE} DIRECTORY)
|
|
|
|
|
get_filename_component(make_parent_directory ${make_directory} DIRECTORY)
|
|
|
|
|
if(NOT (EXISTS ${make_directory}/make.exe))
|
|
|
|
|
file(COPY ${MAKE} DESTINATION ${make_parent_directory})
|
|
|
|
|
file(RENAME ${make_parent_directory}/mingw32-make.exe
|
|
|
|
|
${make_directory}/make.exe
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
set(MAKE ${make_directory}/make.exe)
|
|
|
|
|
else()
|
|
|
|
|
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
function(sphinx_target targetname)
|
2022-02-11 22:47:03 -03:00
|
|
|
# cmake-format: off
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(
|
2022-02-11 22:47:03 -03:00
|
|
|
sphinx_${targetname}
|
2022-09-20 16:00:03 -03:00
|
|
|
COMMAND ${MAKE} SPHINXOPTS=-N -k html singlehtml latexpdf
|
2021-11-10 22:28:44 -03:00
|
|
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/doc/${targetname}
|
|
|
|
|
)
|
2022-02-11 22:47:03 -03:00
|
|
|
# cmake-format: on
|
2021-11-10 22:28:44 -03:00
|
|
|
add_dependencies(sphinx sphinx_${targetname})
|
|
|
|
|
endfunction()
|
|
|
|
|
sphinx_target(manual)
|
|
|
|
|
sphinx_target(models)
|
|
|
|
|
sphinx_target(tutorial)
|
2022-01-24 12:16:35 -08:00
|
|
|
sphinx_target(contributing)
|
2023-03-07 21:15:34 -08:00
|
|
|
sphinx_target(installation)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2022-01-08 23:09:57 -03:00
|
|
|
# end of checking for documentation dependencies and creating targets
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
# Adding this module manually is required by CMake 3.10
|
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
# Process core-config If INT128 is not found, fallback to CAIRO
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${NS3_INT64X64} MATCHES "INT128")
|
2022-03-02 11:51:53 -03:00
|
|
|
check_cxx_source_compiles(
|
|
|
|
|
"#include <stdint.h>
|
2022-11-17 13:44:28 -08:00
|
|
|
int main()
|
2022-03-02 11:51:53 -03:00
|
|
|
{
|
|
|
|
|
if ((uint128_t *) 0) return 0;
|
|
|
|
|
if (sizeof (uint128_t)) return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}"
|
|
|
|
|
HAVE_UINT128_T
|
|
|
|
|
)
|
|
|
|
|
check_cxx_source_compiles(
|
|
|
|
|
"#include <stdint.h>
|
2022-11-17 13:44:28 -08:00
|
|
|
int main()
|
2022-03-02 11:51:53 -03:00
|
|
|
{
|
|
|
|
|
if ((__uint128_t *) 0) return 0;
|
|
|
|
|
if (sizeof (__uint128_t)) return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}"
|
|
|
|
|
HAVE___UINT128_T
|
|
|
|
|
)
|
|
|
|
|
if(HAVE_UINT128_T OR HAVE___UINT128_T)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(INT64X64_USE_128 TRUE)
|
|
|
|
|
else()
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Int128 was not found. Falling back to Cairo."
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(NS3_INT64X64 "CAIRO")
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
# If long double and double have different sizes, fallback to CAIRO
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${NS3_INT64X64} MATCHES "DOUBLE")
|
2021-12-05 21:53:49 +00:00
|
|
|
# WSLv1 has a long double issue that will result in a few tests failing
|
|
|
|
|
# https://github.com/microsoft/WSL/issues/830
|
2021-11-10 22:28:44 -03:00
|
|
|
include(CheckTypeSize)
|
|
|
|
|
check_type_size("double" SIZEOF_DOUBLE)
|
|
|
|
|
check_type_size("long double" SIZEOF_LONG_DOUBLE)
|
|
|
|
|
|
|
|
|
|
if(${SIZEOF_LONG_DOUBLE} EQUAL ${SIZEOF_DOUBLE})
|
|
|
|
|
message(
|
2021-12-05 21:53:49 +00:00
|
|
|
STATUS
|
|
|
|
|
"Long double has the wrong size: LD ${SIZEOF_LONG_DOUBLE} vs D ${SIZEOF_DOUBLE}. Falling back to CAIRO."
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(NS3_INT64X64 "CAIRO")
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
|
|
|
|
set(INT64X64_USE_DOUBLE TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
# Fallback option
|
|
|
|
|
if(${NS3_INT64X64} MATCHES "CAIRO")
|
|
|
|
|
set(INT64X64_USE_CAIRO TRUE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Check for required headers and functions, set flags if they're found or warn
|
|
|
|
|
# if they're not found
|
2022-05-11 21:24:03 -03:00
|
|
|
check_include_file("stdint.h" "HAVE_STDINT_H")
|
|
|
|
|
check_include_file("inttypes.h" "HAVE_INTTYPES_H")
|
|
|
|
|
check_include_file("sys/types.h" "HAVE_SYS_TYPES_H")
|
|
|
|
|
check_include_file("sys/stat.h" "HAVE_SYS_STAT_H")
|
|
|
|
|
check_include_file("dirent.h" "HAVE_DIRENT_H")
|
|
|
|
|
check_include_file("stdlib.h" "HAVE_STDLIB_H")
|
|
|
|
|
check_include_file("signal.h" "HAVE_SIGNAL_H")
|
|
|
|
|
check_include_file("netpacket/packet.h" "HAVE_PACKETH")
|
2021-11-10 22:28:44 -03:00
|
|
|
check_function_exists("getenv" "HAVE_GETENV")
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
configure_file(
|
2022-01-31 20:02:10 -03:00
|
|
|
build-support/core-config-template.h
|
2021-12-05 21:53:49 +00:00
|
|
|
${CMAKE_HEADER_OUTPUT_DIRECTORY}/core-config.h
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Force enable ns-3 logging in debug builds and if requested for other build
|
|
|
|
|
# types
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_LOG} OR (${build_profile} STREQUAL "debug"))
|
|
|
|
|
add_definitions(-DNS3_LOG_ENABLE)
|
|
|
|
|
endif()
|
2021-12-05 21:53:49 +00:00
|
|
|
# Force enable ns-3 asserts in debug builds and if requested for other build
|
|
|
|
|
# types
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_ASSERT} OR (${build_profile} STREQUAL "debug"))
|
|
|
|
|
add_definitions(-DNS3_ASSERT_ENABLE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_TAP OFF)
|
|
|
|
|
if(${NS3_TAP})
|
|
|
|
|
set(ENABLE_TAP ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set(ENABLE_EMU OFF)
|
|
|
|
|
if(${NS3_EMU})
|
|
|
|
|
set(ENABLE_EMU ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
set(PLATFORM_UNSUPPORTED_PRE "Platform doesn't support")
|
|
|
|
|
set(PLATFORM_UNSUPPORTED_POST "features. Continuing without them.")
|
2021-12-05 21:53:49 +00:00
|
|
|
# Remove from libs_to_build all incompatible libraries or the ones that
|
|
|
|
|
# dependencies couldn't be installed
|
2022-09-20 16:00:03 -03:00
|
|
|
if(APPLE OR WSLv1 OR WIN32)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(ENABLE_TAP OFF)
|
|
|
|
|
set(ENABLE_EMU OFF)
|
2021-11-10 22:28:44 -03:00
|
|
|
list(REMOVE_ITEM libs_to_build fd-net-device)
|
2021-12-05 21:53:49 +00:00
|
|
|
message(
|
|
|
|
|
STATUS
|
|
|
|
|
"${PLATFORM_UNSUPPORTED_PRE} TAP and EMU ${PLATFORM_UNSUPPORTED_POST}"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT ${ENABLE_MPI})
|
|
|
|
|
list(REMOVE_ITEM libs_to_build mpi)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(NOT ${ENABLE_VISUALIZER})
|
|
|
|
|
list(REMOVE_ITEM libs_to_build visualizer)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
if(NOT ${ENABLE_TAP})
|
2021-11-10 22:28:44 -03:00
|
|
|
list(REMOVE_ITEM libs_to_build tap-bridge)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Create library names to solve dependency problems with macros that will be
|
|
|
|
|
# called at each lib subdirectory
|
2021-11-10 22:28:44 -03:00
|
|
|
set(ns3-libs)
|
2021-12-05 21:53:49 +00:00
|
|
|
set(ns3-all-enabled-modules)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(ns3-libs-tests)
|
|
|
|
|
set(ns3-contrib-libs)
|
|
|
|
|
set(lib-ns3-static-objs)
|
|
|
|
|
set(ns3-external-libs)
|
|
|
|
|
set(ns3-python-bindings ns${NS3_VER}-pybindings${build_profile_suffix})
|
|
|
|
|
set(ns3-python-bindings-modules)
|
|
|
|
|
|
|
|
|
|
foreach(libname ${scanned_modules})
|
|
|
|
|
# Create libname of output library of module
|
|
|
|
|
library_target_name(${libname} targetname)
|
2021-12-05 21:53:49 +00:00
|
|
|
mark_as_advanced(lib${libname} lib${libname}-obj)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(lib${libname} ${targetname} CACHE INTERNAL "")
|
|
|
|
|
set(lib${libname}-obj ${targetname}-obj CACHE INTERNAL "")
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
unset(optional_visualizer_lib)
|
2022-01-28 14:20:44 -03:00
|
|
|
if(${ENABLE_VISUALIZER} AND (visualizer IN_LIST libs_to_build))
|
2021-11-10 22:28:44 -03:00
|
|
|
set(optional_visualizer_lib ${libvisualizer})
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
set(PRECOMPILE_HEADERS_ENABLED OFF)
|
2021-11-10 22:28:44 -03:00
|
|
|
if(${NS3_PRECOMPILE_HEADERS})
|
2022-09-20 16:00:03 -03:00
|
|
|
if(${NS3_CLANG_TIDY})
|
2022-09-24 13:16:05 -03:00
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Clang-tidy is incompatible with precompiled headers. Continuing without them."
|
|
|
|
|
)
|
2022-09-20 16:00:03 -03:00
|
|
|
elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
|
2022-11-30 12:35:51 -03:00
|
|
|
# If ccache is not enable or was not found, we can continue with
|
|
|
|
|
# precompiled headers
|
|
|
|
|
if((NOT ${NS3_CCACHE}) OR ("${CCACHE}" STREQUAL "CCACHE-NOTFOUND"))
|
2022-11-12 15:16:51 -03:00
|
|
|
set(PRECOMPILE_HEADERS_ENABLED ON)
|
|
|
|
|
message(STATUS "Precompiled headers were enabled")
|
|
|
|
|
else()
|
|
|
|
|
# If ccache was found, we need to check if it is ccache >= 4
|
|
|
|
|
execute_process(COMMAND ${CCACHE} -V OUTPUT_VARIABLE CCACHE_OUT)
|
|
|
|
|
# Extract ccache version
|
|
|
|
|
if(CCACHE_OUT MATCHES "ccache version ([0-9\.]*)")
|
|
|
|
|
# If an incompatible version is found, do not enable precompiled
|
|
|
|
|
# headers
|
|
|
|
|
if("${CMAKE_MATCH_1}" VERSION_LESS "4.0.0")
|
|
|
|
|
set(PRECOMPILE_HEADERS_ENABLED OFF)
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Precompiled headers are incompatible with ccache ${CMAKE_MATCH_1} and will be disabled."
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
set(PRECOMPILE_HEADERS_ENABLED ON)
|
|
|
|
|
message(STATUS "Precompiled headers were enabled.")
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"Failed to extract the ccache version while enabling precompiled headers."
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2021-12-05 21:53:49 +00:00
|
|
|
else()
|
|
|
|
|
message(
|
|
|
|
|
STATUS
|
|
|
|
|
"CMake ${CMAKE_VERSION} does not support precompiled headers. Continuing without them"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED})
|
2022-06-03 18:26:30 -03:00
|
|
|
if(CLANG)
|
|
|
|
|
# Clang adds a timestamp to the PCH, which prevents ccache from working
|
|
|
|
|
# correctly
|
|
|
|
|
# https://github.com/ccache/ccache/issues/539#issuecomment-664198545
|
|
|
|
|
add_definitions(-Xclang -fno-pch-timestamp)
|
|
|
|
|
endif()
|
|
|
|
|
if(${XCODE})
|
|
|
|
|
# XCode is weird and messes up with the PCH, requiring this flag
|
|
|
|
|
# https://github.com/ccache/ccache/issues/156
|
|
|
|
|
add_definitions(-Xclang -fno-validate-pch)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
set(precompiled_header_libraries
|
|
|
|
|
<algorithm>
|
|
|
|
|
<cstdlib>
|
|
|
|
|
<cstring>
|
2022-06-03 17:56:53 -03:00
|
|
|
<exception>
|
|
|
|
|
<fstream>
|
|
|
|
|
<iostream>
|
2021-11-10 22:28:44 -03:00
|
|
|
<limits>
|
2022-06-03 17:56:53 -03:00
|
|
|
<list>
|
|
|
|
|
<map>
|
2021-11-10 22:28:44 -03:00
|
|
|
<math.h>
|
2022-06-03 18:26:30 -03:00
|
|
|
<ostream>
|
2022-06-03 17:56:53 -03:00
|
|
|
<set>
|
|
|
|
|
<sstream>
|
|
|
|
|
<stdint.h>
|
|
|
|
|
<stdlib.h>
|
|
|
|
|
<string>
|
|
|
|
|
<unordered_map>
|
|
|
|
|
<vector>
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
2022-11-30 12:47:56 -03:00
|
|
|
add_library(
|
|
|
|
|
stdlib_pch${build_profile_suffix} OBJECT
|
|
|
|
|
${PROJECT_SOURCE_DIR}/build-support/empty.cc
|
|
|
|
|
)
|
2021-12-05 21:53:49 +00:00
|
|
|
target_precompile_headers(
|
2022-11-30 12:47:56 -03:00
|
|
|
stdlib_pch${build_profile_suffix} PUBLIC
|
|
|
|
|
"${precompiled_header_libraries}"
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2022-11-30 12:47:56 -03:00
|
|
|
add_library(stdlib_pch ALIAS stdlib_pch${build_profile_suffix})
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
add_executable(
|
2022-01-31 20:02:10 -03:00
|
|
|
stdlib_pch_exec ${PROJECT_SOURCE_DIR}/build-support/empty-main.cc
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
|
|
|
|
target_precompile_headers(
|
|
|
|
|
stdlib_pch_exec PUBLIC "${precompiled_header_libraries}"
|
|
|
|
|
)
|
|
|
|
|
set_runtime_outputdirectory(stdlib_pch_exec ${CMAKE_BINARY_DIR}/ "")
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Create new lib for NS3 static builds
|
|
|
|
|
set(lib-ns3-static ns${NS3_VER}-static${build_profile_suffix})
|
|
|
|
|
|
|
|
|
|
# Create a new lib for NS3 monolibrary shared builds
|
|
|
|
|
set(lib-ns3-monolib ns${NS3_VER}-monolib${build_profile_suffix})
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# All contrib libraries can be linked afterwards linking with
|
|
|
|
|
# ${ns3-contrib-libs}
|
2021-11-10 22:28:44 -03:00
|
|
|
process_contribution("${contrib_libs_to_build}")
|
|
|
|
|
|
|
|
|
|
# Netanim depends on ns-3 core, so we built it later
|
|
|
|
|
if(${NS3_NETANIM})
|
|
|
|
|
include(FetchContent)
|
2021-12-05 21:53:49 +00:00
|
|
|
FetchContent_Declare(
|
2022-02-09 20:59:27 -03:00
|
|
|
netanim GIT_REPOSITORY https://gitlab.com/nsnam/netanim.git
|
2023-03-17 09:58:40 +01:00
|
|
|
GIT_TAG netanim-3.109
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
FetchContent_Populate(netanim)
|
2022-01-31 20:02:10 -03:00
|
|
|
file(COPY build-support/3rd-party/netanim-cmakelists.cmake
|
2021-12-05 21:53:49 +00:00
|
|
|
DESTINATION ${netanim_SOURCE_DIR}
|
|
|
|
|
)
|
2022-01-31 20:02:10 -03:00
|
|
|
file(RENAME ${netanim_SOURCE_DIR}/netanim-cmakelists.cmake
|
2021-12-05 21:53:49 +00:00
|
|
|
${netanim_SOURCE_DIR}/CMakeLists.txt
|
|
|
|
|
)
|
2022-06-15 17:08:52 +02:00
|
|
|
add_subdirectory(${netanim_SOURCE_DIR} ${netanim_BINARY_DIR})
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2023-02-03 22:28:16 -03:00
|
|
|
|
|
|
|
|
if(${NS3_FETCH_OPTIONAL_COMPONENTS})
|
|
|
|
|
include(
|
|
|
|
|
build-support/custom-modules/ns3-fetch-optional-modules-dependencies.cmake
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endmacro()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
function(set_runtime_outputdirectory target_name output_directory target_prefix)
|
2022-09-03 02:07:36 -03:00
|
|
|
# Prevent duplicate '/' in EXECUTABLE_DIRECTORY_PATH, since it gets translated
|
|
|
|
|
# to doubled underlines and will cause the ns3 script to fail
|
|
|
|
|
string(REPLACE "//" "/" output_directory "${output_directory}")
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
set(ns3-exec-outputname ns${NS3_VER}-${target_name}${build_profile_suffix})
|
2021-12-05 21:53:49 +00:00
|
|
|
set(ns3-execs "${output_directory}${ns3-exec-outputname};${ns3-execs}"
|
|
|
|
|
CACHE INTERNAL "list of c++ executables"
|
|
|
|
|
)
|
2022-10-25 10:19:01 -03:00
|
|
|
set(ns3-execs-clean "${target_prefix}${target_name};${ns3-execs-clean}"
|
|
|
|
|
CACHE INTERNAL
|
|
|
|
|
"list of c++ executables without version prefix and build suffix"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
set_target_properties(
|
2021-12-05 21:53:49 +00:00
|
|
|
${target_prefix}${target_name}
|
|
|
|
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${output_directory}
|
|
|
|
|
RUNTIME_OUTPUT_NAME ${ns3-exec-outputname}
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
if(${XCODE})
|
2021-12-05 21:53:49 +00:00
|
|
|
# Is that so hard not to break people's CI, AAPL?? Why would you output the
|
|
|
|
|
# targets to a Debug/Release subfolder? Why?
|
2021-11-10 22:28:44 -03:00
|
|
|
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
|
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
|
|
|
|
|
set_target_properties(
|
2021-12-05 21:53:49 +00:00
|
|
|
${target_prefix}${target_name}
|
|
|
|
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${output_directory}
|
|
|
|
|
RUNTIME_OUTPUT_NAME_${OUTPUTCONFIG} ${ns3-exec-outputname}
|
2021-11-10 22:28:44 -03:00
|
|
|
)
|
|
|
|
|
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${ENABLE_TESTS})
|
2021-12-05 21:53:49 +00:00
|
|
|
add_dependencies(all-test-targets ${target_prefix}${target_name})
|
2022-01-31 20:02:10 -03:00
|
|
|
# Create a CTest entry for each executable
|
|
|
|
|
if(WIN32)
|
|
|
|
|
# Windows require this workaround to make sure the DLL files are located
|
|
|
|
|
add_test(
|
|
|
|
|
NAME ctest-${target_prefix}${target_name}
|
|
|
|
|
COMMAND
|
|
|
|
|
${CMAKE_COMMAND} -E env
|
|
|
|
|
"PATH=$ENV{PATH};${CMAKE_RUNTIME_OUTPUT_DIRECTORY};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
|
|
|
|
|
${ns3-exec-outputname}
|
|
|
|
|
WORKING_DIRECTORY ${output_directory}
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
add_test(NAME ctest-${target_prefix}${target_name}
|
|
|
|
|
COMMAND ${ns3-exec-outputname}
|
|
|
|
|
WORKING_DIRECTORY ${output_directory}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(${NS3_CLANG_TIMETRACE})
|
2021-12-05 21:53:49 +00:00
|
|
|
add_dependencies(timeTraceReport ${target_prefix}${target_name})
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endfunction(set_runtime_outputdirectory)
|
|
|
|
|
|
2023-01-30 15:54:35 -03:00
|
|
|
function(get_scratch_prefix prefix)
|
|
|
|
|
# /path/to/ns-3-dev/scratch/nested-subdir
|
|
|
|
|
set(temp ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
|
# remove /path/to/ns-3-dev/ to get scratch/nested-subdir
|
|
|
|
|
string(REPLACE "${PROJECT_SOURCE_DIR}/" "" temp "${temp}")
|
|
|
|
|
# replace path separators with underlines
|
|
|
|
|
string(REPLACE "/" "_" temp "${temp}")
|
|
|
|
|
# save the prefix value to the passed variable
|
|
|
|
|
set(${prefix} ${temp}_ PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2022-09-03 02:07:36 -03:00
|
|
|
function(build_exec)
|
|
|
|
|
# Argument parsing
|
2022-09-24 13:16:05 -03:00
|
|
|
set(options IGNORE_PCH STANDALONE)
|
2022-09-03 02:07:36 -03:00
|
|
|
set(oneValueArgs EXECNAME EXECNAME_PREFIX EXECUTABLE_DIRECTORY_PATH
|
|
|
|
|
INSTALL_DIRECTORY_PATH
|
|
|
|
|
)
|
|
|
|
|
set(multiValueArgs SOURCE_FILES HEADER_FILES LIBRARIES_TO_LINK DEFINITIONS)
|
|
|
|
|
cmake_parse_arguments(
|
|
|
|
|
"BEXEC" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
|
|
|
|
|
)
|
|
|
|
|
|
2023-01-30 15:54:35 -03:00
|
|
|
# Resolve nested scratch prefixes without user intervention
|
2023-04-27 14:23:45 -03:00
|
|
|
string(REPLACE "${PROJECT_SOURCE_DIR}" "" relative_path
|
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
|
|
|
|
)
|
|
|
|
|
if("${relative_path}" MATCHES "scratch" AND "${BEXEC_EXECNAME_PREFIX}"
|
|
|
|
|
STREQUAL ""
|
2023-01-30 15:54:35 -03:00
|
|
|
)
|
|
|
|
|
get_scratch_prefix(BEXEC_EXECNAME_PREFIX)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-03 02:07:36 -03:00
|
|
|
add_executable(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} "${BEXEC_SOURCE_FILES}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
target_compile_definitions(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} PUBLIC ${BEXEC_DEFINITIONS}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(${PRECOMPILE_HEADERS_ENABLED} AND (NOT ${BEXEC_IGNORE_PCH}))
|
|
|
|
|
target_precompile_headers(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} REUSE_FROM stdlib_pch_exec
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-24 13:16:05 -03:00
|
|
|
if(${NS3_STATIC} AND (NOT BEXEC_STANDALONE))
|
2022-09-03 02:07:36 -03:00
|
|
|
target_link_libraries(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE_STATIC}
|
|
|
|
|
${lib-ns3-static}
|
|
|
|
|
)
|
2022-09-24 13:16:05 -03:00
|
|
|
elseif(${NS3_MONOLIB} AND (NOT BEXEC_STANDALONE))
|
2022-09-03 02:07:36 -03:00
|
|
|
target_link_libraries(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE}
|
|
|
|
|
${lib-ns3-monolib} ${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
target_link_libraries(
|
|
|
|
|
${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME} ${LIB_AS_NEEDED_PRE}
|
|
|
|
|
"${BEXEC_LIBRARIES_TO_LINK}" ${LIB_AS_NEEDED_POST}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set_runtime_outputdirectory(
|
|
|
|
|
"${BEXEC_EXECNAME}" "${BEXEC_EXECUTABLE_DIRECTORY_PATH}/"
|
|
|
|
|
"${BEXEC_EXECNAME_PREFIX}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if(BEXEC_INSTALL_DIRECTORY_PATH)
|
|
|
|
|
install(TARGETS ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME}
|
|
|
|
|
EXPORT ns3ExportTargets
|
|
|
|
|
RUNTIME DESTINATION ${BEXEC_INSTALL_DIRECTORY_PATH}
|
|
|
|
|
)
|
|
|
|
|
get_property(
|
|
|
|
|
filename TARGET ${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME}
|
|
|
|
|
PROPERTY RUNTIME_OUTPUT_NAME
|
|
|
|
|
)
|
|
|
|
|
add_custom_target(
|
|
|
|
|
uninstall_${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME}
|
|
|
|
|
COMMAND
|
|
|
|
|
rm ${CMAKE_INSTALL_PREFIX}/${BEXEC_INSTALL_DIRECTORY_PATH}/${filename}
|
|
|
|
|
)
|
|
|
|
|
add_dependencies(
|
|
|
|
|
uninstall uninstall_${BEXEC_EXECNAME_PREFIX}${BEXEC_EXECNAME}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endfunction(build_exec)
|
|
|
|
|
|
2022-01-26 01:53:28 -03:00
|
|
|
function(scan_python_examples path)
|
2022-04-04 22:15:46 -03:00
|
|
|
# Skip python examples search in case the bindings are disabled
|
|
|
|
|
if(NOT ${ENABLE_PYTHON_BINDINGS})
|
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Search for python examples
|
2022-01-26 01:53:28 -03:00
|
|
|
file(GLOB_RECURSE python_examples ${path}/*.py)
|
|
|
|
|
foreach(python_example ${python_examples})
|
|
|
|
|
if(NOT (${python_example} MATCHES "examples-to-run"))
|
|
|
|
|
set(ns3-execs-py "${python_example};${ns3-execs-py}"
|
|
|
|
|
CACHE INTERNAL "list of python scripts"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
add_custom_target(copy_all_headers)
|
|
|
|
|
function(copy_headers_before_building_lib libname outputdir headers visibility)
|
|
|
|
|
foreach(header ${headers})
|
2022-03-17 14:30:35 -03:00
|
|
|
# Copy header to output directory on changes -> too darn slow
|
2022-03-19 12:57:05 -03:00
|
|
|
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${header} ${outputdir}/
|
|
|
|
|
# COPYONLY)
|
2022-03-17 14:30:35 -03:00
|
|
|
|
|
|
|
|
get_filename_component(
|
2022-03-19 12:57:05 -03:00
|
|
|
header_name ${CMAKE_CURRENT_SOURCE_DIR}/${header} NAME
|
2022-03-17 14:30:35 -03:00
|
|
|
)
|
2022-05-02 14:23:17 -03:00
|
|
|
|
2022-09-20 16:00:03 -03:00
|
|
|
# If output directory does not exist, create it
|
|
|
|
|
if(NOT (EXISTS ${outputdir}))
|
|
|
|
|
file(MAKE_DIRECTORY ${outputdir})
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-05-02 14:23:17 -03:00
|
|
|
# If header already exists, skip symlinking/stub header creation
|
|
|
|
|
if(EXISTS ${outputdir}/${header_name})
|
|
|
|
|
continue()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-09-20 16:00:03 -03:00
|
|
|
# Create a stub header in the output directory, including the real header
|
|
|
|
|
# inside their respective module
|
|
|
|
|
get_filename_component(
|
|
|
|
|
ABSOLUTE_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${header}" ABSOLUTE
|
|
|
|
|
)
|
|
|
|
|
file(WRITE ${outputdir}/${header_name}
|
|
|
|
|
"#include \"${ABSOLUTE_HEADER_PATH}\"\n"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endforeach()
|
|
|
|
|
endfunction(copy_headers_before_building_lib)
|
|
|
|
|
|
2022-03-16 22:44:30 -03:00
|
|
|
function(remove_lib_prefix prefixed_library library)
|
2022-03-18 14:04:00 -03:00
|
|
|
# Check if there is a lib prefix
|
|
|
|
|
string(FIND "${prefixed_library}" "lib" lib_pos)
|
|
|
|
|
|
|
|
|
|
# If there is a lib prefix, try to remove it
|
|
|
|
|
if(${lib_pos} EQUAL 0)
|
2022-03-25 22:31:56 -03:00
|
|
|
# Check if we still have something remaining after removing the "lib" prefix
|
2022-03-18 14:04:00 -03:00
|
|
|
string(LENGTH ${prefixed_library} len)
|
|
|
|
|
if(${len} LESS 4)
|
|
|
|
|
message(FATAL_ERROR "Invalid library name: ${prefixed_library}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Remove lib prefix from module name (e.g. libcore -> core)
|
|
|
|
|
string(SUBSTRING "${prefixed_library}" 3 -1 unprefixed_library)
|
|
|
|
|
else()
|
|
|
|
|
set(unprefixed_library ${prefixed_library})
|
2022-03-16 22:44:30 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-03-18 14:04:00 -03:00
|
|
|
# Save the unprefixed library name to the parent scope
|
|
|
|
|
set(${library} ${unprefixed_library} PARENT_SCOPE)
|
2022-03-16 22:44:30 -03:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(check_for_missing_libraries output_variable_name libraries)
|
|
|
|
|
set(missing_dependencies)
|
|
|
|
|
foreach(lib ${libraries})
|
|
|
|
|
# skip check for ns-3 modules if its a path to a library
|
|
|
|
|
if(EXISTS ${lib})
|
|
|
|
|
continue()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# check if the example depends on disabled modules
|
|
|
|
|
remove_lib_prefix("${lib}" lib)
|
|
|
|
|
|
2022-03-17 18:52:23 -03:00
|
|
|
# Check if the module exists in the ns-3 modules list or if it is a
|
|
|
|
|
# 3rd-party library
|
2022-03-16 22:44:30 -03:00
|
|
|
if(NOT (${lib} IN_LIST ns3-all-enabled-modules))
|
|
|
|
|
list(APPEND missing_dependencies ${lib})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${output_variable_name} ${missing_dependencies} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# Import macros used for modules and define specialized versions for src modules
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-module-macros.cmake)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
# Contrib modules counterparts of macros above
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-contributions.cmake)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
# Macro to build examples in ns-3-dev/examples/
|
2022-01-27 11:40:41 -03:00
|
|
|
macro(build_example)
|
2022-09-03 02:07:36 -03:00
|
|
|
set(options IGNORE_PCH)
|
2022-01-27 11:40:41 -03:00
|
|
|
set(oneValueArgs NAME)
|
|
|
|
|
set(multiValueArgs SOURCE_FILES HEADER_FILES LIBRARIES_TO_LINK)
|
2022-02-09 20:59:27 -03:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
"EXAMPLE" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
|
|
|
|
|
)
|
2022-01-27 11:40:41 -03:00
|
|
|
|
2022-09-17 16:33:08 -03:00
|
|
|
# Filter examples out if they don't contain one of the filtered in modules
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
if(NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
set(filtered_in OFF)
|
|
|
|
|
foreach(filtered_module NS3_FILTER_MODULE_EXAMPLES_AND_TESTS)
|
|
|
|
|
if(${filtered_module} IN_LIST EXAMPLE_LIBRARIES_TO_LINK)
|
|
|
|
|
set(filtered_in ON)
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-03-17 18:52:23 -03:00
|
|
|
check_for_missing_libraries(
|
|
|
|
|
missing_dependencies "${EXAMPLE_LIBRARIES_TO_LINK}"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2022-09-17 16:33:08 -03:00
|
|
|
if((NOT missing_dependencies) AND ${filtered_in})
|
2022-09-03 02:07:36 -03:00
|
|
|
# Convert boolean into text to forward argument
|
|
|
|
|
if(${EXAMPLE_IGNORE_PCH})
|
|
|
|
|
set(IGNORE_PCH IGNORE_PCH)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
2022-09-03 02:07:36 -03:00
|
|
|
# Create example library with sources and headers
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
build_exec(
|
|
|
|
|
EXECNAME ${EXAMPLE_NAME}
|
|
|
|
|
SOURCE_FILES ${EXAMPLE_SOURCE_FILES}
|
|
|
|
|
HEADER_FILES ${EXAMPLE_HEADER_FILES}
|
|
|
|
|
LIBRARIES_TO_LINK ${EXAMPLE_LIBRARIES_TO_LINK} ${optional_visualizer_lib}
|
|
|
|
|
EXECUTABLE_DIRECTORY_PATH
|
|
|
|
|
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples/${examplefolder}/
|
|
|
|
|
${IGNORE_PCH}
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2022-09-03 02:07:36 -03:00
|
|
|
# cmake-format: on
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
function(filter_modules modules_to_filter all_modules_list filter_in)
|
|
|
|
|
set(new_modules_to_build)
|
2021-12-10 02:13:43 +00:00
|
|
|
# We are receiving variable names as arguments, so we have to "dereference"
|
2021-12-05 21:53:49 +00:00
|
|
|
# them first That is why we have the duplicated ${${}}
|
2021-11-10 22:28:44 -03:00
|
|
|
foreach(module ${${all_modules_list}})
|
|
|
|
|
if(${filter_in} (${module} IN_LIST ${modules_to_filter}))
|
|
|
|
|
list(APPEND new_modules_to_build ${module})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${all_modules_list} ${new_modules_to_build} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(resolve_dependencies module_name dependencies contrib_dependencies)
|
|
|
|
|
# Create cache variables to hold dependencies list and visited
|
|
|
|
|
set(dependency_visited "" CACHE INTERNAL "")
|
|
|
|
|
set(contrib_dependency_visited "" CACHE INTERNAL "")
|
|
|
|
|
recursive_dependency(${module_name})
|
|
|
|
|
if(${module_name} IN_LIST dependency_visited)
|
|
|
|
|
set(temp ${dependency_visited})
|
|
|
|
|
list(REMOVE_AT temp 0)
|
|
|
|
|
set(${dependencies} ${temp} PARENT_SCOPE)
|
|
|
|
|
set(${contrib_dependencies} ${contrib_dependency_visited} PARENT_SCOPE)
|
|
|
|
|
else()
|
|
|
|
|
set(temp ${contrib_dependency_visited})
|
|
|
|
|
list(REMOVE_AT temp 0)
|
|
|
|
|
set(${dependencies} ${dependency_visited} PARENT_SCOPE)
|
|
|
|
|
set(${contrib_dependencies} ${temp} PARENT_SCOPE)
|
|
|
|
|
endif()
|
|
|
|
|
unset(dependency_visited CACHE)
|
|
|
|
|
unset(contrib_dependency_visited CACHE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(filter_libraries cmakelists_contents libraries)
|
|
|
|
|
string(REGEX MATCHALL "{lib[^}]*[^obj]}" matches "${cmakelists_content}")
|
|
|
|
|
list(REMOVE_ITEM matches "{libraries_to_link}")
|
2021-12-10 02:13:43 +00:00
|
|
|
string(REPLACE "{lib\${name" "" matches "${matches}") # special case for
|
|
|
|
|
# src/test
|
2021-11-10 22:28:44 -03:00
|
|
|
string(REPLACE "{lib" "" matches "${matches}")
|
|
|
|
|
string(REPLACE "}" "" matches "${matches}")
|
|
|
|
|
set(${libraries} ${matches} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(recursive_dependency module_name)
|
|
|
|
|
# Read module CMakeLists.txt and search for ns-3 modules
|
|
|
|
|
set(src_cmakelist ${PROJECT_SOURCE_DIR}/src/${module_name}/CMakeLists.txt)
|
2021-12-05 21:53:49 +00:00
|
|
|
set(contrib_cmakelist
|
|
|
|
|
${PROJECT_SOURCE_DIR}/contrib/${module_name}/CMakeLists.txt
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
set(contrib FALSE)
|
|
|
|
|
if(EXISTS ${src_cmakelist})
|
|
|
|
|
file(READ ${src_cmakelist} cmakelists_content)
|
|
|
|
|
elseif(EXISTS ${contrib_cmakelist})
|
|
|
|
|
file(READ ${contrib_cmakelist} cmakelists_content)
|
|
|
|
|
set(contrib TRUE)
|
|
|
|
|
else()
|
2022-01-23 17:30:08 -03:00
|
|
|
set(cmakelists_content "")
|
2022-03-19 12:57:05 -03:00
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"The CMakeLists.txt file for module ${module_name} was not found."
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2022-01-23 17:30:08 -03:00
|
|
|
filter_libraries("${cmakelists_content}" matches)
|
2021-11-10 22:28:44 -03:00
|
|
|
|
|
|
|
|
# Add this visited module dependencies to the dependencies list
|
|
|
|
|
if(contrib)
|
2021-12-05 21:53:49 +00:00
|
|
|
set(contrib_dependency_visited
|
|
|
|
|
"${contrib_dependency_visited};${module_name}" CACHE INTERNAL ""
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(examples_cmakelists ${contrib_cmakelist})
|
2021-11-10 22:28:44 -03:00
|
|
|
else()
|
2021-12-05 21:53:49 +00:00
|
|
|
set(dependency_visited "${dependency_visited};${module_name}" CACHE INTERNAL
|
|
|
|
|
""
|
|
|
|
|
)
|
2021-12-10 02:13:43 +00:00
|
|
|
set(examples_cmakelists ${src_cmakelist})
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
# Scan dependencies required by this module examples
|
2021-12-10 02:13:43 +00:00
|
|
|
#if(${ENABLE_EXAMPLES})
|
|
|
|
|
# string(REPLACE "${module_name}" "${module_name}/examples" examples_cmakelists ${examples_cmakelists})
|
|
|
|
|
# if(EXISTS ${examples_cmakelists})
|
|
|
|
|
# file(READ ${examples_cmakelists} cmakelists_content)
|
2021-11-10 22:28:44 -03:00
|
|
|
# filter_libraries(${cmakelists_content} example_matches)
|
|
|
|
|
# endif()
|
|
|
|
|
#endif()
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
|
|
|
|
|
# For each dependency, call this same function
|
|
|
|
|
set(matches "${matches};${example_matches}")
|
|
|
|
|
foreach(match ${matches})
|
2021-12-05 21:53:49 +00:00
|
|
|
if(NOT ((${match} IN_LIST dependency_visited)
|
|
|
|
|
OR (${match} IN_LIST contrib_dependency_visited))
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
recursive_dependency(${match})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2022-07-21 22:15:19 -03:00
|
|
|
macro(
|
|
|
|
|
filter_enabled_and_disabled_modules
|
|
|
|
|
libs_to_build
|
|
|
|
|
contrib_libs_to_build
|
|
|
|
|
NS3_ENABLED_MODULES
|
|
|
|
|
NS3_DISABLED_MODULES
|
|
|
|
|
ns3rc_enabled_modules
|
|
|
|
|
ns3rc_disabled_modules
|
2021-12-05 21:53:49 +00:00
|
|
|
)
|
|
|
|
|
mark_as_advanced(ns3-all-enabled-modules)
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
# Before filtering, we set a variable with all scanned modules in the src
|
2021-12-05 21:53:49 +00:00
|
|
|
# directory
|
2021-11-10 22:28:44 -03:00
|
|
|
set(scanned_modules ${${libs_to_build}})
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
# Ensure enabled and disable modules lists are using semicolons
|
|
|
|
|
string(REPLACE "," ";" ${NS3_ENABLED_MODULES} "${${NS3_ENABLED_MODULES}}")
|
|
|
|
|
string(REPLACE "," ";" ${NS3_DISABLED_MODULES} "${${NS3_DISABLED_MODULES}}")
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Now that scanning modules finished, we can remove the disabled modules or
|
|
|
|
|
# replace the modules list with the ones in the enabled list
|
|
|
|
|
if(${NS3_ENABLED_MODULES} OR ${ns3rc_enabled_modules})
|
|
|
|
|
# List of enabled modules passed by the command line overwrites list read
|
|
|
|
|
# from ns3rc
|
2021-12-10 02:13:43 +00:00
|
|
|
if(${NS3_ENABLED_MODULES})
|
2021-12-05 21:53:49 +00:00
|
|
|
set(ns3rc_enabled_modules ${${NS3_ENABLED_MODULES}})
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# Filter enabled modules
|
2021-12-05 21:53:49 +00:00
|
|
|
filter_modules(ns3rc_enabled_modules libs_to_build "")
|
|
|
|
|
filter_modules(ns3rc_enabled_modules contrib_libs_to_build "")
|
2021-11-10 22:28:44 -03:00
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
# Use recursion to automatically determine dependencies required by the
|
|
|
|
|
# manually enabled modules
|
2021-11-10 22:28:44 -03:00
|
|
|
foreach(lib ${${contrib_libs_to_build}})
|
|
|
|
|
resolve_dependencies(${lib} dependencies contrib_dependencies)
|
|
|
|
|
list(APPEND ${contrib_libs_to_build} "${contrib_dependencies}")
|
|
|
|
|
list(APPEND ${libs_to_build} "${dependencies}")
|
|
|
|
|
unset(dependencies)
|
|
|
|
|
unset(contrib_dependencies)
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
foreach(lib ${${libs_to_build}})
|
|
|
|
|
resolve_dependencies(${lib} dependencies contrib_dependencies)
|
|
|
|
|
list(APPEND ${libs_to_build} "${dependencies}")
|
|
|
|
|
unset(dependencies)
|
|
|
|
|
unset(contrib_dependencies)
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-07-21 22:15:19 -03:00
|
|
|
if(${NS3_DISABLED_MODULES} OR ${ns3rc_disabled_modules})
|
|
|
|
|
# List of disabled modules passed by the command line overwrites list read
|
|
|
|
|
# from ns3rc
|
|
|
|
|
|
|
|
|
|
if(${NS3_DISABLED_MODULES})
|
|
|
|
|
set(ns3rc_disabled_modules ${${NS3_DISABLED_MODULES}})
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-12-10 02:13:43 +00:00
|
|
|
set(all_libs ${${libs_to_build}};${${contrib_libs_to_build}})
|
|
|
|
|
|
|
|
|
|
# We then use the recursive dependency finding to get all dependencies of
|
|
|
|
|
# all modules
|
|
|
|
|
foreach(lib ${all_libs})
|
|
|
|
|
resolve_dependencies(${lib} dependencies contrib_dependencies)
|
|
|
|
|
set(${lib}_dependencies "${dependencies};${contrib_dependencies}")
|
|
|
|
|
unset(dependencies)
|
|
|
|
|
unset(contrib_dependencies)
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Now we can begin removing libraries that require disabled dependencies
|
2022-07-21 22:15:19 -03:00
|
|
|
set(disabled_libs "${${ns3rc_disabled_modules}}")
|
2021-12-10 02:13:43 +00:00
|
|
|
foreach(libo ${all_libs})
|
|
|
|
|
foreach(lib ${all_libs})
|
|
|
|
|
foreach(disabled_lib ${disabled_libs})
|
|
|
|
|
if(${lib} STREQUAL ${disabled_lib})
|
|
|
|
|
continue()
|
|
|
|
|
endif()
|
|
|
|
|
if(${disabled_lib} IN_LIST ${lib}_dependencies)
|
|
|
|
|
list(APPEND disabled_libs ${lib})
|
|
|
|
|
break() # proceed to the next lib in all_libs
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Clean dependencies lists
|
|
|
|
|
foreach(lib ${all_libs})
|
|
|
|
|
unset(${lib}_dependencies)
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# We can filter out disabled modules
|
|
|
|
|
filter_modules(disabled_libs libs_to_build "NOT")
|
|
|
|
|
filter_modules(disabled_libs contrib_libs_to_build "NOT")
|
|
|
|
|
|
|
|
|
|
if(core IN_LIST ${libs_to_build})
|
|
|
|
|
list(APPEND ${libs_to_build} test) # include test module
|
|
|
|
|
endif()
|
2021-11-10 22:28:44 -03:00
|
|
|
endif()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Older CMake versions require this workaround for empty lists
|
|
|
|
|
if(NOT ${contrib_libs_to_build})
|
|
|
|
|
set(${contrib_libs_to_build} "")
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-11-10 22:28:44 -03:00
|
|
|
# Filter out any eventual duplicates
|
|
|
|
|
list(REMOVE_DUPLICATES ${libs_to_build})
|
|
|
|
|
list(REMOVE_DUPLICATES ${contrib_libs_to_build})
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Export list with all enabled modules (used to separate ns libraries from
|
|
|
|
|
# non-ns libraries in ns3_module_macros)
|
|
|
|
|
set(ns3-all-enabled-modules "${${libs_to_build}};${${contrib_libs_to_build}}"
|
|
|
|
|
CACHE INTERNAL "list with all enabled modules"
|
|
|
|
|
)
|
2021-11-10 22:28:44 -03:00
|
|
|
endmacro()
|
|
|
|
|
|
2021-12-05 21:53:49 +00:00
|
|
|
# Parse .ns3rc
|
2022-07-21 22:15:19 -03:00
|
|
|
macro(parse_ns3rc enabled_modules disabled_modules examples_enabled
|
|
|
|
|
tests_enabled
|
|
|
|
|
)
|
|
|
|
|
# Try to find .ns3rc
|
|
|
|
|
find_file(NS3RC .ns3rc PATHS /etc $ENV{HOME} $ENV{USERPROFILE}
|
|
|
|
|
${PROJECT_SOURCE_DIR} NO_CACHE
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Set variables with default values (all modules, no examples nor tests)
|
|
|
|
|
set(${enabled_modules} "")
|
|
|
|
|
set(${disabled_modules} "")
|
|
|
|
|
set(${examples_enabled} "FALSE")
|
|
|
|
|
set(${tests_enabled} "FALSE")
|
2022-05-11 16:01:48 -03:00
|
|
|
|
2022-07-21 22:15:19 -03:00
|
|
|
if(NOT (${NS3RC} STREQUAL "NS3RC-NOTFOUND"))
|
|
|
|
|
message(${HIGHLIGHTED_STATUS}
|
|
|
|
|
"Configuration file .ns3rc being used : ${NS3RC}"
|
|
|
|
|
)
|
|
|
|
|
file(READ ${NS3RC} ns3rc_contents)
|
|
|
|
|
# Check if ns3rc file is CMake or Python based and act accordingly
|
|
|
|
|
if(ns3rc_contents MATCHES "ns3rc_*")
|
|
|
|
|
include(${NS3RC})
|
|
|
|
|
else()
|
|
|
|
|
parse_python_ns3rc(
|
|
|
|
|
"${ns3rc_contents}" ${enabled_modules} ${examples_enabled}
|
|
|
|
|
${tests_enabled} ${NS3RC}
|
|
|
|
|
)
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
2022-07-21 22:15:19 -03:00
|
|
|
endif()
|
|
|
|
|
endmacro(parse_ns3rc)
|
2021-12-05 21:53:49 +00:00
|
|
|
|
2022-07-21 22:15:19 -03:00
|
|
|
function(parse_python_ns3rc ns3rc_contents enabled_modules examples_enabled
|
|
|
|
|
tests_enabled ns3rc_location
|
|
|
|
|
)
|
|
|
|
|
# Save .ns3rc backup
|
|
|
|
|
file(WRITE ${ns3rc_location}.backup ${ns3rc_contents})
|
|
|
|
|
|
|
|
|
|
# Match modules_enabled list
|
|
|
|
|
if(ns3rc_contents MATCHES "modules_enabled.*\\[(.*).*\\]")
|
|
|
|
|
set(${enabled_modules} ${CMAKE_MATCH_1})
|
|
|
|
|
if(${enabled_modules} MATCHES "all_modules")
|
|
|
|
|
# If all modules, just clean the filter and all modules will get built by
|
|
|
|
|
# default
|
|
|
|
|
set(${enabled_modules})
|
|
|
|
|
else()
|
|
|
|
|
# If modules are listed, remove quotes and replace commas with semicolons
|
|
|
|
|
# transforming a string into a cmake list
|
|
|
|
|
string(REPLACE "," ";" ${enabled_modules} "${${enabled_modules}}")
|
|
|
|
|
string(REPLACE "'" "" ${enabled_modules} "${${enabled_modules}}")
|
|
|
|
|
string(REPLACE "\"" "" ${enabled_modules} "${${enabled_modules}}")
|
|
|
|
|
string(REPLACE " " "" ${enabled_modules} "${${enabled_modules}}")
|
|
|
|
|
string(REPLACE "\n" ";" ${enabled_modules} "${${enabled_modules}}")
|
|
|
|
|
list(SORT ${enabled_modules})
|
|
|
|
|
|
|
|
|
|
# Remove possibly empty entry
|
|
|
|
|
list(REMOVE_ITEM ${enabled_modules} "")
|
|
|
|
|
foreach(element ${${enabled_modules}})
|
|
|
|
|
# Inspect each element for comments
|
|
|
|
|
if(${element} MATCHES "#.*")
|
|
|
|
|
list(REMOVE_ITEM ${enabled_modules} ${element})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
2022-07-21 22:15:19 -03:00
|
|
|
endif()
|
2021-12-05 21:53:49 +00:00
|
|
|
|
2022-07-21 22:15:19 -03:00
|
|
|
string(REPLACE "True" "ON" ns3rc_contents ${ns3rc_contents})
|
|
|
|
|
string(REPLACE "False" "OFF" ns3rc_contents ${ns3rc_contents})
|
|
|
|
|
|
|
|
|
|
# Match examples_enabled flag
|
|
|
|
|
if(ns3rc_contents MATCHES "examples_enabled = (ON|OFF)")
|
|
|
|
|
set(${examples_enabled} ${CMAKE_MATCH_1})
|
2021-12-05 21:53:49 +00:00
|
|
|
endif()
|
2022-07-21 22:15:19 -03:00
|
|
|
|
|
|
|
|
# Match tests_enabled flag
|
|
|
|
|
if(ns3rc_contents MATCHES "tests_enabled = (ON|OFF)")
|
|
|
|
|
set(${tests_enabled} ${CMAKE_MATCH_1})
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Save variables to parent scope
|
|
|
|
|
set(${enabled_modules} "${${enabled_modules}}" PARENT_SCOPE)
|
|
|
|
|
set(${examples_enabled} "${${examples_enabled}}" PARENT_SCOPE)
|
|
|
|
|
set(${tests_enabled} "${${tests_enabled}}" PARENT_SCOPE)
|
|
|
|
|
|
|
|
|
|
# Save updated .ns3rc file
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
|
|
|
|
"The python-based .ns3rc file format is deprecated and was updated to the CMake format"
|
|
|
|
|
)
|
|
|
|
|
configure_file(
|
|
|
|
|
${PROJECT_SOURCE_DIR}/build-support/.ns3rc-template ${ns3rc_location} @ONLY
|
|
|
|
|
)
|
|
|
|
|
endfunction(parse_python_ns3rc)
|
2021-12-05 21:53:49 +00:00
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
function(log_find_searched_paths)
|
|
|
|
|
# Parse arguments
|
|
|
|
|
set(options)
|
|
|
|
|
set(oneValueArgs TARGET_TYPE TARGET_NAME SEARCH_RESULT SEARCH_SYSTEM_PREFIX)
|
|
|
|
|
set(multiValueArgs SEARCH_PATHS SEARCH_SUFFIXES)
|
|
|
|
|
cmake_parse_arguments(
|
|
|
|
|
"LOGFIND" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Get searched paths and add cmake_system_prefix_path if not explicitly marked
|
|
|
|
|
# not to include it
|
|
|
|
|
set(tsearch_paths ${LOGFIND_SEARCH_PATHS})
|
|
|
|
|
if("${LOGFIND_SEARCH_SYSTEM_PREFIX}" STREQUAL "")
|
|
|
|
|
list(APPEND tsearch_paths "${CMAKE_SYSTEM_PREFIX_PATH}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set(log_find
|
|
|
|
|
"Looking for ${LOGFIND_TARGET_TYPE} ${LOGFIND_TARGET_NAME} in:\n"
|
|
|
|
|
)
|
|
|
|
|
# For each search path and suffix combination, print a line
|
|
|
|
|
foreach(tsearch_path ${tsearch_paths})
|
|
|
|
|
foreach(suffix ${LOGFIND_SEARCH_SUFFIXES})
|
|
|
|
|
string(APPEND log_find
|
|
|
|
|
"\t${tsearch_path}${suffix}/${LOGFIND_TARGET_NAME}\n"
|
|
|
|
|
)
|
|
|
|
|
endforeach()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
|
|
# Add a final line saying if the file was found and where, or if it was not
|
|
|
|
|
# found
|
|
|
|
|
if("${${LOGFIND_SEARCH_RESULT}}" STREQUAL "${LOGFIND_SEARCH_RESULT}-NOTFOUND")
|
|
|
|
|
string(APPEND log_find
|
|
|
|
|
"\n\t${LOGFIND_TARGET_TYPE} ${LOGFIND_TARGET_NAME} was not found\n"
|
|
|
|
|
)
|
|
|
|
|
else()
|
|
|
|
|
string(
|
|
|
|
|
APPEND
|
|
|
|
|
log_find
|
|
|
|
|
"\n\t${LOGFIND_TARGET_TYPE} ${LOGFIND_TARGET_NAME} was found in ${${LOGFIND_SEARCH_RESULT}}\n"
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Replace duplicate path separators
|
|
|
|
|
string(REPLACE "//" "/" log_find "${log_find}")
|
|
|
|
|
|
|
|
|
|
# Print find debug message similar to the one produced by
|
|
|
|
|
# CMAKE_FIND_DEBUG_MODE=true in CMake >= 3.17
|
|
|
|
|
message(STATUS ${log_find})
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2022-02-09 20:59:27 -03:00
|
|
|
function(find_external_library)
|
2022-03-02 11:28:59 -03:00
|
|
|
# Parse arguments
|
|
|
|
|
set(options QUIET)
|
2022-01-28 19:31:35 -03:00
|
|
|
set(oneValueArgs DEPENDENCY_NAME HEADER_NAME LIBRARY_NAME)
|
2022-01-31 13:55:48 +00:00
|
|
|
set(multiValueArgs HEADER_NAMES LIBRARY_NAMES PATH_SUFFIXES SEARCH_PATHS)
|
2022-02-09 20:59:27 -03:00
|
|
|
cmake_parse_arguments(
|
|
|
|
|
"FIND_LIB" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
|
|
|
|
|
)
|
2022-01-28 19:31:35 -03:00
|
|
|
|
2022-03-02 11:28:59 -03:00
|
|
|
# Set the external package/dependency name
|
2022-01-28 19:31:35 -03:00
|
|
|
set(name ${FIND_LIB_DEPENDENCY_NAME})
|
2022-03-02 11:28:59 -03:00
|
|
|
|
|
|
|
|
# We process individual and list of headers and libraries by transforming them
|
|
|
|
|
# into lists
|
2022-01-31 13:55:48 +00:00
|
|
|
set(library_names "${FIND_LIB_LIBRARY_NAME};${FIND_LIB_LIBRARY_NAMES}")
|
|
|
|
|
set(header_names "${FIND_LIB_HEADER_NAME};${FIND_LIB_HEADER_NAMES}")
|
2022-03-02 11:28:59 -03:00
|
|
|
|
|
|
|
|
# Just changing the parsed argument name back to something shorter
|
2022-01-28 19:31:35 -03:00
|
|
|
set(search_paths ${FIND_LIB_SEARCH_PATHS})
|
2022-01-31 13:55:48 +00:00
|
|
|
set(path_suffixes "${FIND_LIB_PATH_SUFFIXES}")
|
|
|
|
|
|
|
|
|
|
set(not_found_libraries)
|
|
|
|
|
set(library_dirs)
|
|
|
|
|
set(libraries)
|
2022-10-15 21:10:52 +01:00
|
|
|
|
2022-10-13 23:54:47 -03:00
|
|
|
# Include parent directories in the search paths to handle Bake cases
|
|
|
|
|
get_filename_component(parent_project_dir ${PROJECT_SOURCE_DIR} DIRECTORY)
|
2022-10-12 01:40:34 -03:00
|
|
|
get_filename_component(
|
|
|
|
|
grandparent_project_dir ${parent_project_dir} DIRECTORY
|
|
|
|
|
)
|
2022-10-13 23:54:47 -03:00
|
|
|
set(project_parent_dirs ${parent_project_dir} ${grandparent_project_dir})
|
2022-10-15 21:10:52 +01:00
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
# Paths and suffixes where libraries will be searched on
|
|
|
|
|
set(library_search_paths
|
|
|
|
|
${search_paths}
|
2022-10-13 23:54:47 -03:00
|
|
|
${project_parent_dirs}
|
2022-03-02 11:51:53 -03:00
|
|
|
${CMAKE_OUTPUT_DIRECTORY} # Search for libraries in ns-3-dev/build
|
|
|
|
|
${CMAKE_INSTALL_PREFIX} # Search for libraries in the install directory
|
|
|
|
|
# (e.g. /usr/)
|
|
|
|
|
$ENV{LD_LIBRARY_PATH} # Search for libraries in LD_LIBRARY_PATH
|
|
|
|
|
# directories
|
|
|
|
|
$ENV{PATH} # Search for libraries in PATH directories
|
|
|
|
|
)
|
2022-06-10 01:18:33 -03:00
|
|
|
# cmake-format: off
|
|
|
|
|
#
|
|
|
|
|
# Split : separated entries from environment variables
|
|
|
|
|
# by replacing separators with ;
|
|
|
|
|
#
|
|
|
|
|
# cmake-format: on
|
2022-06-09 19:23:54 -03:00
|
|
|
string(REPLACE ":" ";" library_search_paths "${library_search_paths}")
|
|
|
|
|
|
2022-03-02 11:51:53 -03:00
|
|
|
set(suffixes /build /lib /build/lib / /bin ${path_suffixes})
|
|
|
|
|
|
2022-03-02 11:28:59 -03:00
|
|
|
# For each of the library names in LIBRARY_NAMES or LIBRARY_NAME
|
2022-01-31 13:55:48 +00:00
|
|
|
foreach(library ${library_names})
|
2022-03-02 11:28:59 -03:00
|
|
|
# We mark this value is advanced not to pollute the configuration with
|
|
|
|
|
# ccmake with the cache variables used internally
|
2022-01-31 13:55:48 +00:00
|
|
|
mark_as_advanced(${name}_library_internal_${library})
|
2022-03-02 11:28:59 -03:00
|
|
|
|
|
|
|
|
# We search for the library named ${library} and store the results in
|
|
|
|
|
# ${name}_library_internal_${library}
|
2022-01-31 13:55:48 +00:00
|
|
|
find_library(
|
|
|
|
|
${name}_library_internal_${library} ${library}
|
2022-03-02 11:51:53 -03:00
|
|
|
HINTS ${library_search_paths} PATH_SUFFIXES ${suffixes}
|
2022-02-09 20:59:27 -03:00
|
|
|
)
|
2022-03-02 11:51:53 -03:00
|
|
|
# cmake-format: off
|
2022-03-02 11:28:59 -03:00
|
|
|
# Note: the PATH_SUFFIXES above apply to *ALL* PATHS and HINTS Which
|
|
|
|
|
# translates to CMake searching on standard library directories
|
|
|
|
|
# CMAKE_SYSTEM_PREFIX_PATH, user-settable CMAKE_PREFIX_PATH or
|
|
|
|
|
# CMAKE_LIBRARY_PATH and the directories listed above
|
|
|
|
|
#
|
|
|
|
|
# e.g. from Ubuntu 22.04 CMAKE_SYSTEM_PREFIX_PATH =
|
|
|
|
|
# /usr/local;/usr;/;/usr/local;/usr/X11R6;/usr/pkg;/opt
|
|
|
|
|
#
|
|
|
|
|
# Searched directories without suffixes
|
|
|
|
|
#
|
|
|
|
|
# ${CMAKE_SYSTEM_PREFIX_PATH}[0] = /usr/local/
|
2022-03-02 11:51:53 -03:00
|
|
|
# ${CMAKE_SYSTEM_PREFIX_PATH}[1] = /usr
|
|
|
|
|
# ${CMAKE_SYSTEM_PREFIX_PATH}[2] = /
|
|
|
|
|
# ...
|
|
|
|
|
# ${CMAKE_SYSTEM_PREFIX_PATH}[6] = /opt
|
|
|
|
|
# ${LD_LIBRARY_PATH}[0]
|
|
|
|
|
# ...
|
|
|
|
|
# ${LD_LIBRARY_PATH}[m]
|
|
|
|
|
# ${PATH}[0]
|
|
|
|
|
# ...
|
|
|
|
|
# ${PATH}[m]
|
2022-03-02 11:28:59 -03:00
|
|
|
#
|
|
|
|
|
# Searched directories with suffixes include all of the directories above
|
2022-03-02 11:51:53 -03:00
|
|
|
# plus all suffixes
|
|
|
|
|
# PATH_SUFFIXES /build /lib /build/lib / /bin # ${path_suffixes}
|
2022-03-02 11:28:59 -03:00
|
|
|
#
|
2022-03-02 11:51:53 -03:00
|
|
|
# /usr/local/build
|
|
|
|
|
# /usr/local/lib
|
|
|
|
|
# /usr/local/build/lib
|
|
|
|
|
# /usr/local/bin
|
|
|
|
|
# ...
|
2022-03-02 11:28:59 -03:00
|
|
|
#
|
2022-03-02 11:51:53 -03:00
|
|
|
# cmake-format: on
|
|
|
|
|
# Or enable NS3_VERBOSE to print the searched paths
|
|
|
|
|
|
|
|
|
|
# Print tested paths to the searched library and if it was found
|
|
|
|
|
if(${NS3_VERBOSE} AND (${CMAKE_VERSION} VERSION_LESS "3.17.0"))
|
|
|
|
|
log_find_searched_paths(
|
|
|
|
|
TARGET_TYPE
|
|
|
|
|
Library
|
|
|
|
|
TARGET_NAME
|
|
|
|
|
${library}
|
|
|
|
|
SEARCH_RESULT
|
|
|
|
|
${name}_library_internal_${library}
|
|
|
|
|
SEARCH_PATHS
|
|
|
|
|
${library_search_paths}
|
|
|
|
|
SEARCH_SUFFIXES
|
|
|
|
|
${suffixes}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-03-02 11:28:59 -03:00
|
|
|
|
|
|
|
|
# After searching the library, the internal variable should have either the
|
|
|
|
|
# absolute path to the library or the name of the variable appended with
|
|
|
|
|
# -NOTFOUND
|
2022-02-09 20:59:27 -03:00
|
|
|
if("${${name}_library_internal_${library}}" STREQUAL
|
|
|
|
|
"${name}_library_internal_${library}-NOTFOUND"
|
2022-01-31 13:55:48 +00:00
|
|
|
)
|
2022-03-02 11:28:59 -03:00
|
|
|
# We keep track of libraries that were not found
|
2022-01-31 13:55:48 +00:00
|
|
|
list(APPEND not_found_libraries ${library})
|
|
|
|
|
else()
|
2022-03-02 11:28:59 -03:00
|
|
|
# We get the name of the parent directory of the library and append the
|
|
|
|
|
# library to a list of found libraries
|
2022-02-09 20:59:27 -03:00
|
|
|
get_filename_component(
|
|
|
|
|
${name}_library_dir_internal ${${name}_library_internal_${library}}
|
|
|
|
|
DIRECTORY
|
|
|
|
|
) # e.g. lib/openflow.(so|dll|dylib|a) -> lib
|
2022-01-31 13:55:48 +00:00
|
|
|
list(APPEND library_dirs ${${name}_library_dir_internal})
|
|
|
|
|
list(APPEND libraries ${${name}_library_internal_${library}})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
2022-01-28 19:31:35 -03:00
|
|
|
|
2022-02-09 20:59:27 -03:00
|
|
|
# For each library that was found (e.g. /usr/lib/pthread.so), get their parent
|
|
|
|
|
# directory (/usr/lib) and its parent (/usr)
|
|
|
|
|
set(parent_dirs)
|
|
|
|
|
foreach(libdir ${library_dirs})
|
|
|
|
|
get_filename_component(parent_libdir ${libdir} DIRECTORY)
|
|
|
|
|
get_filename_component(parent_parent_libdir ${parent_libdir} DIRECTORY)
|
2022-03-25 22:31:56 -03:00
|
|
|
list(APPEND parent_dirs ${libdir} ${parent_libdir} ${parent_parent_libdir})
|
2022-02-09 20:59:27 -03:00
|
|
|
endforeach()
|
|
|
|
|
|
2022-06-14 15:08:41 -03:00
|
|
|
set(header_search_paths
|
|
|
|
|
${search_paths}
|
2022-10-13 23:54:47 -03:00
|
|
|
${parent_dirs}
|
|
|
|
|
${project_parent_dirs}
|
2022-06-14 15:08:41 -03:00
|
|
|
${CMAKE_OUTPUT_DIRECTORY} # Search for headers in
|
|
|
|
|
# ns-3-dev/build
|
|
|
|
|
${CMAKE_INSTALL_PREFIX} # Search for headers in the install
|
|
|
|
|
)
|
2022-03-02 11:51:53 -03:00
|
|
|
|
2022-01-31 13:55:48 +00:00
|
|
|
set(not_found_headers)
|
|
|
|
|
set(include_dirs)
|
|
|
|
|
foreach(header ${header_names})
|
2022-03-02 11:28:59 -03:00
|
|
|
# The same way with libraries, we mark the internal variable as advanced not
|
|
|
|
|
# to pollute ccmake configuration with variables used internally
|
2022-01-31 20:02:10 -03:00
|
|
|
mark_as_advanced(${name}_header_internal_${header})
|
2022-03-02 11:51:53 -03:00
|
|
|
set(suffixes
|
2022-01-31 13:55:48 +00:00
|
|
|
/build
|
|
|
|
|
/include
|
|
|
|
|
/build/include
|
|
|
|
|
/build/include/${name}
|
|
|
|
|
/include/${name}
|
|
|
|
|
/${name}
|
|
|
|
|
/
|
|
|
|
|
${path_suffixes}
|
2022-01-23 17:30:08 -03:00
|
|
|
)
|
2022-03-02 11:51:53 -03:00
|
|
|
|
|
|
|
|
# cmake-format: off
|
|
|
|
|
# Here we search for the header file named ${header} and store the result in
|
|
|
|
|
# ${name}_header_internal_${header}
|
|
|
|
|
#
|
2022-03-02 11:28:59 -03:00
|
|
|
# The same way we did with libraries, here we search on
|
|
|
|
|
# CMAKE_SYSTEM_PREFIX_PATH, along with user-settable ${search_paths}, the
|
|
|
|
|
# parent directories from the libraries, CMAKE_OUTPUT_DIRECTORY and
|
|
|
|
|
# CMAKE_INSTALL_PREFIX
|
|
|
|
|
#
|
|
|
|
|
# And again, for each of them, for every suffix listed /usr/local/build
|
2022-03-02 11:51:53 -03:00
|
|
|
# /usr/local/include
|
|
|
|
|
# /usr/local/build/include
|
|
|
|
|
# /usr/local/build/include/${name}
|
|
|
|
|
# /usr/local/include/${name}
|
|
|
|
|
# ...
|
|
|
|
|
#
|
|
|
|
|
# cmake-format: on
|
|
|
|
|
# Or enable NS3_VERBOSE to get the searched paths printed while configuring
|
|
|
|
|
|
|
|
|
|
find_file(${name}_header_internal_${header} ${header}
|
|
|
|
|
HINTS ${header_search_paths} # directory (e.g. /usr/)
|
|
|
|
|
${header_skip_system_prefix} PATH_SUFFIXES ${suffixes}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Print tested paths to the searched header and if it was found
|
|
|
|
|
if(${NS3_VERBOSE} AND (${CMAKE_VERSION} VERSION_LESS "3.17.0"))
|
|
|
|
|
log_find_searched_paths(
|
|
|
|
|
TARGET_TYPE
|
|
|
|
|
Header
|
|
|
|
|
TARGET_NAME
|
|
|
|
|
${header}
|
|
|
|
|
SEARCH_RESULT
|
|
|
|
|
${name}_header_internal_${header}
|
|
|
|
|
SEARCH_PATHS
|
|
|
|
|
${header_search_paths}
|
|
|
|
|
SEARCH_SUFFIXES
|
|
|
|
|
${suffixes}
|
|
|
|
|
SEARCH_SYSTEM_PREFIX
|
|
|
|
|
${header_skip_system_prefix}
|
|
|
|
|
)
|
|
|
|
|
endif()
|
2022-03-02 11:28:59 -03:00
|
|
|
|
|
|
|
|
# If the header file was not found, append to the not-found list
|
2022-02-09 20:59:27 -03:00
|
|
|
if("${${name}_header_internal_${header}}" STREQUAL
|
|
|
|
|
"${name}_header_internal_${header}-NOTFOUND"
|
|
|
|
|
)
|
2022-01-31 13:55:48 +00:00
|
|
|
list(APPEND not_found_headers ${header})
|
|
|
|
|
else()
|
2022-03-02 11:28:59 -03:00
|
|
|
# If the header file was found, get their directories and the parent of
|
|
|
|
|
# their directories to add as include directories
|
2022-02-09 20:59:27 -03:00
|
|
|
get_filename_component(
|
|
|
|
|
header_include_dir ${${name}_header_internal_${header}} DIRECTORY
|
|
|
|
|
) # e.g. include/click/ (simclick.h) -> #include <simclick.h> should work
|
|
|
|
|
get_filename_component(
|
|
|
|
|
header_include_dir2 ${header_include_dir} DIRECTORY
|
|
|
|
|
) # e.g. include/(click) -> #include <click/simclick.h> should work
|
2022-01-31 13:55:48 +00:00
|
|
|
list(APPEND include_dirs ${header_include_dir} ${header_include_dir2})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
|
2022-03-02 11:28:59 -03:00
|
|
|
# Remove duplicate include directories
|
2022-01-31 22:50:10 -03:00
|
|
|
if(include_dirs)
|
|
|
|
|
list(REMOVE_DUPLICATES include_dirs)
|
|
|
|
|
endif()
|
2022-01-31 13:55:48 +00:00
|
|
|
|
|
|
|
|
# If we find both library and header, we export their values
|
2022-05-11 16:02:55 -03:00
|
|
|
if((NOT not_found_libraries) AND (NOT not_found_headers))
|
2022-01-31 13:55:48 +00:00
|
|
|
set(${name}_INCLUDE_DIRS "${include_dirs}" PARENT_SCOPE)
|
|
|
|
|
set(${name}_LIBRARIES "${libraries}" PARENT_SCOPE)
|
2022-01-28 19:31:35 -03:00
|
|
|
set(${name}_HEADER ${${name}_header_internal} PARENT_SCOPE)
|
|
|
|
|
set(${name}_FOUND TRUE PARENT_SCOPE)
|
2022-04-04 22:15:46 -03:00
|
|
|
if(NOT ${FIND_LIB_QUIET})
|
|
|
|
|
message(STATUS "find_external_library: ${name} was found.")
|
|
|
|
|
endif()
|
2022-01-23 17:30:08 -03:00
|
|
|
else()
|
2022-01-28 19:31:35 -03:00
|
|
|
set(${name}_INCLUDE_DIRS PARENT_SCOPE)
|
|
|
|
|
set(${name}_LIBRARIES PARENT_SCOPE)
|
|
|
|
|
set(${name}_HEADER PARENT_SCOPE)
|
|
|
|
|
set(${name}_FOUND FALSE PARENT_SCOPE)
|
2022-04-04 22:15:46 -03:00
|
|
|
if(NOT ${FIND_LIB_QUIET})
|
|
|
|
|
message(
|
|
|
|
|
${HIGHLIGHTED_STATUS}
|
2022-03-02 11:28:59 -03:00
|
|
|
"find_external_library: ${name} was not found. Missing headers: \"${not_found_headers}\" and missing libraries: \"${not_found_libraries}\"."
|
2022-04-04 22:15:46 -03:00
|
|
|
)
|
|
|
|
|
endif()
|
2022-01-23 17:30:08 -03:00
|
|
|
endif()
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2022-01-26 11:51:50 -03:00
|
|
|
function(get_target_includes target output)
|
|
|
|
|
set(include_directories)
|
|
|
|
|
get_target_property(include_dirs ${target} INCLUDE_DIRECTORIES)
|
2022-05-20 15:39:44 +02:00
|
|
|
list(REMOVE_DUPLICATES include_dirs)
|
2022-01-26 11:51:50 -03:00
|
|
|
foreach(include_dir ${include_dirs})
|
|
|
|
|
if(include_dir MATCHES "<")
|
|
|
|
|
# Skip CMake build and install interface includes
|
|
|
|
|
continue()
|
|
|
|
|
else()
|
|
|
|
|
# Append the include directory to a list
|
|
|
|
|
set(include_directories ${include_directories} -I${include_dir})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${output} ${include_directories} PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
|
function(check_python_packages packages missing_packages)
|
|
|
|
|
set(missing)
|
|
|
|
|
foreach(package ${packages})
|
|
|
|
|
execute_process(
|
2022-03-02 11:51:53 -03:00
|
|
|
COMMAND ${Python3_EXECUTABLE} -c "import ${package}"
|
2022-02-09 20:59:27 -03:00
|
|
|
RESULT_VARIABLE return_code OUTPUT_QUIET ERROR_QUIET
|
2022-01-26 11:51:50 -03:00
|
|
|
)
|
|
|
|
|
if(NOT (${return_code} EQUAL 0))
|
|
|
|
|
list(APPEND missing ${package})
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
set(${missing_packages} "${missing}" PARENT_SCOPE)
|
|
|
|
|
endfunction()
|
|
|
|
|
|
2022-01-31 20:02:10 -03:00
|
|
|
include(build-support/custom-modules/ns3-lock.cmake)
|
|
|
|
|
include(build-support/custom-modules/ns3-configtable.cmake)
|