Skip to content

Commit ef2bc60

Browse files
committed
Inital commit
1 parent 70ea81e commit ef2bc60

20 files changed

+1549
-1
lines changed

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
cmake_minimum_required(VERSION 3.10.0)
32+
33+
project(modern.cpp.core)
34+
include(cmake/env.cmake)
35+
36+
add_subdirectory(source)

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
# modern.cpp.core
2-
Modern C++ Core
2+
Modern C++ core classes for specific functions in most native and modern C++17.
3+
4+
## Build
5+
```bash
6+
mkdir build
7+
cd build
8+
cmake -DCMAKE_BUILD_TYPE=Debug|Release ../modern.cpp.core
9+
make -j`nproc`
10+
```
11+
12+
## Classes
13+
- **CPUID** - Get CPUID.
14+
- **Double** - Less, Greater, Equal, Round.
15+
- **Serial** - Serial communication class.
16+
- **Timing** - Measering time, cpu and real time.
17+
18+
## Template classes
19+
- **CSVWriter** - write out comma seperated values.
20+
- **Timer** - timeout thread one time or interval.
21+
22+
## Unixservice class
23+
- Main function to run as a unix daemon.

cmake/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# cmake
2+
3+
## Configuration files for cmake build environment
4+
5+
env.cmake
6+
Environment variables for ModernCppCore
7+
8+
doxygen.cmake
9+
Template for running doxygen - not yet usable
10+
11+
find_package.cmake
12+
Overall find package to use these variables in other cmake files
13+
14+
## Add environment variables
15+
16+
Open env.cmake and create a new include directory:
17+
set(MCC_SOURCES_MYSHAREDINCLUDE ${MCC_SOURCES_SHARED}/MySharedInclude)

cmake/clang_warnings.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
set(MCC_WARNING_FLAGS
32+
33+
# From Xcode default project
34+
# -Wno-sign-conversion
35+
# -Wno-exit-time-destructors
36+
# -Wno-conversion
37+
38+
# Own parameter
39+
-Wno-c++98-compat # C++11
40+
-Wno-padded
41+
)

cmake/doxygen.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
# first we can indicate the documentation build as an option and set it to ON by default
32+
option(BUILD_DOC "Build documentation" OFF)
33+
34+
# check if Doxygen is installed
35+
find_package(Doxygen)
36+
if (DOXYGEN_FOUND)
37+
# set input and output files
38+
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/../docs/Doxyfile.in)
39+
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
40+
41+
# request to configure the file
42+
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
43+
message("Doxygen build started")
44+
45+
# note the option ALL which allows to build the docs together with the application
46+
add_custom_target( doc_doxygen ALL
47+
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
48+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
49+
COMMENT "Generating API documentation with Doxygen"
50+
VERBATIM )
51+
else (DOXYGEN_FOUND)
52+
message("Doxygen need to be installed to generate the doxygen documentation")
53+
endif (DOXYGEN_FOUND)
54+

cmake/env.cmake

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
#for debugging of build steps
32+
#set(CMAKE_VERBOSE_MAKEFILE ON)
33+
34+
# Pathes
35+
if(NOT MCC_DEV)
36+
get_filename_component(MCC_DEV "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
37+
endif()
38+
39+
set(MCC_CMAKE ${MCC_DEV}/cmake)
40+
41+
# Force C++17
42+
set(CMAKE_CXX_STANDARD 17)
43+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
44+
set(CMAKE_CXX_EXTENSIONS OFF)
45+
46+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
47+
48+
set(USE_CLANG false)
49+
if (CMAKE_CXX_COMPILER_ID MATCHES "[cC][lL][aA][nN][gG]") #Case insensitive match
50+
set(USE_CLANG true)
51+
else()
52+
set(USE_CLANG false)
53+
endif()
54+
55+
set(USE_GCC false)
56+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
57+
set(USE_GCC true)
58+
else()
59+
set(USE_GCC false)
60+
endif()
61+
62+
# Warning flags
63+
if(USE_CLANG)
64+
include(${MCC_CMAKE}/clang_warnings.cmake)
65+
66+
set(MCC_WARNING_FLAGS_SPACED "")
67+
foreach(MCC_WARNING_FLAG ${MCC_WARNING_FLAGS})
68+
set(MCC_WARNING_FLAGS_SPACED "${MCC_WARNING_FLAGS_SPACED} ${MCC_WARNING_FLAG}")
69+
endforeach()
70+
71+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything -Werror")
72+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MCC_WARNING_FLAGS_SPACED}")
73+
endif()
74+
75+
if(USE_GCC)
76+
include(${MCC_CMAKE}/gcc_warnings.cmake)
77+
78+
set(MCC_WARNING_FLAGS_SPACED "")
79+
foreach(MCC_WARNING_FLAG ${MCC_WARNING_FLAGS})
80+
set(MCC_WARNING_FLAGS_SPACED "${MCC_WARNING_FLAGS_SPACED} ${MCC_WARNING_FLAG}")
81+
endforeach()
82+
83+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra")
84+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MCC_WARNING_FLAGS_SPACED}")
85+
endif()
86+
87+
add_compile_options("$<$<CONFIG:DEBUG>:-DDEBUG>")
88+
89+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
90+
91+
# Project modules/variables
92+
set(CMAKE_MODULE_PATH ${MCC_CMAKE}/modules)
93+
94+
# Includes
95+
include(${MCC_CMAKE}/find_package.cmake)

cmake/find_package.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */

cmake/gcc_warnings.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
set(MCC_WARNING_FLAGS
32+
33+
# -Wno-unknown-pragmas
34+
)

source/CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#/*
2+
# * Copyright (c) 2020 Florian Becker <[email protected]> (VX APPS).
3+
# * All rights reserved.
4+
# *
5+
# * Redistribution and use in source and binary forms, with or without
6+
# * modification, are permitted provided that the following conditions are met:
7+
# *
8+
# * 1. Redistributions of source code must retain the above copyright notice, this
9+
# * list of conditions and the following disclaimer.
10+
# *
11+
# * 2. Redistributions in binary form must reproduce the above copyright notice,
12+
# * this list of conditions and the following disclaimer in the documentation
13+
# * and/or other materials provided with the distribution.
14+
# *
15+
# * 3. Neither the name of the copyright holder nor the names of its
16+
# * contributors may be used to endorse or promote products derived from
17+
# * this software without specific prior written permission.
18+
# *
19+
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
# * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
# * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
# * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
# * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
# * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
# */
30+
31+
project(modern.cpp.core)
32+
33+
add_library(modern.cpp.core
34+
../README.md
35+
CPUID.h
36+
Double.cpp
37+
Double.h
38+
ModernCppCore.h
39+
Serial.cpp
40+
Serial.h
41+
Timing.cpp
42+
Timing.h
43+
templates/CSVWriter.h
44+
templates/Timer.h
45+
unixservice/main.cpp
46+
)

0 commit comments

Comments
 (0)