### Configure Fledge IEC104 Plugin Build with CMake Options Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/README.rst These examples demonstrate various ways to configure the Fledge IEC104 plugin build using CMake, including default behavior, setting `FLEDGE_ROOT`, and overriding paths for source, includes, libraries, and installation. ```console $ cmake .. $ export FLEDGE_ROOT=/some_fledge_setup $ cmake .. $ cmake -DFLEDGE_SRC=/home/source/develop/Fledge .. $ cmake -DFLEDGE_INCLUDE=/dev-package/include .. $ cmake -DFLEDGE_LIB=/home/dev/package/lib .. $ cmake -DFLEDGE_INSTALL=/home/source/develop/Fledge .. $ cmake -DFLEDGE_INSTALL=/usr/local/fledge .. ``` -------------------------------- ### Set Build Version and Install Plugin Library Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Sets the SOVERSION property for the shared library to 1. It then defines the installation target for the plugin. If the `FLEDGE_INSTALL` variable is set, the compiled shared library is installed to the specified Fledge plugin directory. ```CMake set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1) set(FLEDGE_INSTALL "" CACHE INTERNAL "") 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() ``` -------------------------------- ### Clone and Prepare lib60870 Source Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/README.rst This sequence of commands clones the lib60870 repository from GitHub and sets an environment variable `LIB_104` to its current working directory, which is required for subsequent build steps. ```console $ git clone https://github.com/mz-automation/lib60870.git $ cd lib60870 $ export LIB_104=`pwd` ``` -------------------------------- ### Build lib60870 Library Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/README.rst These commands navigate into the `lib60970-C` directory, create a build directory, configure the project using CMake, and then compile the lib60870 library using Make. ```console $ cd lib60970-C $ mkdir build $ cd build $ cmake .. $ make ``` -------------------------------- ### Build Fledge IEC104 South Plugin Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/README.rst This sequence of commands creates a build directory within the plugin's source tree, configures the project using CMake, and then compiles the Fledge IEC104 South plugin using Make. ```console $ mkdir build $ cd build $ cmake .. $ make ``` -------------------------------- ### Configure Include and Link Directories Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Adds various include directories necessary for compilation, including the plugin's own headers, Fledge's headers, and `lib60870`'s headers. It also adds Fledge's library link directories and conditionally includes RapidJSON if `FLEDGE_SRC` is defined. ```CMake include_directories(include) include_directories(${FLEDGE_INCLUDE_DIRS}) include_directories(${LIB60870}/src/hal/inc) link_directories(${FLEDGE_LIB_DIRS}) 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 and Link Dependencies Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Creates the shared library for the plugin using all discovered source files and the generated version header. It then links all necessary Fledge libraries, `lib60870`, and other system libraries like `pthread` and `dl` required for the plugin's runtime. ```CMake add_library(${PROJECT_NAME} SHARED ${SOURCES} version.h) target_link_libraries(${PROJECT_NAME} ${NEEDED_FLEDGE_LIBS}) target_link_libraries(${PROJECT_NAME} -L/usr/local/lib -llib60870) target_link_libraries(${PROJECT_NAME} -lpthread -ldl) ``` -------------------------------- ### Discover Source Files and Set lib60870 Path Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Uses `file(GLOB)` to find all C++ source files (`.cpp`) in the current directory. It also sets the path to the `lib60870-C` library, typically located in the user's home directory. ```CMake file(GLOB SOURCES *.cpp) set(LIB60870 "$ENV{HOME}/lib60870/lib60870-C") ``` -------------------------------- ### Add Fledge IEC104 Service via cURL Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/README.rst This cURL command demonstrates how to add a new IEC104 south service to Fledge using its web API, specifying the service name, type, plugin, and enabling it. ```console $ curl -sX POST http://localhost:8081/fledge/service -d '{"name":"iec104_name","type":"south","plugin":"iec104","enabled":true}' ``` -------------------------------- ### Generate Version Header File Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Defines a custom build command to generate the `version.h` header file. This file is created from a `VERSION` file using a `mkversion` script, ensuring that the plugin's build includes dynamic version information. ```CMake 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}) ``` -------------------------------- ### Configure CMake Project and C++ Compiler Flags Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Sets the minimum required CMake version, defines the project name for the IEC104 plugin, and configures C++11 standard with O3 optimization for all C++ compilations. ```CMake cmake_minimum_required(VERSION 2.8) project(iec104) set(CMAKE_CXX_FLAGS "-std=c++11 -O3") ``` -------------------------------- ### Define Fledge Plugin Type and Core Dependencies Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Specifies the type of the Fledge plugin as 'south' and lists the essential Fledge libraries, such as 'common-lib', that are required for this plugin to function correctly. ```CMake set(PLUGIN_TYPE "south") set(NEEDED_FLEDGE_LIBS common-lib) ``` -------------------------------- ### Locate Fledge Package and Handle Build Errors Source: https://github.com/fledge-iot/fledge-south-iec104/blob/develop/CMakeLists.txt Configures CMake to find the Fledge package. If Fledge is not found, it attempts to clean up any existing build artifacts (like `Makefile`) and then terminates the build process with a fatal error message, ensuring a clean state for subsequent attempts. ```CMake set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) find_package(Fledge) 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() message(FATAL_ERROR "Fledge plugin '${PROJECT_NAME}' build error.") endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.