Skip to content

Commit b703db2

Browse files
committed
Add CMake
1 parent a0a047c commit b703db2

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(processWatchdog C CXX)
3+
4+
option(MAX_APPS_OPTION "Set the maximum number of applications" ON)
5+
if(MAX_APPS_OPTION)
6+
set(MAX_APPS 6 CACHE STRING "Maximum number of applications")
7+
add_definitions(-DMAX_APPS=${MAX_APPS})
8+
endif()
9+
10+
# Add the include directory
11+
include_directories(${PROJECT_SOURCE_DIR}/src)
12+
13+
# Add the main executable
14+
add_executable(processWatchdog
15+
src/main.c
16+
src/apps.c
17+
src/cmd.c
18+
src/config.c
19+
src/filecmd.c
20+
src/heartbeat.c
21+
src/ini.c
22+
src/log.c
23+
src/process.c
24+
src/server.c
25+
src/stats.c
26+
src/test.c
27+
src/utils.c
28+
)
29+
30+
# Add the unit tests
31+
enable_testing()
32+
find_package(GTest REQUIRED)
33+
add_subdirectory(test)

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ A `Makefile` is included to compile the Process Watchdog application.
324324
make
325325
```
326326

327+
## Building with CMake
328+
329+
To build the project with CMake, you need to have CMake and GTest installed.
330+
331+
```bash
332+
mkdir build
333+
cd build
334+
cmake ..
335+
make
336+
./test/unit_tests
337+
```
338+
327339
## Running the Application
328340
Use the provided `run.sh` script to start the Process Watchdog application. This script includes a mechanism to restart the watchdog itself if it crashes, providing an additional level of protection.
329341

src/apps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
*/
3131

3232
// Constants
33+
#ifndef MAX_APPS
3334
#define MAX_APPS 6 /**< Maximum supported number of applications. */
35+
#endif
3436
#define MAX_APP_CMD_LENGTH 256 /**< Maximum length of the command to start an application. */
3537
#define MAX_APP_NAME_LENGTH 32 /**< Maximum length of an application name. */
3638
#define MAX_WAIT_PROCESS_START 5 /**< Maximum time to wait for a process to start running (seconds). */

test/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
set(CMAKE_CXX_STANDARD 11)
2+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3+
4+
add_executable(unit_tests
5+
server_test.cpp
6+
../src/apps.c
7+
../src/cmd.c
8+
../src/config.c
9+
../src/filecmd.c
10+
../src/heartbeat.c
11+
../src/ini.c
12+
../src/log.c
13+
../src/process.c
14+
../src/server.c
15+
../src/stats.c
16+
../src/test.c
17+
../src/utils.c
18+
)
19+
target_link_libraries(
20+
unit_tests
21+
PRIVATE
22+
GTest::GTest
23+
GTest::Main
24+
)
25+
26+
include(GoogleTest)
27+
gtest_discover_tests(unit_tests)

test/server_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "gtest/gtest.h"
2+
3+
extern "C" {
4+
#include "server.h"
5+
}
6+
7+
TEST(ServerTest, UdpStart) {
8+
int socket;
9+
int port = 12345;
10+
ASSERT_EQ(udp_start(&socket, port), 0);
11+
udp_stop(socket);
12+
}

0 commit comments

Comments
 (0)