Skip to content

Commit 5d5f61a

Browse files
authored
Added CMakeLists.txt
1 parent 6b13daa commit 5d5f61a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

CMakeLists.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# @brief CMake minimum required version and project name
2+
cmake_minimum_required(VERSION 3.22)
3+
project(GROUP-A)
4+
5+
# @brief Set C++ standard to 17 and enable C++ standard requirement
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
9+
# @brief Enable UART communication protocol
10+
set(UARTCOM OFF) #Set to "ON" to use UART communication protocol, otherwise set it to "OFF" to use TCP communication protocol.
11+
12+
# @brief Set client directory and headers and sources
13+
set(CLIENT_DIR client/desktop)
14+
set(CLIENT_HEADERS shared/setting.h ${CLIENT_DIR}/include/window.h ${CLIENT_DIR}/include/canvas.h ${CLIENT_DIR}/include/comservice.h)
15+
set(CLIENT_SOURCES ${CLIENT_DIR}/main.cpp ${CLIENT_DIR}/src/window.cpp ${CLIENT_DIR}/src/canvas.cpp ${CLIENT_DIR}/src/comservice.cpp)
16+
set(CLIENT_LIBRARIES Qt6::Core Qt6::Widgets Qt6::Multimedia)
17+
18+
# @brief Set server directory and headers and sources
19+
set(SERVER_DIR server/desktop)
20+
set(SERVER_HEADERS shared/setting.h ${SERVER_DIR}/include/window.h ${SERVER_DIR}/include/comservice.h)
21+
set(SERVER_SOURCES ${SERVER_DIR}/main.cpp ${SERVER_DIR}/src/window.cpp ${SERVER_DIR}/src/comservice.cpp)
22+
set(SERVER_LIBRARIES Qt6::Core Qt6::Widgets)
23+
24+
# @brief Set the UART variable to "ON" to use UART communication protocol, otherwise set it to "TCP" to use TCP communication protocol.
25+
if (${UARTCOM} MATCHES ON)
26+
add_compile_definitions(UARTCOM)
27+
28+
set(CLIENT_LIBRARIES ${CLIENT_LIBRARIES} Qt6::SerialPort)
29+
set(CLIENT_HEADERS ${CLIENT_HEADERS} ${CLIENT_DIR}/include/uartservice.h)
30+
set(CLIENT_SOURCES ${CLIENT_SOURCES} ${CLIENT_DIR}/src/uartservice.cpp)
31+
32+
set(SERVER_LIBRARIES ${SERVER_LIBRARIES} Qt6::SerialPort)
33+
set(SERVER_HEADERS ${SERVER_HEADERS} ${SERVER_DIR}/include/uartservice.h)
34+
set(SERVER_SOURCES ${SERVER_SOURCES} ${SERVER_DIR}/src/uartservice.cpp)
35+
36+
else()
37+
set(CLIENT_HEADERS ${CLIENT_HEADERS} ${CLIENT_DIR}/include/tcpservice.h)
38+
set(CLIENT_SOURCES ${CLIENT_SOURCES} ${CLIENT_DIR}/src/tcpservice.cpp)
39+
40+
set(SERVER_HEADERS ${SERVER_HEADERS} ${SERVER_DIR}/include/tcpservice.h)
41+
set(SERVER_SOURCES ${SERVER_SOURCES} ${SERVER_DIR}/src/tcpservice.cpp)
42+
endif()
43+
44+
# @brief Find Qt6 Core and Widgets packages
45+
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Multimedia SerialPort)
46+
47+
# @brief Add server executable and link libraries
48+
add_executable(server ${SERVER_HEADERS} ${SERVER_SOURCES})
49+
target_link_libraries(server PUBLIC ${SERVER_LIBRARIES})
50+
target_include_directories(server PUBLIC shared ${SERVER_DIR}/include)
51+
52+
# @brief Add client executable and link libraries
53+
add_executable(client ${CLIENT_HEADERS} ${CLIENT_SOURCES})
54+
target_link_libraries(client PUBLIC ${CLIENT_LIBRARIES})
55+
target_include_directories(client PUBLIC shared ${CLIENT_DIR}/include)
56+
57+
58+
# Add custom target for building firmware for the ESP32
59+
# cmake --build . --target build_server_firmware
60+
61+
add_custom_target(build_server_firmware
62+
COMMAND pio run
63+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/server/esp32
64+
COMMENT "Building firmware for ESP32...(server)"
65+
)
66+
67+
# Add custom target for uploading firmware to the ESP32
68+
# cmake --build . --target upload_server_firmware
69+
70+
add_custom_target(upload_server_firmware
71+
COMMAND pio run -t upload
72+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/server/esp32
73+
COMMENT "Uploading firmware to ESP32..."
74+
)
75+
76+
# Add custom target for building firmware for the client
77+
# cmake --build . --target build_client_firmware
78+
79+
add_custom_target(build_client_firmware
80+
COMMAND pio run
81+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/client/esp32
82+
COMMENT "Building firmware for ESP32...(client)"
83+
)
84+
85+
# Add custom target for uploading firmware to the client
86+
# cmake --build . --target upload_client_firmware
87+
88+
add_custom_target(upload_client_firmware
89+
COMMAND pio run -t upload
90+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/client/esp32
91+
COMMENT "Uploading firmware to ESP32...(client)"
92+
)
93+
94+
# @brief Use the code snippet down below in the terminal to run the compile and run the project!
95+
# @code
96+
# rm -r * && cmake .. && make && ./server && ./client
97+
# @endcode
98+

0 commit comments

Comments
 (0)