-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
138 lines (113 loc) · 4.63 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
cmake_minimum_required(VERSION 3.16)
# Set the plugin name to build
project(iec61850)
# Supported options:
# -DFLEDGE_INCLUDE
# -DFLEDGE_LIB
# -DFLEDGE_SRC
# -DFLEDGE_INSTALL
#
# If no -D options are given and FLEDGE_ROOT environment variable is set
# then Fledge libraries and header files are pulled from FLEDGE_ROOT path.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
message(STATUS ${CMAKE_CXX_FLAGS})
if (${CMAKE_BUILD_TYPE} STREQUAL Coverage)
message("Coverage is going to be generated")
enable_testing()
add_subdirectory(tests)
include(CodeCoverage)
append_coverage_compiler_flags()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
# set(GCOVR_ADDITIONAL_ARGS "--exclude-unreachable-branches" "--exclude-throw-branches" )
#
# setup_target_for_coverage_gcovr_sonar(NAME "${PROJECT_NAME}_coverage_sonar"
# EXECUTABLE RunTests
# DEPENDENCIES RunTests
# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
# EXCLUDE "tests/*"
# )
#
# setup_target_for_coverage_gcovr_html(NAME "${PROJECT_NAME}_coverage_html"
# EXECUTABLE RunTests
# DEPENDENCIES RunTests
# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}"
# EXCLUDE "tests/*"
# )
else()
message("Build without Coverage")
set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -Wall")
endif()
# Generation version header file
set_source_files_properties(version.h PROPERTIES GENERATED TRUE)
add_custom_command(
OUTPUT version.h
DEPENDS ${CMAKE_SOURCE_DIR}/VERSION
COMMAND ${CMAKE_SOURCE_DIR}/mkversion ${CMAKE_SOURCE_DIR}
COMMENT "Generating version header"
VERBATIM
)
include_directories(${CMAKE_BINARY_DIR})
# Set plugin type (south, north, filter)
set(PLUGIN_TYPE "north")
# Add here all needed Fledge libraries as list
set(NEEDED_FLEDGE_LIBS common-lib)
# Find source files
file(GLOB SOURCES src/*.cpp)
# Find Fledge includes and libs, by including FindFledge.cmak file
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Fledge)
# If errors: make clean and remove Makefile
if (NOT FLEDGE_FOUND)
if (EXISTS "${CMAKE_BINARY_DIR}/Makefile")
execute_process(COMMAND make clean WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
file(REMOVE "${CMAKE_BINARY_DIR}/Makefile")
endif()
# Stop the build process
message(FATAL_ERROR "Fledge plugin '${PROJECT_NAME}' build error.")
endif()
# On success, FLEDGE_INCLUDE_DIRS and FLEDGE_LIB_DIRS variables are set
# Add ./include
include_directories(include)
# Add Fledge include dir(s)
include_directories(${FLEDGE_INCLUDE_DIRS})
# Add Fledge lib path
link_directories(${FLEDGE_LIB_DIRS})
# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES} version.h)
# Add Fledge library names
target_link_libraries(${PROJECT_NAME} ${NEEDED_FLEDGE_LIBS})
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/der-scheduling)
set(WITH_SCHEDULING 1)
else()
message("NOTE: der-scheduling is required for scheduling support!")
endif(EXISTS ${CMAKE_CURRENT_LIST_DIR}/dependencies/der-scheduling)
if(WITH_SCHEDULING)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/dependencies/der-scheduling/ der_scheduler)
target_link_libraries(${PROJECT_NAME} der_scheduler)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/dependencies/der-scheduling/src/scheduler)
endif(WITH_SCHEDULING)
# Add the libiec61850
find_library(LIBIEC61850 libiec61850.a)
if (NOT LIBIEC61850)
message(FATAL_ERROR "The 61850 library 'libiec61850' was not found (in the standard lib dir)\n"
"Please build and install the libiec61850 library")
return()
endif()
target_link_libraries(${PROJECT_NAME} -L/usr/local/lib -liec61850)
# Add additional libraries
target_link_libraries(${PROJECT_NAME} )
# Set the build version
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1)
set(FLEDGE_INSTALL "" CACHE INTERNAL "")
# Install library
if (FLEDGE_INSTALL)
message(STATUS "Installing ${PROJECT_NAME} in ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME}")
install(TARGETS ${PROJECT_NAME} DESTINATION ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME})
endif()
# Doc with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(docs/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Generating documentation with Doxygen" VERBATIM)
endif(DOXYGEN_FOUND)