This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 230
/
CMakeLists.txt
167 lines (140 loc) · 4.68 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
cmake_minimum_required (VERSION 3.11)
# Check if we are the root project
set(is_root OFF)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(is_root ON)
endif()
# Project declaration
set(OPENDNP3_MAJOR_VERSION 3)
set(OPENDNP3_MINOR_VERSION 1)
set(OPENDNP3_MICRO_VERSION 2)
set(OPENDNP3_VERSION ${OPENDNP3_MAJOR_VERSION}.${OPENDNP3_MINOR_VERSION}.${OPENDNP3_MICRO_VERSION})
project(opendnp3 VERSION ${OPENDNP3_VERSION})
# Packing variable
set(CPACK_PACKAGE_NAME opendnp3)
set(CPACK_PACKAGE_VENDOR "Step Function I/O LLC")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "DNP3 (IEEE-1815) protocol stack")
set(CPACK_PACKAGE_DESCRIPTION "OpenDNP3 is the de facto reference implementation of IEEE-1815 (DNP3), a standards-based SCADA protocol.")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://dnp3.github.io/")
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_LIST_DIR}/LICENSE)
set(CPACK_RESOURCE_FILE_README ${CMAKE_CURRENT_LIST_DIR}/README.md)
set(CPACK_PACKAGE_VERSION_MAJOR ${OPENDNP3_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${OPENDNP3_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${OPENDNP3_MICRO_VERSION})
# Minimum compiler version
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "Visual Studio earlier than 2015 does not implement std::chrono::steady_clock properly. Use a modern compiler.")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Clang utilities
include(./cmake/ClangFormat.cmake)
include(./cmake/ClangTidy.cmake)
if(WIN32)
set(DNP3_STATIC_LIBS_BY_DEFAULT ON)
else()
set(DNP3_STATIC_LIBS_BY_DEFAULT OFF)
endif()
# Compilation options
option(DNP3_TLS "Build TLS client/server support (requires OpenSSL)" OFF)
option(DNP3_TESTS "Build unit and integration tests" OFF)
option(DNP3_EXAMPLES "Build example applications" OFF)
option(DNP3_FUZZING "Build Google OSS-Fuzz targets" OFF)
option(DNP3_COVERAGE "Enable code coverage target" OFF)
option(DNP3_JAVA "Building the native Java bindings" OFF)
if(WIN32)
option(DNP3_DOTNET "Build the .NET bindings" OFF)
set(DNP3_DOTNET_FRAMEWORK_VERSION "v4.5" CACHE STRING "The target .NET framework version for the .NET components")
endif()
option(DNP3_EVERYTHING "Build all optional targets" OFF)
option(DNP3_STATIC_LIBS "Build static libraries instead of shared libraries" ${DNP3_STATIC_LIBS_BY_DEFAULT})
if(DNP3_EVERYTHING)
set(DNP3_TLS ON)
set(DNP3_TESTS ON)
set(DNP3_EXAMPLES ON)
set(DNP3_FUZZING ON)
set(DNP3_JAVA ON)
if(WIN32)
set(DNP3_DOTNET ON)
endif()
endif()
if(DNP3_STATIC_LIBS)
set(BUILD_SHARED_LIBS OFF)
# the java bindings are always explicitly built as a shared library
# so fpic is required if building the main library statically
if(DNP3_JAVA)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
else()
if(WIN32)
message(FATAL_ERROR "building shared libraries not supported on Windows")
endif()
set(BUILD_SHARED_LIBS ON)
endif()
# External dependencies
include(./deps/asio.cmake)
include(./deps/exe4cpp.cmake)
include(./deps/ser4cpp.cmake)
if(DNP3_TLS)
find_package(OpenSSL 1.1.1 REQUIRED)
endif()
if(DNP3_TESTS OR DNP3_FUZZING)
include(./deps/catch.cmake)
endif()
# Set coverage flags if necessary
if(DNP3_COVERAGE)
include(./cmake/CodeCoverage.cmake)
add_coverage_flags()
endif()
# Library
add_subdirectory(./cpp/lib)
# Tests
if(DNP3_TESTS)
enable_testing()
add_subdirectory(./cpp/tests/dnp3mocks)
add_subdirectory(./cpp/tests/unit)
add_subdirectory(./cpp/tests/asiotests)
add_subdirectory(./cpp/tests/integration)
if(DNP3_COVERAGE)
define_coverage_target(
NAME coverage
DIRECTORY cpp/lib
TARGETS unittests asiotests integrationtests
)
endif()
endif()
# Examples
if(DNP3_EXAMPLES)
add_subdirectory(./cpp/examples/decoder)
add_subdirectory(./cpp/examples/master)
add_subdirectory(./cpp/examples/master-gprs)
add_subdirectory(./cpp/examples/master-udp)
add_subdirectory(./cpp/examples/outstation)
add_subdirectory(./cpp/examples/outstation-udp)
if(DNP3_TLS)
add_subdirectory(./cpp/examples/tls/master)
add_subdirectory(./cpp/examples/tls/master-gprs)
add_subdirectory(./cpp/examples/tls/outstation)
endif()
endif()
# Fuzzing
if(DNP3_FUZZING)
if(NOT DNP3_TESTS)
# DNP3 mocks is needed for the fuzzing
add_subdirectory(./cpp/tests/dnp3mocks)
endif()
add_subdirectory(./cpp/tests/fuzz)
endif()
if(DNP3_JAVA)
add_subdirectory(./java)
endif()
if(WIN32 AND DNP3_DOTNET)
message("The .NET framework version is: ${DNP3_DOTNET_FRAMEWORK_VERSION}")
add_subdirectory(./dotnet)
endif()
# Define utility targets
if(is_root)
define_clang_format()
define_clang_tidy()
endif()
# Packaging
include(CPack)