|
| 1 | +cmake_minimum_required(VERSION 3.25) |
| 2 | + |
| 3 | +project(OpenModSim |
| 4 | + VERSION 1.8.0 |
| 5 | + LANGUAGES CXX) |
| 6 | + |
| 7 | +set(CMAKE_AUTOUIC ON) |
| 8 | +set(CMAKE_AUTOMOC ON) |
| 9 | +set(CMAKE_AUTORCC ON) |
| 10 | +set(CMAKE_CXX_STANDARD 17) |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 12 | +set(PRODUCT_NAME "Open ModSim") |
| 13 | + |
| 14 | +# Find Qt6 or fallback to Qt5 |
| 15 | +find_package(Qt6 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Core5Compat Qml Help LinguistTools QUIET) |
| 16 | +if (NOT Qt6_FOUND) |
| 17 | + find_package(Qt5 COMPONENTS Core Gui Widgets Network PrintSupport SerialBus SerialPort Qml Help LinguistTools QUIET) |
| 18 | +endif() |
| 19 | + |
| 20 | +if(Qt6_FOUND) |
| 21 | + get_target_property(QT_BINARY_DIR Qt6::qmake IMPORTED_LOCATION) |
| 22 | + get_filename_component(QT_BINARY_DIR "${QT_BINARY_DIR}" DIRECTORY) |
| 23 | + get_filename_component(QT_LIBEXEC_DIR "${QT_BINARY_DIR}/../libexec" REALPATH) |
| 24 | +else() |
| 25 | + get_target_property(QT_BINARY_DIR Qt5::qmake IMPORTED_LOCATION) |
| 26 | + get_filename_component(QT_BINARY_DIR "${QT_BINARY_DIR}" DIRECTORY) |
| 27 | + set(QT_LIBEXEC_DIR "${QT_BINARY_DIR}") |
| 28 | +endif() |
| 29 | + |
| 30 | +# Define target |
| 31 | +add_executable(omodsim) |
| 32 | + |
| 33 | +# Define compile definitions |
| 34 | +add_compile_definitions(APP_NAME="${PRODUCT_NAME}") |
| 35 | +add_compile_definitions(APP_DESCRIPTION="${PROJECT_DESCRIPTION}") |
| 36 | +add_compile_definitions(APP_VERSION="${PROJECT_VERSION}") |
| 37 | + |
| 38 | +# Include directories |
| 39 | +target_include_directories(omodsim PRIVATE |
| 40 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 41 | + ${CMAKE_CURRENT_SOURCE_DIR}/controls |
| 42 | + ${CMAKE_CURRENT_SOURCE_DIR}/dialogs |
| 43 | + ${CMAKE_CURRENT_SOURCE_DIR}/jsobjects |
| 44 | + ${CMAKE_CURRENT_SOURCE_DIR}/modbusmessages |
| 45 | +) |
| 46 | + |
| 47 | +# Source files |
| 48 | +set(SOURCES |
| 49 | + ansimenu.cpp |
| 50 | + cmdlineparser.cpp |
| 51 | + controls/addressbasecombobox.cpp |
| 52 | + controls/booleancombobox.cpp |
| 53 | + controls/bytelisttextedit.cpp |
| 54 | + controls/clickablelabel.cpp |
| 55 | + controls/consoleoutput.cpp |
| 56 | + controls/customframe.cpp |
| 57 | + controls/customlineedit.cpp |
| 58 | + controls/flowcontroltypecombobox.cpp |
| 59 | + controls/helpwidget.cpp |
| 60 | + controls/jscodeeditor.cpp |
| 61 | + controls/mainstatusbar.cpp |
| 62 | + controls/modbuslogwidget.cpp |
| 63 | + controls/modbusmessagewidget.cpp |
| 64 | + controls/numericcombobox.cpp |
| 65 | + controls/numericlineedit.cpp |
| 66 | + controls/outputwidget.cpp |
| 67 | + controls/paritytypecombobox.cpp |
| 68 | + controls/pointtypecombobox.cpp |
| 69 | + controls/runmodecombobox.cpp |
| 70 | + controls/scriptcontrol.cpp |
| 71 | + controls/searchlineedit.cpp |
| 72 | + controls/simulationmodecombobox.cpp |
| 73 | + datasimulator.cpp |
| 74 | + dialogs/dialogautosimulation.cpp |
| 75 | + dialogs/dialogcoilsimulation.cpp |
| 76 | + dialogs/dialogabout.cpp |
| 77 | + dialogs/dialogdisplaydefinition.cpp |
| 78 | + dialogs/dialogforcemultiplecoils.cpp |
| 79 | + dialogs/dialogforcemultipleregisters.cpp |
| 80 | + dialogs/dialogmsgparser.cpp |
| 81 | + dialogs/dialogprintsettings.cpp |
| 82 | + dialogs/dialogscriptsettings.cpp |
| 83 | + dialogs/dialogselectserviceport.cpp |
| 84 | + dialogs/dialogsetuppresetdata.cpp |
| 85 | + dialogs/dialogsetupserialport.cpp |
| 86 | + dialogs/dialogwindowsmanager.cpp |
| 87 | + dialogs/dialogwritecoilregister.cpp |
| 88 | + dialogs/dialogwriteholdingregister.cpp |
| 89 | + dialogs/dialogwriteholdingregisterbits.cpp |
| 90 | + htmldelegate.cpp |
| 91 | + jscompleter.cpp |
| 92 | + jsobjects/console.cpp |
| 93 | + jsobjects/script.cpp |
| 94 | + jsobjects/server.cpp |
| 95 | + formmodsim.cpp |
| 96 | + jshighlighter.cpp |
| 97 | + jsobjects/storage.cpp |
| 98 | + main.cpp |
| 99 | + mainwindow.cpp |
| 100 | + menuconnect.cpp |
| 101 | + modbusdataunitmap.cpp |
| 102 | + modbusmessages/modbusmessage.cpp |
| 103 | + modbusmultiserver.cpp |
| 104 | + qfixedsizedialog.cpp |
| 105 | + qhexvalidator.cpp |
| 106 | + qint64validator.cpp |
| 107 | + quintvalidator.cpp |
| 108 | + recentfileactionlist.cpp |
| 109 | + windowactionlist.cpp |
| 110 | +) |
| 111 | + |
| 112 | +# Header files |
| 113 | +set(HEADERS |
| 114 | + ansimenu.h |
| 115 | + ansiutils.h |
| 116 | + byteorderutils.h |
| 117 | + cmdlineparser.h |
| 118 | + connectiondetails.h |
| 119 | + controls/addressbasecombobox.h |
| 120 | + controls/booleancombobox.h |
| 121 | + controls/bytelisttextedit.h |
| 122 | + controls/clickablelabel.h |
| 123 | + controls/consoleoutput.h |
| 124 | + controls/customframe.h |
| 125 | + controls/customlineedit.h |
| 126 | + controls/flowcontroltypecombobox.h |
| 127 | + controls/helpwidget.h |
| 128 | + controls/jscodeeditor.h |
| 129 | + controls/mainstatusbar.h |
| 130 | + controls/modbuslogwidget.h |
| 131 | + controls/modbusmessagewidget.h |
| 132 | + controls/numericcombobox.h |
| 133 | + controls/numericlineedit.h |
| 134 | + controls/outputwidget.h |
| 135 | + controls/paritytypecombobox.h |
| 136 | + controls/pointtypecombobox.h |
| 137 | + controls/runmodecombobox.h |
| 138 | + controls/scriptcontrol.h |
| 139 | + controls/searchlineedit.h |
| 140 | + controls/simulationmodecombobox.h |
| 141 | + datasimulator.h |
| 142 | + dialogs/dialogautosimulation.h |
| 143 | + dialogs/dialogcoilsimulation.h |
| 144 | + dialogs/dialogabout.h |
| 145 | + dialogs/dialogdisplaydefinition.h |
| 146 | + dialogs/dialogforcemultiplecoils.h |
| 147 | + dialogs/dialogforcemultipleregisters.h |
| 148 | + dialogs/dialogmsgparser.h |
| 149 | + dialogs/dialogprintsettings.h |
| 150 | + dialogs/dialogscriptsettings.h |
| 151 | + dialogs/dialogselectserviceport.h |
| 152 | + dialogs/dialogsetuppresetdata.h |
| 153 | + dialogs/dialogsetupserialport.h |
| 154 | + dialogs/dialogwindowsmanager.h |
| 155 | + dialogs/dialogwritecoilregister.h |
| 156 | + dialogs/dialogwriteholdingregister.h |
| 157 | + dialogs/dialogwriteholdingregisterbits.h |
| 158 | + formatutils.h |
| 159 | + htmldelegate.h |
| 160 | + jscompleter.h |
| 161 | + jsobjects/console.h |
| 162 | + jsobjects/script.h |
| 163 | + jsobjects/server.h |
| 164 | + displaydefinition.h |
| 165 | + enums.h |
| 166 | + formmodsim.h |
| 167 | + jshighlighter.h |
| 168 | + jsobjects/storage.h |
| 169 | + mainwindow.h |
| 170 | + menuconnect.h |
| 171 | + modbusdataunitmap.h |
| 172 | + modbuslimits.h |
| 173 | + modbusmessages/diagnostics.h |
| 174 | + modbusmessages/getcommeventcounter.h |
| 175 | + modbusmessages/getcommeventlog.h |
| 176 | + modbusmessages/maskwriteregister.h |
| 177 | + modbusmessages/modbusmessage.h |
| 178 | + modbusmessages/modbusmessages.h |
| 179 | + modbusmessages/readcoils.h |
| 180 | + modbusmessages/readdiscreteinputs.h |
| 181 | + modbusmessages/readexceptionstatus.h |
| 182 | + modbusmessages/readfifoqueue.h |
| 183 | + modbusmessages/readfilerecord.h |
| 184 | + modbusmessages/readholdingregisters.h |
| 185 | + modbusmessages/readinputregisters.h |
| 186 | + modbusmessages/readwritemultipleregisters.h |
| 187 | + modbusmessages/reportserverid.h |
| 188 | + modbusmessages/writefilerecord.h |
| 189 | + modbusmessages/writemultiplecoils.h |
| 190 | + modbusmessages/writemultipleregisters.h |
| 191 | + modbusmessages/writesinglecoil.h |
| 192 | + modbusmessages/writesingleregister.h |
| 193 | + modbusmultiserver.h |
| 194 | + modbussimulationparams.h |
| 195 | + modbuswriteparams.h |
| 196 | + numericutils.h |
| 197 | + qfixedsizedialog.h |
| 198 | + qhexvalidator.h |
| 199 | + qint64validator.h |
| 200 | + qmodbusadu.h |
| 201 | + qmodbusadurtu.h |
| 202 | + qmodbusadutcp.h |
| 203 | + qrange.h |
| 204 | + quintvalidator.h |
| 205 | + recentfileactionlist.h |
| 206 | + scriptsettings.h |
| 207 | + serialportutils.h |
| 208 | + windowactionlist.h |
| 209 | +) |
| 210 | + |
| 211 | +# UI Forms |
| 212 | +set(UI_FILES |
| 213 | + controls/outputwidget.ui |
| 214 | + controls/scriptcontrol.ui |
| 215 | + dialogs/dialogautosimulation.ui |
| 216 | + dialogs/dialogcoilsimulation.ui |
| 217 | + dialogs/dialogabout.ui |
| 218 | + dialogs/dialogdisplaydefinition.ui |
| 219 | + dialogs/dialogforcemultiplecoils.ui |
| 220 | + dialogs/dialogforcemultipleregisters.ui |
| 221 | + dialogs/dialogmsgparser.ui |
| 222 | + dialogs/dialogprintsettings.ui |
| 223 | + dialogs/dialogscriptsettings.ui |
| 224 | + dialogs/dialogselectserviceport.ui |
| 225 | + dialogs/dialogsetuppresetdata.ui |
| 226 | + dialogs/dialogsetupserialport.ui |
| 227 | + dialogs/dialogwindowsmanager.ui |
| 228 | + dialogs/dialogwritecoilregister.ui |
| 229 | + dialogs/dialogwriteholdingregister.ui |
| 230 | + dialogs/dialogwriteholdingregisterbits.ui |
| 231 | + formmodsim.ui |
| 232 | + mainwindow.ui |
| 233 | +) |
| 234 | + |
| 235 | +set(TS_FILES |
| 236 | + translations/omodsim_ru.ts |
| 237 | +) |
| 238 | + |
| 239 | +set(JSHELP_INPUT "${CMAKE_SOURCE_DIR}/docs/jshelp.qhcp") |
| 240 | +set(JSHELP_QCH "${CMAKE_BINARY_DIR}/docs/jshelp.qch") |
| 241 | +set(JSHELP_QHC "${CMAKE_BINARY_DIR}/docs/jshelp.qhc") |
| 242 | + |
| 243 | +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/docs) |
| 244 | + |
| 245 | +find_program(QHELP_GENERATOR_EXECUTABLE qhelpgenerator |
| 246 | + HINTS "${QT_BINARY_DIR}" "${QT_LIBEXEC_DIR}" |
| 247 | + NO_DEFAULT_PATH) |
| 248 | +if(NOT QHELP_GENERATOR_EXECUTABLE) |
| 249 | + find_program(QHELP_GENERATOR_EXECUTABLE qhelpgenerator) |
| 250 | +endif() |
| 251 | + |
| 252 | +if(QHELP_GENERATOR_EXECUTABLE) |
| 253 | + message(STATUS "qhelpgenerator found at: ${QHELP_GENERATOR_EXECUTABLE}") |
| 254 | +else() |
| 255 | + message(FATAL_ERROR "qhelpgenerator not found") |
| 256 | +endif() |
| 257 | + |
| 258 | +# Link libraries |
| 259 | +target_sources(omodsim PRIVATE resources.qrc ${HEADERS} ${SOURCES} ${UI_FILES} ${TS_FILES}) |
| 260 | +target_link_libraries(omodsim PRIVATE Qt::Widgets Qt::Network Qt::PrintSupport Qt::SerialBus Qt::SerialPort Qt::Qml Qt::Help) |
| 261 | + |
| 262 | +if(Qt6_FOUND) |
| 263 | + qt_add_lupdate(omodsim |
| 264 | + TS_FILES ${TS_FILES} |
| 265 | + SOURCES ${SOURCES} ${HEADERS} ${UI_FILES} |
| 266 | + ) |
| 267 | + target_link_libraries(omodsim PRIVATE Qt::Core5Compat) |
| 268 | +else() |
| 269 | + add_custom_command( |
| 270 | + OUTPUT ${TS_FILES} |
| 271 | + COMMAND ${Qt5_LUPDATE_EXECUTABLE} |
| 272 | + ${SOURCES} ${HEADERS} ${UI_FILES} |
| 273 | + -ts ${TS_FILES} |
| 274 | + DEPENDS ${SOURCES} ${HEADERS} ${UI_FILES} |
| 275 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 276 | + COMMENT "Updating translation files..." |
| 277 | + ) |
| 278 | + add_custom_target(update_translations ALL DEPENDS ${TS_FILES}) |
| 279 | + |
| 280 | +endif() |
| 281 | + |
| 282 | +if(WIN32) |
| 283 | + string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION}) |
| 284 | + list(GET VERSION_LIST 0 VERSION_MAJOR) |
| 285 | + list(GET VERSION_LIST 1 VERSION_MINOR) |
| 286 | + list(GET VERSION_LIST 2 VERSION_PATCH) |
| 287 | + |
| 288 | + set(EXECUTABLE_NAME "omodsim") |
| 289 | + set(ICON_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/omodsim.ico") |
| 290 | + set(RC_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/omodsim.rc.in") |
| 291 | + set(GENERATED_RC "${CMAKE_BINARY_DIR}/omodsim.rc") |
| 292 | + |
| 293 | + configure_file(${RC_TEMPLATE} ${GENERATED_RC} @ONLY) |
| 294 | + |
| 295 | + target_sources(omodsim PRIVATE ${ICON_PATH} ${GENERATED_RC}) |
| 296 | + set_target_properties(omodsim PROPERTIES WIN32_EXECUTABLE ON) |
| 297 | +endif() |
| 298 | + |
| 299 | +add_custom_command( |
| 300 | + OUTPUT ${JSHELP_QCH} ${JSHELP_QHC} |
| 301 | + COMMAND ${QHELP_GENERATOR_EXECUTABLE} ${JSHELP_INPUT} |
| 302 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/docs |
| 303 | + COMMAND ${CMAKE_COMMAND} -E rename |
| 304 | + ${CMAKE_SOURCE_DIR}/docs/jshelp.qch ${JSHELP_QCH} |
| 305 | + COMMAND ${CMAKE_COMMAND} -E rename |
| 306 | + ${CMAKE_SOURCE_DIR}/docs/jshelp.qhc ${JSHELP_QHC} |
| 307 | + COMMENT "Generating and moving help files..." |
| 308 | + VERBATIM |
| 309 | +) |
| 310 | + |
| 311 | +add_custom_target(helpgenerator ALL DEPENDS ${JSHELP_QCH} ${JSHELP_QHC}) |
| 312 | +add_dependencies(omodsim helpgenerator) |
| 313 | +add_dependencies(omodsim update_translations) |
0 commit comments