1- cmake_minimum_required (VERSION 3.25 )
1+ cmake_minimum_required (VERSION 3.16 )
22
33project (omodsim
4- VERSION 1.8.2
4+ VERSION 1.9.0
5+ DESCRIPTION "An Open Source Modbus Slave (Server) Utility"
56 LANGUAGES CXX )
67
78set (CMAKE_AUTOUIC ON )
@@ -10,13 +11,24 @@ set(CMAKE_AUTORCC ON)
1011set (CMAKE_CXX_STANDARD 17)
1112set (CMAKE_CXX_STANDARD_REQUIRED ON )
1213set (PRODUCT_NAME "Open ModSim" )
14+ set (EXECUTABLE_PATH "${CMAKE_INSTALL_PREFIX} /bin/${PROJECT_NAME} " )
15+
16+ # Split version to major, minor, patch
17+ string (REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION} )
18+ list (GET VERSION_LIST 0 VERSION_MAJOR)
19+ list (GET VERSION_LIST 1 VERSION_MINOR)
20+ list (GET VERSION_LIST 2 VERSION_PATCH)
1321
1422# Find Qt6 or fallback to Qt5
1523find_package (Qt6 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Core5Compat Qml Help LinguistTools QUIET )
1624if (NOT Qt6_FOUND)
1725 find_package (Qt5 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Qml Help LinguistTools QUIET )
1826endif ()
1927
28+ if (NOT Qt6_FOUND AND NOT Qt5_FOUND)
29+ message (FATAL_ERROR "One or more Qt development packages not found. Please install Qt5 or Qt6 development packages." )
30+ endif ()
31+
2032if (Qt6_FOUND)
2133 get_target_property (QT_BINARY_DIR Qt6::qmake IMPORTED_LOCATION )
2234 get_filename_component (QT_BINARY_DIR "${QT_BINARY_DIR} " DIRECTORY )
@@ -28,15 +40,30 @@ else()
2840endif ()
2941
3042# Define target
31- add_executable (omodsim )
43+ add_executable (${PROJECT_NAME} )
44+
45+ find_package (Git QUIET )
46+ if (GIT_FOUND)
47+ execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
48+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} /../.git
49+ OUTPUT_VARIABLE GIT_BRANCH
50+ OUTPUT_STRIP_TRAILING_WHITESPACE
51+ ERROR_QUIET )
52+
53+ if (${GIT_BRANCH} MATCHES dev)
54+ set (PROJECT_VERSION ${VERSION_MAJOR} .${VERSION_MINOR} -dev)
55+ endif ()
56+ else ()
57+ message (STATUS "Git not found - skipping branch detection" )
58+ endif ()
3259
3360# Define compile definitions
3461add_compile_definitions (APP_NAME= "${PRODUCT_NAME} " )
3562add_compile_definitions (APP_DESCRIPTION= "${PROJECT_DESCRIPTION} " )
3663add_compile_definitions (APP_VERSION= "${PROJECT_VERSION} " )
3764
3865# Include directories
39- target_include_directories (omodsim PRIVATE
66+ target_include_directories (${PROJECT_NAME} PRIVATE
4067 ${CMAKE_CURRENT_SOURCE_DIR}
4168 ${CMAKE_CURRENT_SOURCE_DIR} /controls
4269 ${CMAKE_CURRENT_SOURCE_DIR} /dialogs
@@ -70,6 +97,7 @@ set(SOURCES
7097 controls/scriptcontrol.cpp
7198 controls/searchlineedit.cpp
7299 controls/simulationmodecombobox.cpp
100+ controls/statisticwidget.cpp
73101 datasimulator.cpp
74102 dialogs/dialogautosimulation.cpp
75103 dialogs/dialogcoilsimulation.cpp
@@ -138,6 +166,7 @@ set(HEADERS
138166 controls/scriptcontrol.h
139167 controls/searchlineedit.h
140168 controls/simulationmodecombobox.h
169+ controls/statisticwidget.h
141170 datasimulator.h
142171 dialogs/dialogautosimulation.h
143172 dialogs/dialogcoilsimulation.h
@@ -155,6 +184,7 @@ set(HEADERS
155184 dialogs/dialogwritecoilregister.h
156185 dialogs/dialogwriteholdingregister.h
157186 dialogs/dialogwriteholdingregisterbits.h
187+ fontutils.h
158188 formatutils.h
159189 htmldelegate.h
160190 jscompleter.h
@@ -212,6 +242,7 @@ set(HEADERS
212242set (UI_FILES
213243 controls/outputwidget.ui
214244 controls/scriptcontrol.ui
245+ controls/statisticwidget.ui
215246 dialogs/dialogautosimulation.ui
216247 dialogs/dialogcoilsimulation.ui
217248 dialogs/dialogabout.ui
@@ -257,15 +288,19 @@ else()
257288endif ()
258289
259290# Link libraries
260- target_sources (omodsim PRIVATE resources.qrc ${HEADERS} ${SOURCES} ${UI_FILES} ${TS_FILES} )
261- target_link_libraries (omodsim PRIVATE Qt::Widgets Qt::Network Qt::PrintSupport Qt::SerialBus Qt::SerialPort Qt::Qml Qt::Help )
291+ target_sources (${PROJECT_NAME} PRIVATE resources.qrc ${HEADERS} ${SOURCES} ${UI_FILES} ${TS_FILES} )
292+ target_link_libraries (${PROJECT_NAME} PRIVATE Qt::Widgets Qt::Network Qt::PrintSupport Qt::SerialBus Qt::SerialPort Qt::Qml Qt::Help )
293+
294+ if (TARGET update_translations)
295+ add_dependencies (${PROJECT_NAME} update_translations )
296+ endif ()
262297
263298if (Qt6_FOUND)
264- qt_add_lupdate (omodsim
299+ qt_add_lupdate (${PROJECT_NAME}
265300 TS_FILES ${TS_FILES}
266301 SOURCES ${SOURCES} ${HEADERS} ${UI_FILES}
267302 )
268- target_link_libraries (omodsim PRIVATE Qt::Core5Compat )
303+ target_link_libraries (${PROJECT_NAME} PRIVATE Qt::Core5Compat )
269304else ()
270305 add_custom_command (
271306 OUTPUT ${TS_FILES}
@@ -277,24 +312,19 @@ else()
277312 COMMENT "Updating translation files..."
278313 )
279314 add_custom_target (update_translations ALL DEPENDS ${TS_FILES} )
280-
281315endif ()
282316
283317if (WIN32 )
284- string (REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION} )
285- list (GET VERSION_LIST 0 VERSION_MAJOR)
286- list (GET VERSION_LIST 1 VERSION_MINOR)
287- list (GET VERSION_LIST 2 VERSION_PATCH)
288-
289- set (EXECUTABLE_NAME "omodsim" )
290318 set (ICON_FILE "${CMAKE_CURRENT_SOURCE_DIR} /res/omodsim.ico" )
291- set (RC_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR} /omodsim.rc.in" )
292- set (GENERATED_RC "${CMAKE_BINARY_DIR} /omodsim.rc" )
293319
294- configure_file (${RC_TEMPLATE} ${GENERATED_RC} @ONLY )
320+ configure_file (
321+ "${CMAKE_CURRENT_SOURCE_DIR} /omodsim.rc.in"
322+ "${CMAKE_BINARY_DIR} /omodsim.rc"
323+ @ONLY
324+ )
295325
296- target_sources (omodsim PRIVATE ${ICON_PATH} ${GENERATED_RC} )
297- set_target_properties (omodsim PROPERTIES WIN32_EXECUTABLE ON )
326+ target_sources (${PROJECT_NAME} PRIVATE ${ICON_PATH} " ${CMAKE_BINARY_DIR} /omodsim.rc" )
327+ set_target_properties (${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE ON )
298328endif ()
299329
300330add_custom_command (
@@ -310,5 +340,4 @@ add_custom_command(
310340)
311341
312342add_custom_target (helpgenerator ALL DEPENDS ${JSHELP_QCH} ${JSHELP_QHC} )
313- add_dependencies (omodsim helpgenerator )
314- add_dependencies (omodsim update_translations )
343+ add_dependencies (${PROJECT_NAME} helpgenerator )
0 commit comments