Skip to content

Commit

Permalink
Merge pull request #11 from NikolasK-source/main
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
NikolasK-source authored Feb 2, 2024
2 parents 3461093 + d8efce1 commit 3611fdd
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "libs/cxxopts"]
path = libs/cxxopts
url = https://github.com/jarro2783/cxxopts.git
[submodule "libs/cxxsemaphore"]
path = libs/cxxsemaphore
url = https://github.com/NikolasK-source/cxxsemaphore.git
[submodule "libs/cxxshm"]
path = libs/cxxshm
url = https://github.com/NikolasK-source/cxxshm.git
123 changes: 61 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
# ======================================================================================================================

# project
project(dump-shm LANGUAGES CXX VERSION 1.1.0)
project(dump-shm LANGUAGES CXX VERSION 1.2.0)

# settings
set(Target "dump-shm") # Executable name (without file extension!)
Expand All @@ -25,7 +25,6 @@ option(LTO_ENABLED "enable interprocedural and link time optimizations" OFF)
option(COMPILER_EXTENSIONS "enable compiler specific C++ extensions" OFF)



# ======================================================================================================================
# ======================================================================================================================

Expand All @@ -34,12 +33,12 @@ option(COMPILER_EXTENSIONS "enable compiler specific C++ extensions" OFF)
# ======================================================================================================================

# TODO select useful checks
if(CLANG_TIDY)
if (CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=*;
)
endif()
)
endif ()

# add executable
add_executable(${Target})
Expand All @@ -54,7 +53,7 @@ set_target_properties(${Target} PROPERTIES
CXX_STANDARD ${STANDARD}
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ${COMPILER_EXTENSIONS}
)
)

# compiler definitions
target_compile_definitions(${Target} PUBLIC "PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
Expand All @@ -65,26 +64,26 @@ target_compile_definitions(${Target} PUBLIC "SYSTEM_INFO=\"${CMAKE_SYSTEM_NAME}
# options that are valid for gcc and clang
function(commonopts)
# more debugging information
if(OPTIMIZE_DEBUG)
if (OPTIMIZE_DEBUG)
SET(CMAKE_CXX_FLAGS_DEBUG "-g3 -O3")
else()
else ()
SET(CMAKE_CXX_FLAGS_DEBUG "-g3")
endif()
endif ()

if(MAKE_32_BIT_BINARY)
if (MAKE_32_BIT_BINARY)
message(STATUS "Compiling as 32 bit binary.")
target_compile_options(${Target} PUBLIC -m32)
endif()
endif ()

if(ENABLE_MULTITHREADING AND OPENMP)
if (ENABLE_MULTITHREADING AND OPENMP)
message(STATUS "openmp enabled")
target_compile_options(${Target} PUBLIC -fopenmp)
endif()
endif ()

if(OPTIMIZE_FOR_ARCHITECTURE)
if (OPTIMIZE_FOR_ARCHITECTURE)
message(STATUS "using architecture specific code generator: ${ARCHITECTURE}")
target_compile_options(${Target} PUBLIC -march=${ARCHITECTURE})
endif()
endif ()
endfunction()

# warnings that are valid for gcc and clang
Expand Down Expand Up @@ -148,104 +147,104 @@ function(clangwarn)

endfunction()

if(COMPILER_WARNINGS)
if (COMPILER_WARNINGS)
message(STATUS "Compiler warnings enabled.")
else()
else ()
message(STATUS "Compiler warnings disabled.")
endif()
endif ()

# compiler settings
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# compiler specific defines
target_compile_definitions(${Target} PUBLIC "COMPILER_GNU")
target_compile_definitions(${Target} PUBLIC "COMPILER_GNU_CLANG")

commonopts()

# enable warnings
if(COMPILER_WARNINGS)
if (COMPILER_WARNINGS)
commonwarn()
gccwarn()
else()
else ()
target_compile_options(${Target} PUBLIC -w)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# compiler specific defines
target_compile_definitions(${Target} PUBLIC "COMPILER_CLANG")
target_compile_definitions(${Target} PUBLIC "COMPILER_GNU_CLANG")

commonopts()

# enable warnings (general)
if(COMPILER_WARNINGS)
if (COMPILER_WARNINGS)
commonwarn()
clangwarn()
else()
else ()
target_compile_options(${Target} PUBLIC -w)
endif()
endif ()

elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# compiler specific defines
target_compile_definitions(${Target} PUBLIC "COMPILER_MSVC")

# more debugging information
SET(CMAKE_CXX_FLAGS_DEBUG "/Zi")
SET(CMAKE_CXX_FLAGS_DEBUG "/Zi")
message(AUTHOR_WARNING
"You are using the MSVC compiler! Only gcc/clang are fully supported by this template.")

if(COMPILER_WARNINGS)
if (COMPILER_WARNINGS)
target_compile_options(${Target} PUBLIC /Wall /WX)
endif()
endif ()

if(ENABLE_MULTITHREADING AND OPENMP)
if (ENABLE_MULTITHREADING AND OPENMP)
target_compile_options(${Target} PUBLIC /OpenMP)
endif()
else()
endif ()
else ()
message(AUTHOR_WARNING
"You are using a compiler other than gcc/clang. Only gcc/clang are fully supported by this template.")
endif()
endif ()

if(ENABLE_MULTITHREADING)
if (ENABLE_MULTITHREADING)
# required by threading lib (std::thread)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${Target} PRIVATE Threads::Threads)
endif()
endif ()

# lto
if(LTO_ENABLED)
if (LTO_ENABLED)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT error)
if( ipo_supported )
if (ipo_supported)
message(STATUS "IPO / LTO enabled")
set_property(TARGET ${Target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
else ()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
endif()
endif ()
endif ()

# os dependent defines
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
target_compile_definitions(${Target} PUBLIC "OS_LINUX")
target_compile_definitions(${Target} PUBLIC "OS_POSIX")
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
target_compile_definitions(${Target} PUBLIC "OS_FREEBSD")
target_compile_definitions(${Target} PUBLIC "OS_POSIX")
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
target_compile_definitions(${Target} PUBLIC "OS_WINDOWS")
# TODO check options
target_compile_options(${Target} PUBLIC -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd)
SET(CMAKE_CXX_FLAGS_DEBUG "-g3 -D_DEBUG")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_compile_definitions(${Target} PUBLIC "OS_DARWIN")
target_compile_definitions(${Target} PUBLIC "OS_POSIX")
endif()
endif ()

# architecture defines
target_compile_definitions(${Target} PUBLIC CPU_WORD_BYTES=${CMAKE_SIZEOF_VOID_P})


if(BUILD_DOC)
if (BUILD_DOC)
# doxygen documentation (https://vicrucann.github.io/tutorials/quick-cmake-doxygen/)
# check if Doxygen is installed
find_package(Doxygen)
Expand All @@ -254,35 +253,35 @@ if(BUILD_DOC)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

if(EXISTS ${DOXYGEN_IN})
if (EXISTS ${DOXYGEN_IN})
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message(STATUS "Doxygen configured")

# note the option ALL which allows to build the docs together with the application
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
message(STATUS "Added target doc_doxygen")
else()
else ()
message(WARNING "doxygen documentation requested, but file ${DOXYGEN_IN} does not exist.")
endif()
endif ()
else (DOXYGEN_FOUND)
message(WARNING "Doxygen need to be installed and accessible to generate the doxygen documentation.")
message(WARNING "Doxygen need to be installed and accessible to generate the doxygen documentation.")
endif (DOXYGEN_FOUND)
endif()
endif ()

# add clang format target
if(CLANG_FORMAT)
if (CLANG_FORMAT)
set(CLANG_FORMAT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format)

if(EXISTS ${CLANG_FORMAT_FILE})
if (EXISTS ${CLANG_FORMAT_FILE})
include(ClangFormat.cmake)
target_clangformat_setup(${Target})
message(STATUS "Added clang format target(s)")
else()
else ()
message(WARNING "Clang format enabled, but file ${CLANG_FORMAT_FILE} does not exist")
endif()
endif()
endif ()
endif ()
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

This application dumps the content of a shared memory object to stdout.

## Build dependencies

### Ubuntu/Debian
```
apt update; apt install clang cmake build-essential
```

## Build
```
git submodule init
git submodule update
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=$(which clang++) -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
Expand Down
7 changes: 6 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ cat /dev/shm/<name> | hexdump -C -v

## Install

### Using the Modbus Collection Flapak Package: Shared Memory Modbus
### Using the Arch User Repository (recommended for Arch based Linux distributions)
The application is available as [dump-shm](https://aur.archlinux.org/packages/dump-shm) in the [Arch User Repository](https://aur.archlinux.org/).
See the [Arch Wiki](https://wiki.archlinux.org/title/Arch_User_Repository) for information about how to install AUR packages.


### Using the Modbus Collection Flatpak Package: Shared Memory Modbus
[SHM-Modbus](https://nikolask-source.github.io/SHM_Modbus/) is a collection of the shared memory modbus tools.
It is available as flatpak and published on flathub as ```network.koesling.shm-modbs```.

Expand Down
5 changes: 5 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ add_subdirectory(cxxopts EXCLUDE_FROM_ALL)
# ---------------------------------------- link libraries --------------------------------------------------------------
# ======================================================================================================================

add_subdirectory(cxxsemaphore)
add_subdirectory(cxxshm)

target_link_libraries(${Target} PRIVATE rt)
target_link_libraries(${Target} PRIVATE cxxopts)
target_link_libraries(${Target} PRIVATE cxxsemaphore)
target_link_libraries(${Target} PRIVATE cxxshm)
1 change: 1 addition & 0 deletions libs/cxxsemaphore
Submodule cxxsemaphore added at c5aec9
1 change: 1 addition & 0 deletions libs/cxxshm
Submodule cxxshm added at fc145c
16 changes: 8 additions & 8 deletions network.koesling.dump-shm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: network.koesling.dump-shm
runtime: org.freedesktop.Platform
runtime-version: '21.08'
runtime-version: '23.08'
sdk: org.freedesktop.Sdk
command: dump-shm
finish-args:
Expand All @@ -9,14 +9,14 @@ modules:
- name: dump_shm
buildsystem: simple
build-commands:
# build
- mkdir build
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
- cmake --build build
# build
- mkdir build
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
- cmake --build build

# install
- mkdir -p "${FLATPAK_DEST}/bin"
- cp build/dump-shm ${FLATPAK_DEST}/bin
# install
- mkdir -p "${FLATPAK_DEST}/bin"
- cp build/dump-shm ${FLATPAK_DEST}/bin
sources:
- type: git
branch: release
Expand Down
16 changes: 8 additions & 8 deletions network.koesling.test-dump-shm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: network.koesling.test-dump-shm
runtime: org.freedesktop.Platform
runtime-version: '21.08'
runtime-version: '23.08'
sdk: org.freedesktop.Sdk
command: dump-shm
finish-args:
Expand All @@ -9,14 +9,14 @@ modules:
- name: dump-shm
buildsystem: simple
build-commands:
# build
- mkdir build
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
- cmake --build build
# build
- mkdir build
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
- cmake --build build

# install
- mkdir -p "${FLATPAK_DEST}/bin"
- cp build/dump-shm ${FLATPAK_DEST}/bin
# install
- mkdir -p "${FLATPAK_DEST}/bin"
- cp build/dump-shm ${FLATPAK_DEST}/bin
sources:
- type: dir
path: .
Expand Down
Loading

0 comments on commit 3611fdd

Please sign in to comment.