Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- code for IEC 104 to pivot and pivot to IEC 104 conversion #3

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
cmake_minimum_required(VERSION 2.8)

# Set the plugin name to build
project(iec104_pivot_filter)

# 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} -O3 --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 --coverage")
set(GCOVR_ADDITIONAL_ARGS "--exclude-unreachable-branches" "--exclude-throw-branches" )

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++11 -O3")
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 "filter")
# 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

if (FLEDGE_SRC)
message(STATUS "Using third-party includes " ${FLEDGE_SRC}/C/thirdparty)
include_directories(${FLEDGE_SRC}/C/thirdparty/rapidjson/include)
endif()


# Create shared library
add_library(${PROJECT_NAME} SHARED ${SOURCES} version.h)

# Add Fledge library names
target_link_libraries(${PROJECT_NAME} ${NEEDED_FLEDGE_LIBS})

target_link_libraries(${PROJECT_NAME} -L/usr/local/lib -llib60870)

# Add additional libraries
target_link_libraries(${PROJECT_NAME} -lpthread -ldl)

# 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()
139 changes: 139 additions & 0 deletions FindFledge.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# This CMake file locates the Fledge header files and libraries
#
# The following variables are set:
# FLEDGE_INCLUDE_DIRS - Path(s) to Fledge headers files found
# FLEDGE_LIB_DIRS - Path to Fledge shared libraries
# FLEDGE_SUCCESS - Set on succes
#
# In case of error use SEND_ERROR and return()
#

# Set defaults paths of installed Fledge SDK package
set(FLEDGE_DEFAULT_INCLUDE_DIR "/usr/include/fledge" CACHE INTERNAL "")
set(FLEDGE_DEFAULT_LIB_DIR "/usr/lib/fledge" CACHE INTERNAL "")

# CMakeLists.txt options
set(FLEDGE_SRC "" CACHE INTERNAL "")
set(FLEDGE_INCLUDE "" CACHE INTERNAL "")
set(FLEDGE_LIB "" CACHE INTERNAL "")

# Return variables
set(FLEDGE_INCLUDE_DIRS "" CACHE INTERNAL "")
set(FLEDGE_LIB_DIRS "" CACHE INTERNAL "")
set(FLEDGE_FOUND "" CACHE INTERNAL "")

# No options set
# If FLEDGE_ROOT env var is set, use it
if (NOT FLEDGE_SRC AND NOT FLEDGE_INCLUDE AND NOT FLEDGE_LIB)
if (DEFINED ENV{FLEDGE_ROOT})
message(STATUS "No options set.\n"
" +Using found FLEDGE_ROOT $ENV{FLEDGE_ROOT}")
set(FLEDGE_SRC $ENV{FLEDGE_ROOT})
endif()
endif()

# -DFLEDGE_SRC=/some_path or FLEDGE_ROOT path
# Set return variable FLEDGE_INCLUDE_DIRS
if (FLEDGE_SRC)
unset(_INCLUDE_LIST CACHE)
file(GLOB_RECURSE _INCLUDE_COMMON "${FLEDGE_SRC}/C/common/*.h")
file(GLOB_RECURSE _INCLUDE_SERVICES "${FLEDGE_SRC}/C/services/common/*.h")
list(APPEND _INCLUDE_LIST ${_INCLUDE_COMMON} ${_INCLUDE_SERVICES})
foreach(_ITEM ${_INCLUDE_LIST})
get_filename_component(_ITEM_PATH ${_ITEM} DIRECTORY)
list(APPEND FLEDGE_INCLUDE_DIRS ${_ITEM_PATH})
endforeach()
unset(INCLUDE_LIST CACHE)

list(REMOVE_DUPLICATES FLEDGE_INCLUDE_DIRS)

string (REPLACE ";" "\n +" DISPLAY_PATHS "${FLEDGE_INCLUDE_DIRS}")
if (NOT DEFINED ENV{FLEDGE_ROOT})
message(STATUS "Using -DFLEDGE_SRC option for includes\n +" "${DISPLAY_PATHS}")
else()
message(STATUS "Using FLEDGE_ROOT for includes\n +" "${DISPLAY_PATHS}")
endif()

if (NOT FLEDGE_INCLUDE_DIRS)
message(SEND_ERROR "Needed Fledge header files not found in path ${FLEDGE_SRC}/C")
return()
endif()
else()
# -DFLEDGE_INCLUDE=/some_path
if (NOT FLEDGE_INCLUDE)
set(FLEDGE_INCLUDE ${FLEDGE_DEFAULT_INCLUDE_DIR})
message(STATUS "Using Fledge dev package includes " ${FLEDGE_INCLUDE})
else()
message(STATUS "Using -DFLEDGE_INCLUDE option " ${FLEDGE_INCLUDE})
endif()
# Remove current value from cache
unset(_FIND_INCLUDES CACHE)
# Get up to date var from find_path
find_path(_FIND_INCLUDES NAMES plugin_api.h PATHS ${FLEDGE_INCLUDE})
if (_FIND_INCLUDES)
list(APPEND FLEDGE_INCLUDE_DIRS ${_FIND_INCLUDES})
endif()
# Remove current value from cache
unset(_FIND_INCLUDES CACHE)

if (NOT FLEDGE_INCLUDE_DIRS)
message(SEND_ERROR "Needed Fledge header files not found in path ${FLEDGE_INCLUDE}")
return()
endif()
endif()

#
# Fledge Libraries
#
# Check -DFLEDGE_LIB=/some path is valid
# or use FLEDGE_SRC/cmake_build/C/lib
# FLEDGE_SRC might have been set to FLEDGE_ROOT above
#
if (FLEDGE_SRC)
# Set return variable FLEDGE_LIB_DIRS
set(FLEDGE_LIB "${FLEDGE_SRC}/cmake_build/C/lib")

if (NOT DEFINED ENV{FLEDGE_ROOT})
message(STATUS "Using -DFLEDGE_SRC option for libs \n +" "${FLEDGE_SRC}/cmake_build/C/lib")
else()
message(STATUS "Using FLEDGE_ROOT for libs \n +" "${FLEDGE_SRC}/cmake_build/C/lib")
endif()

if (NOT EXISTS "${FLEDGE_SRC}/cmake_build")
message(SEND_ERROR "Fledge has not been built yet in ${FLEDGE_SRC} Compile it first.")
return()
endif()

# Set return variable FLEDGE_LIB_DIRS
set(FLEDGE_LIB_DIRS "${FLEDGE_SRC}/cmake_build/C/lib")
else()
if (NOT FLEDGE_LIB)
set(FLEDGE_LIB ${FLEDGE_DEFAULT_LIB_DIR})
message(STATUS "Using Fledge dev package libs " ${FLEDGE_LIB})
else()
message(STATUS "Using -DFLEDGE_LIB option " ${FLEDGE_LIB})
endif()
# Set return variable FLEDGE_LIB_DIRS
set(FLEDGE_LIB_DIRS ${FLEDGE_LIB})
endif()

# Check NEEDED_FLEDGE_LIBS in libraries in FLEDGE_LIB_DIRS
# NEEDED_FLEDGE_LIBS variables comes from CMakeLists.txt
foreach(_LIB ${NEEDED_FLEDGE_LIBS})
# Remove current value from cache
unset(_FOUND_LIB CACHE)
# Get up to date var from find_library
find_library(_FOUND_LIB NAME ${_LIB} PATHS ${FLEDGE_LIB_DIRS})
if (_FOUND_LIB)
# Extract path form founf library file
get_filename_component(_DIR_LIB ${_FOUND_LIB} DIRECTORY)
else()
message(SEND_ERROR "Needed Fledge library ${_LIB} not found in ${FLEDGE_LIB_DIRS}")
return()
endif()
# Remove current value from cache
unset(_FOUND_LIB CACHE)
endforeach()

# Set return variable FLEDGE_FOUND
set(FLEDGE_FOUND "true")
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0
Loading