Skip to content

Commit ef0c9a9

Browse files
committed
Added install command for cmake
1 parent 69ccef4 commit ef0c9a9

15 files changed

+228
-180
lines changed

CMakeLists.txt

+76-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,79 @@ set(MB_QT_ENABLED ON)
2626
set(MB_C_SUPPORT_DISABLE ON)
2727
add_subdirectory(modbus/src)
2828

29-
add_subdirectory(src)
29+
add_subdirectory(src/core)
30+
31+
add_subdirectory(src/client)
32+
33+
add_subdirectory(src/server)
34+
35+
# Check if Doxygen is available
36+
find_package(Doxygen)
37+
38+
if (DOXYGEN_FOUND)
39+
message("Doxygen found: ${DOXYGEN_EXECUTABLE}")
40+
# Add a target to generate Doxygen documentation for the client
41+
add_custom_target(DoxygenClient
42+
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/DoxyfileClient
43+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc
44+
COMMENT "Generating Doxygen documentation for Client"
45+
VERBATIM
46+
)
47+
48+
# Add a target to generate Doxygen documentation for the server
49+
add_custom_target(DoxygenServer
50+
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/DoxyfileServer
51+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc
52+
COMMENT "Generating Doxygen documentation for Server"
53+
VERBATIM
54+
)
55+
56+
# Find qhelpgenerator executable
57+
find_program(QHELPGENERATOR_EXECUTABLE qhelpgenerator)
58+
59+
if (QHELPGENERATOR_EXECUTABLE)
60+
message("qhelpgenerator found: ${QHELPGENERATOR_EXECUTABLE}")
61+
62+
# Add a target to generate Qt help files for the server
63+
add_custom_target(QtHelpServer
64+
COMMAND ${QHELPGENERATOR_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/output/ModbusServer.qhcp
65+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc/output
66+
COMMENT "Generating Qt help files for Server"
67+
VERBATIM
68+
)
69+
70+
# Add a target to generate Qt help files for the client
71+
add_custom_target(QtHelpClient
72+
COMMAND ${QHELPGENERATOR_EXECUTABLE} ${CMAKE_SOURCE_DIR}/doc/output/ModbusClient.qhcp
73+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc/output
74+
COMMENT "Generating Qt help files for Client"
75+
VERBATIM
76+
)
77+
78+
# Make sure QtHelpServer runs after DoxygenServer
79+
add_dependencies(QtHelpServer DoxygenServer)
80+
81+
# Make sure QtHelpClient runs after DoxygenClient
82+
add_dependencies(QtHelpClient DoxygenClient)
83+
else()
84+
message(STATUS "qhelpgenerator not found. Qt help targets will not be generated.")
85+
endif()
86+
else()
87+
message(STATUS "Doxygen not found. Documentation targets will not be generated/regenerated.")
88+
endif()
89+
90+
install(TARGETS ${MB_LIBRARY_NAME} DESTINATION .)
91+
install(TARGETS ${MBTOOLS_CORE_LIB_NAME} DESTINATION .)
92+
install(TARGETS ${MBTOOLS_CLIENT_APP_NAME} DESTINATION .)
93+
install(TARGETS ${MBTOOLS_SERVER_APP_NAME} DESTINATION .)
94+
95+
# Install scripts
96+
# Collect Python files using GLOB
97+
file(GLOB MBTOOLS_SCRIPT_FILES "${CMAKE_SOURCE_DIR}/src/server/python/*.py")
98+
# Install Python files
99+
install(FILES ${MBTOOLS_SCRIPT_FILES} DESTINATION "./script/server")
100+
101+
# Install help files
102+
# Collect help files using GLOB
103+
file(GLOB MBTOOLS_HELP_FILES "${CMAKE_SOURCE_DIR}/doc/output/*.qch" "${CMAKE_SOURCE_DIR}/doc/output/*.qhc")
104+
install(FILES ${MBTOOLS_HELP_FILES} DESTINATION "./help")

ModbusTools.pro

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
TEMPLATE = subdirs
22

33
# Specify the location where the help files should be installed
4-
HELPDIR = $$OUT_PWD/bin/help
4+
HELPDIR = $$OUT_PWD/help
55

66
# List of help files to install
7-
help.files = $$PWD/../help/client/*.qch \
8-
$$PWD/../help/client/*.qhc \
9-
$$PWD/../help/server/*.qch \
10-
$$PWD/../help/server/*.qhc
7+
help.files = $$PWD/doc/output/*.qch \
8+
$$PWD/doc/output/*.qhc
119

1210
help.path = $$HELPDIR
1311
help.depends = $(first)

changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,7 @@ List of changes of new v0.4 version of ModbusTools:
149149

150150
* Fixed TCP Server delay while connecting (within ModbusLib subproject)
151151
* Added setting 'Max Connections' for max simultanious TCP server connections
152+
* Added support for script modules for the ModbusTools server
153+
* Added install command for cmake script
154+
152155

doc/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ c:\Qt\5.15.2\msvc2019_64\bin\assistant.exe -collectionFile "output/ModbusServer.
6262
Assumed application dir view:
6363
* server.exe
6464
* client.exe
65+
* ...
6566
* help : <dir>
6667
* ModbusClient.qch
6768
* ModbusClient.qhc

doc/output/ModbusClient.chm

0 Bytes
Binary file not shown.

doc/output/ModbusServer.chm

-2 Bytes
Binary file not shown.

src/CMakeLists.txt

-5
This file was deleted.

src/README.md

+136-91
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,9 @@
22

33
This page describes the process of building a ModbusTools project from source files.
44

5-
## Building ModbusTools from source on Windows
6-
7-
### Preparation
8-
9-
The ModbusTools project requires Qt version 5.8 or later.
10-
11-
1. Download qt-online-installer, follow the link and choose Windows version for installer:
12-
13-
https://www.qt.io/download-qt-installer
14-
15-
2. Run qt-online-installer and install all necessary components: Qt 5 (Qt5.15.2) framework.
16-
17-
Qt 5.8 or higher is needed so in `Select Components` window check `Archive` checkbox and push `Filter` button.
18-
Then is better to check latest version of Qt5.15 framework (e.g. 5.15.2)
19-
20-
3. Download and install git for Windows or use WSL and install git for WSL.
21-
22-
4. Make dir for binaries, e.g. in `<user-home-dir>\bin\ModbusTools` using Windows command console:
23-
```console
24-
>cd `<user-home-dir>`
25-
>mkdir bin\ModbusTools
26-
>cd bin\ModbusTools
27-
```
28-
5. Clone repository:
29-
```console
30-
$ git clone --recursive https://github.com/serhmarch/ModbusTools.git
31-
```
32-
33-
### Build using qmake
34-
35-
This example shows how to build `ModbusTools` for MSVC compiler using `qmake`.
36-
37-
1. Open Windows command console and initialize all MSVC compiler vars (e.g. include, lib) using `vcvarsall.bat` script.
38-
This script will be configured for x64 arch (use `...\vcvarsall.bat -help` to display all options):
39-
`console
40-
41-
> "c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
42-
> `
43-
44-
2. Run qmake to produce `Makefile`.
45-
This command will make `Release` version, for `Debug` replase with `"CONFIG+=debug"`:
46-
`console
47-
48-
> C:\Qt\5.15.2\msvc2019_64\bin\qmake.exe path\to\ModbusTools.pro -spec win32-msvc "CONFIG+=release"
49-
> `
50-
51-
3. Produce all make files:
52-
53-
```console
54-
>C:\Qt\Tools\QtCreator\bin\jom\jom.exe -f Makefile qmake_all
55-
```
56-
57-
4. Build project from Makefile's:
58-
```console
59-
>C:\Qt\Tools\QtCreator\bin\jom\jom.exe
60-
```
61-
62-
### Build using cmake
63-
64-
1. Run cmake to generate project (make) files.
65-
`CMAKE_PREFIX_PATH` must be set to installed Qt framewrok files:
66-
`console
67-
> cmake -DCMAKE_PREFIX_PATH:PATH=C:/Qt/5.15.2/msvc2019_64 -S path\to\ModbusTools -B .
68-
> `
69-
2. Make binaries (+ debug|release config):
70-
```console
71-
$ cmake --build .
72-
$ cmake --build . --config Debug
73-
$ cmake --build . --config Release
74-
```
75-
3. Resulting bin files is located in `Debug` or `Release` directory.
76-
77-
#### Build using CMakePresets.json
78-
79-
```console
80-
cmake --preset "Win64-MSVC"
81-
cmake --build --preset "Win64-MSVC-Debug"
82-
cmake --build --preset "Win64-MSVC-Release"
83-
```
84-
855
## Building ModbusTools from source on Linux
866

87-
### Preparation
7+
### Preparations
888

899
The ModbusTools project requires Qt version 5.8 or later.
9010

@@ -147,6 +67,46 @@ The ModbusTools project requires Qt version 5.8 or later.
14767
$ cd bin/ModbusTools
14868
```
14969

70+
### Build using cmake
71+
72+
1. Run cmake to generate project (make) files.
73+
74+
```console
75+
$ cmake -S ~/src/ModbusTools -B .
76+
```
77+
78+
2. Make binaries (+ debug|release config):
79+
```console
80+
$ cmake --build .
81+
$ cmake --build . --config Debug
82+
$ cmake --build . --config Release
83+
```
84+
3. Resulting bin files is located in `./bin` directory.
85+
86+
#### Build using CMakePresets.json
87+
88+
```console
89+
cmake --preset "Linux-Debug"
90+
cmake --build --preset "Linux-Debug"
91+
92+
cmake --preset "Linux-Release"
93+
cmake --build --preset "Linux-Release"
94+
```
95+
96+
### Install using cmake
97+
98+
To install compiled binaries and other necessary files run next command:
99+
100+
```console
101+
$ cmake --install <build_dir> --prefix <install_dest_dir>
102+
```
103+
104+
Next command installs files from build dir into ModbusTools dir of user's home directory:
105+
106+
```console
107+
$ cmake --install . --prefix "$HOME/ModbusTools"
108+
```
109+
150110
### Build using qmake
151111

152112
1. Run qmake to create Makefile for build:
@@ -189,30 +149,98 @@ The ModbusTools project requires Qt version 5.8 or later.
189149
-rwxr-xr-x 1 march march 269888 Sep 27 16:24 libmodbus.so.1.0.0
190150
```
191151

192-
### Build using cmake
152+
## Building ModbusTools from source on Windows
193153

194-
1. Run cmake to generate project (make) files.
154+
### Preparation
195155

196-
```console
197-
$ cmake -S ~/src/ModbusTools -B .
198-
```
156+
The ModbusTools project requires Qt version 5.8 or later.
157+
158+
1. Download qt-online-installer, follow the link and choose Windows version for installer:
159+
160+
https://www.qt.io/download-qt-installer
161+
162+
2. Run qt-online-installer and install all necessary components: Qt 5 (Qt5.15.2) framework.
163+
164+
Qt 5.8 or higher is needed so in `Select Components` window check `Archive` checkbox and push `Filter` button.
165+
Then is better to check latest version of Qt5.15 framework (e.g. 5.15.2)
166+
167+
3. Download and install git for Windows or use WSL and install git for WSL.
168+
169+
4. Make dir for binaries, e.g. in `<user-home-dir>\bin\ModbusTools` using Windows command console:
170+
```console
171+
>cd `<user-home-dir>`
172+
>mkdir bin\ModbusTools
173+
>cd bin\ModbusTools
174+
```
175+
5. Clone repository:
176+
```console
177+
$ git clone --recursive https://github.com/serhmarch/ModbusTools.git
178+
```
179+
180+
### Build using qmake
181+
182+
This example shows how to build `ModbusTools` for MSVC compiler using `qmake`.
199183

184+
1. Open Windows command console and initialize all MSVC compiler vars (e.g. include, lib) using `vcvarsall.bat` script.
185+
This script will be configured for x64 arch (use `...\vcvarsall.bat -help` to display all options):
186+
`console
187+
188+
> "c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
189+
> `
190+
191+
2. Run qmake to produce `Makefile`.
192+
This command will make `Release` version, for `Debug` replase with `"CONFIG+=debug"`:
193+
`console
194+
195+
> C:\Qt\5.15.2\msvc2019_64\bin\qmake.exe path\to\ModbusTools.pro -spec win32-msvc "CONFIG+=release"
196+
> `
197+
198+
3. Produce all make files:
199+
200+
```console
201+
>C:\Qt\Tools\QtCreator\bin\jom\jom.exe -f Makefile qmake_all
202+
```
203+
204+
4. Build project from Makefile's:
205+
```console
206+
>C:\Qt\Tools\QtCreator\bin\jom\jom.exe
207+
```
208+
209+
### Build using cmake
210+
211+
1. Run cmake to generate project (make) files.
212+
`CMAKE_PREFIX_PATH` must be set to installed Qt framewrok files:
213+
`console
214+
> cmake -DCMAKE_PREFIX_PATH:PATH=C:/Qt/5.15.2/msvc2019_64 -S path\to\ModbusTools -B .
215+
> `
200216
2. Make binaries (+ debug|release config):
201217
```console
202218
$ cmake --build .
203219
$ cmake --build . --config Debug
204220
$ cmake --build . --config Release
205221
```
206-
3. Resulting bin files is located in `./bin` directory.
222+
3. Resulting bin files is located in `Debug` or `Release` directory.
207223

208224
#### Build using CMakePresets.json
209225

210226
```console
211-
cmake --preset "Linux-Debug"
212-
cmake --build --preset "Linux-Debug"
227+
cmake --preset "Win64-MSVC"
228+
cmake --build --preset "Win64-MSVC-Debug"
229+
cmake --build --preset "Win64-MSVC-Release"
230+
```
213231

214-
cmake --preset "Linux-Release"
215-
cmake --build --preset "Linux-Release"
232+
### Install using cmake
233+
234+
To install compiled binaries and other necessary files run next command:
235+
236+
```console
237+
> cmake --install <build_dir> --prefix <install_dest_dir>
238+
```
239+
240+
Next command installs files from build dir into ModbusTools dir of user's home directory:
241+
242+
```console
243+
> cmake --install . --prefix "%USERPROFILE%\ModbusTools"
216244
```
217245

218246
## Build Docker Image
@@ -232,6 +260,23 @@ The GUIs will be exposed via a web server on port 6080.
232260
```
233261
3. Access the application at `http://localhost:6080/vnc.html`
234262

263+
# Install ModbusTools
264+
265+
General view of ModbusTools applications dir:
266+
* modbus.dll
267+
* core.dll
268+
* server.exe
269+
* client.exe
270+
* script : [dir]
271+
* server : [dir]
272+
* mbserver.py
273+
* help : [dir]
274+
* ModbusClient.qch
275+
* ModbusClient.qhc
276+
* ModbusServer.qch
277+
* ModbusServer.qhc
278+
279+
## Install using cmake
235280

236281
## Arch Linux Install
237282

src/client/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ project(
66
VERSION ${PROJECT_VERSION}
77
LANGUAGES CXX)
88

9-
set(MBTOOLS_CLIENT_APP_NAME client)
9+
set(MBTOOLS_CLIENT_APP_NAME client CACHE INTERNAL "Name of the ModbusTools client application")
1010

1111
message("MBTOOLS: Start configure client '${MBTOOLS_CLIENT_APP_NAME}'")
1212

0 commit comments

Comments
 (0)