Skip to content

Commit e2f289a

Browse files
Merge branch 'main' into release
2 parents 7b239ac + 3e3c4da commit e2f289a

22 files changed

+538
-239
lines changed

.github/workflows/cmake.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,60 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v3
21-
22-
- name: Init submodules
23-
run: git submodule init
24-
25-
- name: Update submodules
26-
run: git submodule update
21+
22+
- name: create tmp dir
23+
run: mkdir tmp
24+
25+
- name: update
26+
run: |
27+
sudo apt update
28+
sudo apt upgrade -y
29+
30+
- name: install cxxopts
31+
run: |
32+
git clone https://github.com/jarro2783/cxxopts.git tmp/cxxopts
33+
cd tmp/cxxopts
34+
git checkout $(git tag | grep -P '^v\d+\.\d+\.\d+$' | sort | tail -1)
35+
cmake -B build . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF -DCLANG_TIDY=OFF
36+
cmake --build build
37+
sudo cmake --install build
38+
cd -
39+
40+
- name: install cxxshm
41+
run: |
42+
git clone https://github.com/NikolasK-source/cxxshm.git tmp/cxxshm
43+
cd tmp/cxxshm
44+
git checkout $(git tag | grep -P '^v\d+\.\d+\.\d+$' | sort | tail -1)
45+
cmake -B build . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF -DCLANG_TIDY=OFF
46+
cmake --build build
47+
sudo cmake --install build
48+
cd -
49+
50+
- name: install cxxsemaphore
51+
run: |
52+
git clone https://github.com/NikolasK-source/cxxsemaphore.git tmp/cxxsemaphore
53+
cd tmp/cxxsemaphore
54+
git checkout $(git tag | grep -P '^v\d+\.\d+\.\d+$' | sort | tail -1)
55+
cmake -B build . -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF -DCLANG_TIDY=OFF
56+
cmake --build build
57+
sudo cmake --install build
58+
cd -
59+
60+
- name: install libmodbus
61+
run: |
62+
git clone https://github.com/stephane/libmodbus.git tmp/libmodbus
63+
cd tmp/libmodbus
64+
git checkout $(git tag | grep -P '^v\d+\.\d+\.\d+$' | sort | tail -1)
65+
autoreconf --install --symlink --force
66+
./configure
67+
make
68+
sudo make install
69+
cd -
2770
2871
- name: Configure CMake
2972
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
3073
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
31-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
74+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF -DCLANG_TIDY=OFF -DBUILD_DOC=OFF
3275

3376
- name: Build
3477
# Build your program with the given configuration
File renamed without changes.

.github/workflows/flatpak_release.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# general
22
build*
33
docs/*
4+
docs_doxy
45

56
!docs/index.md
67
!docs/_config.yml

CMakeLists.txt

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
99
# ======================================================================================================================
1010

1111
# project
12-
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.6.0)
12+
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.6.1)
1313

1414
# settings
1515
set(Target "modbus-tcp-client-shm") # Executable name (without file extension!)
@@ -37,154 +37,4 @@ option(ENABLE_TEST "enable test builds" OFF)
3737

3838
# ----------------------------------------------- Do not change --------------------------------------------------------
3939
# ======================================================================================================================
40-
41-
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
42-
43-
if (CLANG_TIDY)
44-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
45-
if (${CLANG_TIDY_NO_ERRORS})
46-
set(CLANG_TIDY_CONFIG_FILE ${CMAKE_SOURCE_DIR}/.clang-tidy-noerrors)
47-
else ()
48-
set(CLANG_TIDY_CONFIG_FILE ${CMAKE_SOURCE_DIR}/.clang-tidy)
49-
endif ()
50-
51-
set(CMAKE_CXX_CLANG_TIDY
52-
clang-tidy
53-
-config-file=${CLANG_TIDY_CONFIG_FILE})
54-
message(STATUS "clang-tidy enabled: ${CLANG_TIDY_CONFIG_FILE}")
55-
else ()
56-
message(WARNING "clang-tidy requested, but only available if clang is selected as compiler")
57-
endif ()
58-
endif ()
59-
60-
# add executable
61-
add_executable(${Target})
62-
install(TARGETS ${Target})
63-
64-
# set source and libraries directory
65-
add_subdirectory("src")
66-
add_subdirectory("libs")
67-
68-
include(warnings.cmake)
69-
include(define.cmake)
70-
include(compileropts.cmake)
71-
72-
# force C++ Standard and disable/enable compiler specific extensions
73-
set_target_properties(${Target} PROPERTIES
74-
CXX_STANDARD ${STANDARD}
75-
CXX_STANDARD_REQUIRED ON
76-
CXX_EXTENSIONS ${COMPILER_EXTENSIONS}
77-
)
78-
79-
# compiler definitions and options
80-
set_definitions(${Target})
81-
if (ENABLE_MULTITHREADING AND OPENMP)
82-
set_options(${Target} ON)
83-
else ()
84-
set_options(${Target} OFF)
85-
endif ()
86-
87-
if (COMPILER_WARNINGS)
88-
enable_warnings(${Target})
89-
message(STATUS "Compiler warnings enabled.")
90-
else ()
91-
disable_warnings(${Target})
92-
message(STATUS "Compiler warnings disabled.")
93-
endif ()
94-
95-
if (ENABLE_MULTITHREADING)
96-
# required by threading lib (std::thread)
97-
set(THREADS_PREFER_PTHREAD_FLAG ON)
98-
find_package(Threads REQUIRED)
99-
target_link_libraries(${Target} PRIVATE Threads::Threads)
100-
endif ()
101-
102-
# lto
103-
if (LTO_ENABLED)
104-
include(CheckIPOSupported)
105-
check_ipo_supported(RESULT ipo_supported OUTPUT error)
106-
if (ipo_supported)
107-
message(STATUS "IPO / LTO enabled")
108-
set_property(TARGET ${Target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
109-
else ()
110-
message(STATUS "IPO / LTO not supported: <${error}>")
111-
endif ()
112-
endif ()
113-
114-
if (BUILD_DOC)
115-
# doxygen documentation (https://vicrucann.github.io/tutorials/quick-cmake-doxygen/)
116-
# check if Doxygen is installed
117-
find_package(Doxygen)
118-
if (DOXYGEN_FOUND)
119-
# set input and output files
120-
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
121-
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
122-
123-
if (EXISTS ${DOXYGEN_IN})
124-
# request to configure the file
125-
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
126-
message(STATUS "Doxygen configured")
127-
128-
# note the option ALL which allows to build the docs together with the application
129-
add_custom_target(doc_doxygen_${Target} ALL
130-
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
131-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
132-
COMMENT "Generating API documentation with Doxygen"
133-
VERBATIM)
134-
message(STATUS "Added target doc_doxygen_${Target}")
135-
136-
if (TARGET doc_doxygen)
137-
add_dependencies(doc_doxygen doc_doxygen_${Target})
138-
else ()
139-
add_custom_target(doc_doxygen DEPENDS doc_doxygen_${Target})
140-
endif ()
141-
else ()
142-
message(WARNING "doxygen documentation requested, but file ${DOXYGEN_IN} does not exist.")
143-
endif ()
144-
else (DOXYGEN_FOUND)
145-
message(WARNING "Doxygen must be installed and accessible to generate the doxygen documentation.")
146-
endif (DOXYGEN_FOUND)
147-
endif ()
148-
149-
# add clang format target
150-
if (CLANG_FORMAT)
151-
set(CLANG_FORMAT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format)
152-
153-
if (EXISTS ${CLANG_FORMAT_FILE})
154-
include(ClangFormat.cmake)
155-
target_clangformat_setup(${Target})
156-
message(STATUS "Added clang format target(s)")
157-
else ()
158-
message(WARNING "Clang format enabled, but file ${CLANG_FORMAT_FILE} does not exist")
159-
endif ()
160-
endif ()
161-
162-
# add test targets
163-
if (ENABLE_TEST)
164-
enable_testing()
165-
add_subdirectory("test")
166-
endif ()
167-
168-
# generate version_info.cpp
169-
# output is not the acutal generated file --> command is always executed
170-
add_custom_command(
171-
OUTPUT
172-
${CMAKE_SOURCE_DIR}/src/generated/version_info_cpp
173-
174-
COMMAND
175-
bash ${CMAKE_SOURCE_DIR}/scripts/gen_version_info_cpp.sh ${PROJECT_NAME}
176-
177-
WORKING_DIRECTORY
178-
${CMAKE_SOURCE_DIR}
179-
)
180-
181-
execute_process(
182-
COMMAND bash "${CMAKE_SOURCE_DIR}/scripts/gen_version_info_cpp.sh" ${PROJECT_NAME}
183-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
184-
)
185-
186-
add_custom_target(${Target}_generated_version_info
187-
DEPENDS ${CMAKE_SOURCE_DIR}/src/generated/version_info_cpp
188-
)
189-
190-
add_dependencies(${Target} ${Target}_generated_version_info)
40+
include(cmake_files/setup.cmake)

Doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PROJECT_LOGO =
5858
# entered, it will be relative to the location where doxygen was started. If
5959
# left blank the current directory will be used.
6060

61-
OUTPUT_DIRECTORY = docs
61+
OUTPUT_DIRECTORY = docs_doxy
6262

6363
# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
6464
# directories (in 2 levels) under the output directory of each output format and

cmake_files/ClangFormat.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright Tomas Zeman 2019-2020.
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# (See accompanying file LICENSE_1_0.txt or copy at
4+
# http://www.boost.org/LICENSE_1_0.txt)
5+
6+
function(prefix_clangformat_setup prefix)
7+
if(NOT CLANGFORMAT_EXECUTABLE)
8+
set(CLANGFORMAT_EXECUTABLE clang-format)
9+
endif()
10+
11+
if(NOT EXISTS ${CLANGFORMAT_EXECUTABLE})
12+
find_program(clangformat_executable_tmp ${CLANGFORMAT_EXECUTABLE})
13+
if(clangformat_executable_tmp)
14+
set(CLANGFORMAT_EXECUTABLE ${clangformat_executable_tmp})
15+
unset(clangformat_executable_tmp)
16+
else()
17+
message(FATAL_ERROR "ClangFormat: ${CLANGFORMAT_EXECUTABLE} not found! Aborting")
18+
endif()
19+
endif()
20+
21+
foreach(clangformat_source ${ARGN})
22+
get_filename_component(clangformat_source ${clangformat_source} ABSOLUTE)
23+
list(APPEND clangformat_sources ${clangformat_source})
24+
endforeach()
25+
26+
add_custom_target(${prefix}_clangformat
27+
COMMAND
28+
${CLANGFORMAT_EXECUTABLE}
29+
-style=file
30+
-i
31+
${clangformat_sources}
32+
WORKING_DIRECTORY
33+
${CMAKE_SOURCE_DIR}
34+
COMMENT
35+
"Formatting ${prefix} with ${CLANGFORMAT_EXECUTABLE} ..."
36+
)
37+
38+
if(TARGET clangformat)
39+
add_dependencies(clangformat ${prefix}_clangformat)
40+
else()
41+
add_custom_target(clangformat DEPENDS ${prefix}_clangformat)
42+
endif()
43+
endfunction()
44+
45+
function(clangformat_setup)
46+
prefix_clangformat_setup(${PROJECT_NAME} ${ARGN})
47+
endfunction()
48+
49+
function(target_clangformat_setup target)
50+
get_target_property(target_sources ${target} SOURCES)
51+
prefix_clangformat_setup(${target} ${target_sources})
52+
endfunction()

cmake_files/compileropts.cmake

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Copyright (C) 2022 Nikolas Koesling <nikolas@koesling.info>.
3+
# This template is free software. You can redistribute it and/or modify it under the terms of the MIT License.
4+
#
5+
6+
# options that are valid for gcc and clang
7+
function(commonopts target)
8+
# more debugging information
9+
if(OPTIMIZE_DEBUG)
10+
SET(CMAKE_CXX_FLAGS_DEBUG "-g3 -O3")
11+
else()
12+
SET(CMAKE_CXX_FLAGS_DEBUG "-g3")
13+
endif()
14+
15+
if(MAKE_32_BIT_BINARY)
16+
message(STATUS "Compiling as 32 bit binary.")
17+
target_compile_options(${target} PUBLIC -m32)
18+
endif()
19+
20+
if(OPTIMIZE_FOR_ARCHITECTURE)
21+
message(STATUS "using architecture specific code generator: ${ARCHITECTURE}")
22+
target_compile_options(${target} PUBLIC -march=${ARCHITECTURE})
23+
endif()
24+
endfunction()
25+
26+
function(set_options target use_omp)
27+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
28+
commonopts(${target})
29+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
30+
commonopts(${target})
31+
32+
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
33+
# TODO check options
34+
target_compile_options(${target} PUBLIC -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd)
35+
SET(CMAKE_CXX_FLAGS_DEBUG "-g3 -D_DEBUG")
36+
endif()
37+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
38+
# more debugging information
39+
SET(CMAKE_CXX_FLAGS_DEBUG "/Zi")
40+
41+
if(ENABLE_MULTITHREADING AND OPENMP)
42+
target_compile_options(${target} PUBLIC /OpenMP)
43+
endif()
44+
else()
45+
message(AUTHOR_WARNING
46+
"You are using a compiler other than gcc/clang. Only gcc/clang are fully supported by this template.")
47+
endif()
48+
49+
if(use_omp)
50+
find_package(OpenMP)
51+
if (OPENMP_FOUND)
52+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
53+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
54+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
55+
target_link_libraries(${target} PRIVATE OpenMP::OpenMP_CXX)
56+
message(STATUS "openmp enabled")
57+
endif()
58+
endif()
59+
endfunction()

0 commit comments

Comments
 (0)