From b0ec6b41100ed62867784d477041dc2bb6ae7c8f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 25 Jul 2015 13:45:26 +0200 Subject: [PATCH] further cleanups of the NS3 detection (it breaks on travis) --- buildtools/Cmake/CompleteInFiles.cmake | 8 +-- buildtools/Cmake/Modules/FindNS3.cmake | 67 +++++++++++++++++--------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index 34023d15e9..52aef28cb1 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -838,8 +838,8 @@ set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=\"${CMAKE_INSTALL_PREFIX}/lib") if(GTNETS_LIB_PATH) set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${GTNETS_LIB_PATH}") endif() -if(HAVE_NS3_LIB) - set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${HAVE_NS3_LIB}") +if(NS3_LIBRARY_PATH) + set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}") endif() set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"") @@ -860,8 +860,8 @@ set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=\"${CMAKE_BINARY_DIR}/lib") if(GTNETS_LIB_PATH) set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${GTNETS_LIB_PATH}") endif() -if(HAVE_NS3_LIB) - set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${HAVE_NS3_LIB}") +if(NS3_LIBRARY_PATH) + set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}") endif() set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"") set(libdir "${CMAKE_BINARY_DIR}/lib") diff --git a/buildtools/Cmake/Modules/FindNS3.cmake b/buildtools/Cmake/Modules/FindNS3.cmake index 7e8d7eae86..250dfedf0e 100644 --- a/buildtools/Cmake/Modules/FindNS3.cmake +++ b/buildtools/Cmake/Modules/FindNS3.cmake @@ -1,16 +1,32 @@ +# Try to find the NS3 library. +# +# The user can hint a path using the ns3_path option. +# +# Once done, the following will be defined: +# +# NS3_INCLUDE_DIRS - the NS3 include directories +# NS3_LIBRARY_PATH - path to the libs +# NS3_LIBRARIES - link these to use NS3 (full path to libs) +# +# This could be improved in many ways (patches welcome): +# - No way to specify a minimal version (v3.10 is hardcoded). +# - No proper find_package() integration + ## ADDING A NS3 VERSION. # - Add ns3.${version}-core to the NAME line of the find_library below # - Add include/ns3{version} to the PATH_SUFFIXES line of the find_path below -find_library(HAVE_NS3_CORE_LIB +set(HAVE_NS3 0) + +find_library(NS3_LIBRARIES NAME ns3-core ns3.14-core ns3.15-core ns3.16-core ns3.17-core ns3.18-core ns3.19-core ns3.20-core ns3.21-core ns3.22-core PATH_SUFFIXES lib64 lib ns3/lib PATHS ${ns3_path} ) -find_path(HAVE_CORE_MODULE_H +find_path(NS3_INCLUDE_DIR NAME ns3/core-module.h PATH_SUFFIXES include ns3/include include/ns3.14 include/ns3.15 include/ns3.16 include/ns3.17 include/ns3.18 include/ns3.19 include/ns3.20 include/ns3.21 include/ns3.22 PATHS @@ -19,46 +35,49 @@ find_path(HAVE_CORE_MODULE_H -if(HAVE_CORE_MODULE_H) +if(NS3_INCLUDE_DIR) message(STATUS "Looking for ns3/core-module.h - found") else() message(STATUS "Looking for ns3/core-module.h - not found") endif() -mark_as_advanced(HAVE_CORE_MODULE_H) +mark_as_advanced(NS3_INCLUDE_DIR) message(STATUS "Looking for lib ns3-core") -if(HAVE_NS3_CORE_LIB) +if(NS3_LIBRARIES) message(STATUS "Looking for lib ns3-core - found") else() message(STATUS "Looking for lib ns3-core - not found") endif() +mark_as_advanced(NS3_LIBRARIES) -mark_as_advanced(HAVE_NS3_LIB) -mark_as_advanced(HAVE_NS3_CORE_LIB) -if(HAVE_CORE_MODULE_H) - if(HAVE_NS3_LIB) - message(STATUS "Warning: NS-3 version <= 3.10") +if(NS3_INCLUDE_DIR) + if(NS3_LIBRARIES) set(HAVE_NS3 1) - set(NS3_VERSION_MINOR 10) - get_filename_component(NS3_LIBRARY_PATH "${HAVE_NS3_LIB}" PATH) - endif() - if(HAVE_NS3_CORE_LIB) - message(STATUS "NS-3 version > 3.10") - string(REGEX REPLACE ".*ns3.([0-9]+)-core.*" "\\1" NS3_VERSION_MINOR "${HAVE_NS3_CORE_LIB}") - set(HAVE_NS3 1) - get_filename_component(NS3_LIBRARY_PATH "${HAVE_NS3_CORE_LIB}" PATH) + + string(REGEX REPLACE ".*ns3.([0-9]+)-core.*" "\\1" NS3_VERSION_MINOR "${NS3_LIBRARIES}") + get_filename_component(NS3_LIBRARY_PATH "${NS3_LIBRARIES}" PATH) + + # Compute NS3_PATH + string(REGEX REPLACE "(.*)/lib" "\\1" NS3_PATH "${NS3_LIBRARY_PATH}") + + message(STATUS "NS-3 found (v3.${NS3_VERSION_MINOR} in ${NS3_PATH}).") + + if (NOT NS3_LIBRARY_PATH STREQUAL "/usr/lib") + string(REGEX MATCH "${NS3_LIBRARY_PATH}" MatchResult "$ENV{LD_LIBRARY_PATH}") + if(NOT MatchResult) + message(STATUS "Warning: NS3 not installed in system path, and not listed in LD_LIBRARY_PATH." + " You want to: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}") + endif() + endif() endif() endif() +mark_as_advanced(NS3_LIBRARY_PATH) -if(HAVE_NS3) - string(REGEX MATCH "${NS3_LIBRARY_PATH}" operation "$ENV{LD_LIBRARY_PATH}") - if(NOT operation) - message(STATUS "Warning: To use NS-3 don't forget to set LD_LIBRARY_PATH with: export LD_LIBRARY_PATH=${NS3_LIBRARY_PATH}\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}") - endif() +if(HAVE_NS3) link_directories(${NS3_LIBRARY_PATH}) - include_directories(${HAVE_CORE_MODULE_H}) + include_directories(${NS3_INCLUDE_DIR}) else() message(STATUS "Warning: To use NS-3 Please install ns3 at least version 3.10 (http://www.nsnam.org/releases/)") endif() -- 2.20.1