From 7dfc27c1d33a1b795f053b51dbc21b459ec0cfda Mon Sep 17 00:00:00 2001 From: Navarrop Date: Wed, 13 Apr 2011 16:30:48 +0200 Subject: [PATCH] Add FindNS3 module to cmake. --- buildtools/Cmake/CompleteInFiles.cmake | 7 ++- buildtools/Cmake/MakeLib.cmake | 4 ++ buildtools/Cmake/Modules/FindGTnets.cmake | 1 + buildtools/Cmake/Modules/FindNS3.cmake | 66 +++++++++++++++++++++++ buildtools/Cmake/Option.cmake | 2 + buildtools/Cmake/PrintArgs.cmake | 2 + 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 buildtools/Cmake/Modules/FindNS3.cmake diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index 4f801ebb7d..63de957d67 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -19,6 +19,7 @@ string(TOUPPER ${enable_pcre} enable_pcre) if(enable_pcre STREQUAL "AUTO" OR enable_pcre STREQUAL "ON") include(FindPCRE) endif(enable_pcre STREQUAL "AUTO" OR enable_pcre STREQUAL "ON") +set(HAVE_GTNETS 0) if(enable_gtnets) include(FindGTnets) endif(enable_gtnets) @@ -28,6 +29,10 @@ endif(enable_smpi) if(enable_lua) include(FindLua51Simgrid) endif(enable_lua) +set(HAVE_NS3 0) +if(enable_ns3) + include(FindNS3) +endif(enable_ns3) # Checks for header libraries functions. CHECK_LIBRARY_EXISTS(pthread pthread_create "" pthread) @@ -637,7 +642,7 @@ set(includedir ${CMAKE_INSTALL_PREFIX}/include) set(top_builddir ${CMAKE_HOME_DIRECTORY}) set(libdir ${exec_prefix}/lib) set(CMAKE_LINKARGS "${CMAKE_BINARY_DIR}/lib") -set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:$LD_LIBRARY_PATH") +set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:${HAVE_NS3_LIB}:$LD_LIBRARY_PATH") configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/smpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/smpif.h @ONLY) configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY) diff --git a/buildtools/Cmake/MakeLib.cmake b/buildtools/Cmake/MakeLib.cmake index 2c1847c52d..06185fbe1b 100644 --- a/buildtools/Cmake/MakeLib.cmake +++ b/buildtools/Cmake/MakeLib.cmake @@ -123,6 +123,10 @@ if(HAVE_GTNETS) SET(SIMGRID_DEP "${SIMGRID_DEP} -lgtnets") endif(HAVE_GTNETS) +if(HAVE_NS3) + SET(SIMGRID_DEP "${SIMGRID_DEP} -lns3") +endif(HAVE_NS3) + if(HAVE_POSIX_GETTIME) SET(SIMGRID_DEP "${SIMGRID_DEP} -lrt") endif(HAVE_POSIX_GETTIME) diff --git a/buildtools/Cmake/Modules/FindGTnets.cmake b/buildtools/Cmake/Modules/FindGTnets.cmake index 44eb7a800b..a1e39de8de 100644 --- a/buildtools/Cmake/Modules/FindGTnets.cmake +++ b/buildtools/Cmake/Modules/FindGTnets.cmake @@ -25,6 +25,7 @@ find_path(HAVE_SIMULATOR_H /opt/csw /sw /usr + ${gtnets_path} ) string(REPLACE "/libgtnets.${LIB_EXE}" "" GTNETS_LIB_PATH "${HAVE_GTNETS_LIB}") diff --git a/buildtools/Cmake/Modules/FindNS3.cmake b/buildtools/Cmake/Modules/FindNS3.cmake new file mode 100644 index 0000000000..8906d1f0ae --- /dev/null +++ b/buildtools/Cmake/Modules/FindNS3.cmake @@ -0,0 +1,66 @@ +find_library(HAVE_NS3_LIB + NAME ns3 + HINTS + $ENV{LD_LIBRARY_PATH} + $ENV{HOME} + PATH_SUFFIXES lib64 lib lib64/ns3 lib/ns3 + PATHS + /opt + /opt/local + /opt/csw + /sw + /usr + ${ns3_path} +) + +find_path(HAVE_CORE_MODULE_H + NAME ns3/core-module.h + HINTS + $ENV{HOME} + PATH_SUFFIXES include include/ns3 + PATHS + /opt + /opt/local + /opt/csw + /sw + /usr + ${ns3_path} +) + +message(STATUS "Looking for core-module.h") +if(HAVE_CORE_MODULE_H) +message(STATUS "Looking for core-module.h - found") +else(HAVE_CORE_MODULE_H) +message(STATUS "Looking for core-module.h - not found") +endif(HAVE_CORE_MODULE_H) +mark_as_advanced(HAVE_CORE_MODULE_H) + +message(STATUS "Looking for lib ns3") +if(HAVE_NS3_LIB) +message(STATUS "Looking for lib ns3 - found") +else(HAVE_NS3_LIB) +message(STATUS "Looking for lib ns3 - not found") +endif(HAVE_NS3_LIB) +mark_as_advanced(HAVE_NS3_LIB) + +if(HAVE_NS3_LIB AND HAVE_CORE_MODULE_H) + set(HAVE_NS3 1) + string(REPLACE "/libns3.${LIB_EXE}" "" HAVE_NS3_LIB "${HAVE_NS3_LIB}") + string(REGEX MATCH "${HAVE_NS3_LIB}" 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=$LD_LIBRARY_PATH:${HAVE_NS3_LIB}") + set(HAVE_NS3 0) + + else(NOT operation) + + string(REGEX MATCH "-L${HAVE_NS3_LIB} " operation1 "${CMAKE_C_FLAGS}") + if(NOT operation1) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${HAVE_NS3_LIB} ") + endif(NOT operation1) + + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-I${HAVE_CORE_MODULE_H} -L${HAVE_NS3_LIB} ") + endif(NOT operation) + +endif(HAVE_NS3_LIB AND HAVE_CORE_MODULE_H) \ No newline at end of file diff --git a/buildtools/Cmake/Option.cmake b/buildtools/Cmake/Option.cmake index bd58b59107..b4b671d143 100644 --- a/buildtools/Cmake/Option.cmake +++ b/buildtools/Cmake/Option.cmake @@ -5,6 +5,7 @@ set(BIBTEX2HTML ${BIBTEX2HTML} CACHE PATH "Path to bibtex2html") set(gtnets_path ${gtnets_path} CACHE PATH "Path to gtnets lib and include") +set(ns3_path ${ns3_path} CACHE PATH "Path to ns3 lib and include") set(custom_flags ${custom_flags} CACHE FORCE "Customers flags add to cmake_c_flag") if(NOT CMAKE_INSTALL_PREFIX) @@ -16,6 +17,7 @@ endif(NOT CMAKE_INSTALL_PREFIX) set(pipol_user ${pipol_user} CACHE TYPE INTERNAL FORCE) option(enable_gtnets "Whether gtnets model is activated." on) +option(enable_ns3 "Whether ns3 model is activated." off) option(enable_smpi "This variable set smpi lib." on) option(enable_lua "Whether the lua bindings are activated." on) set(enable_pcre ${enable_pcre} CACHE FORCE "Whether the pcre lib is activated.") diff --git a/buildtools/Cmake/PrintArgs.cmake b/buildtools/Cmake/PrintArgs.cmake index 613d96a4a8..9e7c532922 100644 --- a/buildtools/Cmake/PrintArgs.cmake +++ b/buildtools/Cmake/PrintArgs.cmake @@ -89,7 +89,9 @@ message(" CPPFlags: ${CMAKE_CXX_FLAGS}") message("") if(NOT APPLE AND NOT WIN32) message(" Compile Gtnets : ${HAVE_GTNETS}") +message(" Compile NS-3 : ${HAVE_NS3}") message(" Gtnets path : ${gtnets_path}") +message(" NS-3 path : ${ns3_path}") endif(NOT APPLE AND NOT WIN32) message(" Compile Lua : ${HAVE_LUA}") message(" Compile Smpi : ${enable_smpi}") -- 2.20.1