Skip to content

Commit da603b3

Browse files
committed
Support for Windows compilation
Thanks for contributions from: - RalfOGit <https://github.com/RalfOGit> - MightyPiggie <https://github.com/MightyPiggie> PR: #5 Signed-off-by: Mateusz Mazur <[email protected]>
1 parent bc6f5fe commit da603b3

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

.github/workflows/cmake-multi-platform.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ jobs:
3030
- os: ubuntu-latest
3131
c_compiler: clang
3232
cpp_compiler: clang++
33-
exclude:
3433
- os: windows-latest
3534
c_compiler: cl
35+
cpp_compiler: cl
36+
exclude:
3637
- os: windows-latest
3738
c_compiler: gcc
3839
- os: windows-latest
@@ -67,7 +68,8 @@ jobs:
6768
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
6869
-DMODBUS_EXAMPLE=ON
6970
-DMODBUS_TESTS=ON
70-
-DMODBUS_COMMUNICATION=${{ matrix.os == 'windows-latest' && 'OFF' || matrix.os == 'ubuntu-latest' && 'ON' }}
71+
-DMODBUS_TCP_COMMUNICATION=${{ matrix.os == 'windows-latest' && 'OFF' || matrix.os == 'ubuntu-latest' && 'ON' }}
72+
-DMODBUS_SERIAL_COMMUNICATION=${{ matrix.os == 'windows-latest' && 'OFF' || matrix.os == 'ubuntu-latest' && 'ON' }}
7173
-S ${{ github.workspace }}
7274
7375
- name: Build

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
*.exe
3131
*.out
3232
*.app
33-
3433
build
3534

35+
# Windows specific
36+
out
37+
.vs
38+
3639
# Gtags
3740
GTAGS
3841
GRTAGS

CMakeLists.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(protocolConverter)
2+
project(modbus)
33

44
set(CMAKE_CXX_STANDARD 17)
55

@@ -11,7 +11,14 @@ endif()
1111

1212
option(MODBUS_EXAMPLE "Build example program" OFF)
1313
option(MODBUS_TESTS "Build tests" OFF)
14-
option(MODBUS_COMMUNICATION "Use Modbus communication library" ON)
14+
option(MODBUS_TCP_COMMUNICATION "Use Modbus TCP communication library" ON)
15+
16+
if(NOT win32)
17+
# Serial not supported on Windows
18+
option(MODBUS_SERIAL_COMMUNICATION "Use Modbus serial communication library" OFF) # not supported by windows platform
19+
else()
20+
message(STATUS "Modbus Serial not supported on Windows.")
21+
endif()
1522

1623
add_subdirectory(src)
1724

src/CMakeLists.txt

+8-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ target_include_directories(Modbus_Core PUBLIC ${PROJECT_SOURCE_DIR}/include PRIV
2323
add_library(Modbus)
2424
target_link_libraries(Modbus Modbus_Core)
2525

26+
if(MODBUS_SERIAL_COMMUNICATION)
27+
message(STATUS "Enabling Modbus Serial")
28+
add_subdirectory(Serial)
29+
target_link_libraries(Modbus Modbus_Serial)
30+
endif()
2631

27-
if(MODBUS_COMMUNICATION)
28-
message("Modbus communication is experimental")
32+
if(MODBUS_TCP_COMMUNICATION)
33+
message(STATUS "Enabling Modbus Serial")
2934
add_subdirectory(TCP)
30-
add_subdirectory(Serial)
31-
target_link_libraries(Modbus Modbus_TCP Modbus_Serial)
35+
target_link_libraries(Modbus Modbus_TCP)
3236
endif()

tests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ project(Google_tests)
22
add_subdirectory(googletest)
33
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
44

5+
if (MSVC)
6+
set(gtest_force_shared_crt on)
7+
endif()
8+
59
set(TestFiles MB/ModbusRequestTests.cpp
610
MB/ModbusResponseTests.cpp
711
MB/ModbusExceptionTests.cpp

0 commit comments

Comments
 (0)