Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
frs69wq committed Sep 16, 2024
1 parent 1c9a208 commit 45a4014
Show file tree
Hide file tree
Showing 46 changed files with 7,058 additions and 2 deletions.
114 changes: 114 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
cmake_minimum_required(VERSION 3.1)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/conf/cmake/")
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

project(dtlmod VERSION 0.1 DESCRIPTION "Data Transport Layer Module")

include(GNUInstallDirs)
find_package(SimGrid 3.35.1 REQUIRED)
find_package(FSMod REQUIRED)
find_package(nlohmann_json REQUIRED)

include_directories(
${CMAKE_SOURCE_DIR}/include
${SimGrid_INCLUDE_DIR}
${FSMod_INCLUDE_DIR}
${CMAKE_BINARY_DIR}/include
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# build the version number
set(DTLMOD_VERSION_MAJOR "0")
set(DTLMOD_VERSION_MINOR "1")
set(DTLMOD_VERSION_PATCH "0")
set(DTLMOD_VERSION_EXTRA "dev")

if (${DTLMOD_VERSION_PATCH} EQUAL "0")
set(DTLMOD_RELEASE_VERSION "${DTLMOD_VERSION_MAJOR}.${DTLMOD_VERSION_MINOR}")
else ()
set(DTLMOD_RELEASE_VERSION "${DTLMOD_VERSION_MAJOR}.${DTLMOD_VERSION_MINOR}.${DTLMOD_VERSION_PATCH}")
endif ()

set(SOURCE_FILES
src/DTL.cpp
src/Engine.cpp
src/FileEngine.cpp
src/StagingEngine.cpp
src/Metadata.cpp
src/Stream.cpp
src/Variable.cpp
src/Transport.cpp
src/FileTransport.cpp
src/MailboxTransport.cpp
src/MessageQueueTransport.cpp
)

set(HEADER_FILES
include/dtlmod/DTL.hpp
include/dtlmod/DTLException.hpp
include/dtlmod/Engine.hpp
include/dtlmod/FileTransport.hpp
include/dtlmod/FileEngine.hpp
include/dtlmod/MailboxTransport.hpp
include/dtlmod/MessageQueueTransport.hpp
include/dtlmod/Metadata.hpp
include/dtlmod/StagingEngine.hpp
include/dtlmod/Stream.hpp
include/dtlmod/Transport.hpp
include/dtlmod/Variable.hpp)

set (CONFIG_FILES
test/DTL-config.json)

add_library(dtlmod SHARED ${SOURCE_FILES})

set_target_properties(dtlmod PROPERTIES
SOVERSION 0.1
LINKER_LANGUAGE CXX
PUBLIC_HEADER "${HEADER_FILES}")

target_include_directories(dtlmod PRIVATE include)
target_link_libraries(dtlmod PUBLIC ${SimGrid_LIBRARY} ${FSMOD_LIBRARY})

foreach (conf "${CONFIG_FILES}")
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/${conf}
${CMAKE_CURRENT_BINARY_DIR}/config_files/${conf})
endforeach()

install(TARGETS dtlmod
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dtlmod)
install(FILES include/dtlmod.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Google test
find_library(GTEST_LIBRARY NAMES gtest)
if(GTEST_LIBRARY)
set(TEST_FILES
test/dtl_config.cpp
test/dtl_connection.cpp
test/dtl_file_engine.cpp
test/dtl_staging_engine.cpp
test/dtl_stream.cpp
test/dtl_variable.cpp
test/main.cpp
test/test_util.hpp
include/dtlmod.hpp)
add_definitions(-DGTEST_USED)
add_executable(unit_tests EXCLUDE_FROM_ALL ${SOURCE_FILES} ${HEADER_FILES} ${TEST_FILES})
target_include_directories(unit_tests PRIVATE include)
target_link_libraries(unit_tests ${GTEST_LIBRARY} ${SIMGRID_LIBRARY} ${FSMOD_LIBRARY} dtlmod -lpthread -lm)
set_target_properties(unit_tests PROPERTIES COMPILE_FLAGS "-g -O0 --coverage")
set_target_properties(unit_tests PROPERTIES LINK_FLAGS "--coverage")
#add_custom_command(TARGET unit_tests COMMAND find . -name *.gcda -delete)
else()
add_custom_target(unit_tests echo "ERROR: Cannot build unit_tests because Google Test (libgtest) was not found by cmake." COMMAND echo " If you have installed Google Test, re-run cmake." VERBATIM)
endif()

# Documentation
include(${CMAKE_HOME_DIRECTORY}/conf/cmake/Documentation.cmake)
98 changes: 98 additions & 0 deletions FindDTLMod.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# CMake find module to search for the Data Transport Layer Module.

# Copyright (c) 2024. The SWAT Team.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the license (GNU LGPL) which comes with this package.

#
# USERS OF PROGRAMS USING DTLMod
# -------------------------------
#
# If cmake does not find this file, add its path to CMAKE_PREFIX_PATH:
# CMAKE_PREFIX_PATH="/path/to/FindDTLMod.cmake:$CMAKE_PREFIX_PATH" cmake .
#
# If this file does not find DTLMod, define DTLMOD_PATH:
# DTLMOD_PATH=/path/to/dtlmod cmake .

#
# DEVELOPERS OF PROGRAMS USING DTLMod
# ------------------------------------
#
# 1. Include this file in your own CMakeLists.txt (before defining any target)
# by copying it in your development tree.
#
# 2. Afterward, if you have CMake >= 2.8.12, this will define a
# target called 'DTLMOD::DTLMOD'. Use it as:
# target_link_libraries(your-simulator DTLMOD::DTLMOD)
#
# With older CMake (< 2.8.12), it simply defines several variables:
# DTLMOD_INCLUDE_DIR - the DTLMod include directories
# DTLMOD_LIBRARY - link your simulator against it to use DTLMod
# Use as:
# include_directories("${DTLMOD_INCLUDE_DIR}" SYSTEM)
# target_link_libraries(your-simulator ${DTLMOD_LIBRARY})
#
# Since DTLMOD header files require C++17, so we set CMAKE_CXX_STANDARD to 17.
# Change this variable in your own file if you need a later standard.

cmake_minimum_required(VERSION 2.8.12)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_path(DTLMOD_INCLUDE_DIR
NAMES dtlmod.hpp
PATHS ${DTLMOD_PATH}/include /opt/dtlmod/include
)

find_library(DTLMOD_LIBRARY
NAMES dtlmod
PATHS ${DTLMOD_PATH}/lib /opt/dtlmod/lib
)

mark_as_advanced(DTLMOD_INCLUDE_DIR)
mark_as_advanced(DTLMOD_LIBRARY)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DTLMod
FOUND_VAR DTLMOD_FOUND
REQUIRED_VARS DTLMOD_INCLUDE_DIR DTLMOD_LIBRARY
VERSION_VAR DTLMOD_VERSION
REASON_FAILURE_MESSAGE "The DTLMod package could not be located. If you installed DTLMod in a non-standard location, pass -DDTLMOD_PATH=<path to location> to cmake (e.g., cmake -DDTLMOD_PATH=/opt/somewhere/)"
FAIL_MESSAGE "Could not find the DTLMod installation"
)


if (DTLMOD_FOUND AND NOT CMAKE_VERSION VERSION_LESS 2.8.12)

add_library(DTLMOD::DTLMOD SHARED IMPORTED)
set_target_properties(DTLMOD::DTLMOD PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${DTLMOD_INCLUDE_DIR}
INTERFACE_COMPILE_FEATURES cxx_alias_templates
IMPORTED_LOCATION ${DTLMOD_LIBRARY}
)
# We need C++17, so check for it just in case the user removed it since compiling DTLMOD
if (NOT CMAKE_VERSION VERSION_LESS 3.8)
# 3.8+ allows us to simply require C++17 (or higher)
set_property(TARGET DTLMOD::DTLMOD PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_17)
elseif (NOT CMAKE_VERSION VERSION_LESS 3.1)
# 3.1+ is similar but for certain features. We pick just one
set_property(TARGET DTLMOD::DTLMOD PROPERTY INTERFACE_COMPILE_FEATURES cxx_attribute_deprecated)
else ()
# Old CMake can't do much. Just check the CXX_FLAGS and inform the user when a C++17 feature does not work
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_CXX_FLAGS}")
check_cxx_source_compiles("
#if __cplusplus < 201703L
#error
#else
int main(){}
#endif
" _DTLMOD_CXX17_ENABLED)
if (NOT _DTLMOD_CXX17_ENABLED)
message(WARNING "C++17 is required to use DTLMod. Enable it with e.g. -std=c++17")
endif ()
unset(_DTLMOD_CXX14_ENABLED CACHE)
endif ()
endif ()
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# DTLMod
Versatile Simulated Data Transport Layer
[![License: LGPL v2.1](https://img.shields.io/badge/License-LGPL_v2.1-blue.svg)](https://www.gnu.org/licenses/lgpl-2.1)

# DTLMod: a versatile simulated Data Transport Layer

## Overview
This project implements a versatile simulated data transport layer "module" on top of
[SimGrid](https://simgrid.frama.io/simgrid/), to be used in any SimGrid-based simulator.

## Dependencies and installation

The only required dependencies are on [SimGrid](https://simgrid.frama.io/simgrid/) and its
[File System Module](https://github.com/simgrid/file-system-module). An optional dependency
is [Google Test](https://github.com/google/googletest) for compiling the unit tests.

Here is the typical Ubuntu installation procedure:

```bash
cd DTL
mkdir build
cd build
cmake ..
make -j4
sudo make install
```

after which the dtlmod library and header files will be installed in `/usr/local/`.

To compile and run the unit tests, just run the following command in the `build` directory:

```bash
make unit_tests
./unit_tests
```

---
69 changes: 69 additions & 0 deletions conf/cmake/Documentation.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
find_package(Doxygen QUIET)
if (NOT DOXYGEN_FOUND)
message("-- Doxygen: No (warning: Doxygen is needed in case you want to generate DTLMOD documentation)")
endif()


if (DOXYGEN_FOUND)

message("-- Found Doxygen")

# DTLMOD APIs documentation
foreach (SECTION USER)
string(TOLOWER ${SECTION} SECTION_LOWER)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/docs/logs/Doxyfile_${SECTION})
set(DTLMOD_DOC_INPUT "${CMAKE_HOME_DIRECTORY}/src ${CMAKE_HOME_DIRECTORY}/include")

if (${SECTION} STREQUAL "USER")
set(DTLMOD_SECTIONS "USER")
else ()
set(DTLMOD_SECTIONS "NODICE")
endif ()

set(DTLMOD_SECTIONS_OUTPUT ${SECTION_LOWER})
configure_file(${CMAKE_HOME_DIRECTORY}/conf/doxygen/Doxyfile.in ${DOXYGEN_OUT} @ONLY)

add_custom_target(doc-${SECTION_LOWER}
WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
COMMENT "Generating DTLMOD ${SECTION} documentation" VERBATIM)
add_custom_command(TARGET doc-${SECTION_LOWER}
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/docs/${DTLMOD_RELEASE_VERSION}/${SECTION_LOWER}
COMMAND echo "CALLING DOXYGEN: ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}"
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
COMMAND echo "CALLING DOX")

LIST(APPEND DTLMOD_SECTIONS_LIST doc-${SECTION_LOWER})
endforeach ()

# DTLMOD documentation pages
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/docs/logs/Doxyfile_pages)
set(DTLMOD_DOC_INPUT "${CMAKE_HOME_DIRECTORY}/doc ${CMAKE_HOME_DIRECTORY}/src ${CMAKE_HOME_DIRECTORY}/include")
set(DTLMOD_SECTIONS "USER")
set(DTLMOD_SECTIONS_OUTPUT "pages")

configure_file(${CMAKE_HOME_DIRECTORY}/conf/doxygen/Doxyfile.in ${DOXYGEN_OUT} @ONLY)

get_directory_property(extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${extra_clean_files};${CMAKE_CURRENT_BINARY_DIR}/docs")

add_custom_target(doc DEPENDS dtlmod ${DTLMOD_SECTIONS_LIST})

add_custom_command(TARGET doc
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/docs/source
COMMAND cp -r ${CMAKE_HOME_DIRECTORY}/doc/source ${CMAKE_CURRENT_BINARY_DIR}/docs)
add_custom_command(TARGET doc
COMMAND python3 ${CMAKE_HOME_DIRECTORY}/doc/scripts/generate_rst.py ${CMAKE_CURRENT_BINARY_DIR}/docs/${DTLMOD_RELEASE_VERSION} ${CMAKE_CURRENT_BINARY_DIR}/docs/source ${DTLMOD_RELEASE_VERSION})
add_custom_command(TARGET doc
COMMAND sphinx-build ${CMAKE_CURRENT_BINARY_DIR}/docs/source ${CMAKE_CURRENT_BINARY_DIR}/docs/build/${DTLMOD_RELEASE_VERSION})
add_custom_command(TARGET doc
COMMAND cp -R ${CMAKE_CURRENT_BINARY_DIR}/docs/build/${DTLMOD_RELEASE_VERSION} ${CMAKE_CURRENT_BINARY_DIR}/docs/build/latest)
add_custom_command(TARGET doc
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/docs/${DTLMOD_RELEASE_VERSION}
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/docs/latest
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/docs/logs
COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/docs/source
COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/docs/build/* ${CMAKE_CURRENT_BINARY_DIR}/docs
COMMAND rmdir ${CMAKE_CURRENT_BINARY_DIR}/docs/build)


endif()
Loading

0 comments on commit 45a4014

Please sign in to comment.