Skip to content

Commit

Permalink
Split project into multiple plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
zinccyy committed Jan 3, 2023
1 parent f41ab13 commit 4660991
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 31 deletions.
47 changes: 17 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ project(sysrepo-plugin-system C)

include(CompileOptions.cmake)

set(PLUGIN_LIRBARY_NAME srplg-ietf-system-core)
set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-system-core")

set(PLUGIN 0 CACHE BOOL "Build a plugin")
# set(PLUGIN 0 CACHE BOOL "Build a plugin")
option(ENABLE_BUILD_TESTS, "Build tests" OFF)

# local includes
Expand All @@ -14,13 +14,13 @@ include_directories(
${CMAKE_SOURCE_DIR}/deps/uthash/include
)

# first - find needed and optional packages
# find needed and optional packages
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
find_package(SYSREPO REQUIRED)
find_package(LIBYANG REQUIRED)
find_package(SRPC REQUIRED)
find_package(UMGMT REQUIRED)
find_package(LIBSYSTEMD)
find_package(LIBSYSTEMD REQUIRED)
find_package(AUGYANG)

# package includes
Expand All @@ -29,11 +29,12 @@ include_directories(
${LIBYANG_INCLUDE_DIRS}
${SRPC_INCLUDE_DIRS}
${UMGMT_INCLUDE_DIRS}
${SYSTEMD_INCLUDE_DIRS}
)

# sources
set(
SOURCES
CORE_SOURCES

src/core/common.c
src/core/ly_tree.c
Expand Down Expand Up @@ -79,33 +80,19 @@ set(
src/core/api/system/authentication/change.c
)

# build plugin core library
add_library(${PLUGIN_LIRBARY_NAME} STATIC ${SOURCES})
install(TARGETS ${PLUGIN_LIRBARY_NAME} DESTINATION lib)

# if(SYSTEMD_FOUND)
# if(DEFINED SYSTEMD_IFINDEX)
# add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX})
# else()
# message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it")
# endif()

# add_compile_definitions(SYSTEMD)
# target_link_libraries(
# ${CMAKE_PROJECT_NAME}
# ${SYSTEMD_LIBRARIES}
# )
# include_directories(
# ${SYSTEMD_INCLUDE_DIRS}
# )
# endif()
# build plugin static library
add_library(${PLUGIN_CORE_LIBRARY_NAME} STATIC ${CORE_SOURCES})
install(TARGETS ${PLUGIN_CORE_LIBRARY_NAME} DESTINATION lib)

# add main plugin to the build process
add_subdirectory("src/plugins/ietf-system")

# # augyang support
# if(AUGYANG_FOUND)
# add_compile_definitions(AUGYANG)
# else(AUGYANG_FOUND)
# message(WARNING "AUGYANG not found - augeas support will be disabled")
# endif()
if(AUGYANG_FOUND)
add_subdirectory("src/plugins/ietf-system-augeas")
else(AUGYANG_FOUND)
message(WARNING "AUGYANG not found - disabled build of the augeas specific plugin")
endif()

if(ENABLE_BUILD_TESTS)
find_package(CMOCKA REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

volatile int exit_application = 0;

// extern needed data to build the plugin executable
extern const char *PLUGIN_NAME;
extern int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data);
extern void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data);
Expand Down
40 changes: 40 additions & 0 deletions src/plugins/ietf-system-augeas/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.0)

set(PLUGIN_LIBRARY_NAME "srplg-ietf-system-augeas")
set(PLUGIN_EXECUTABLE_NAME "ietf-system-augeas-plugin")

set(
PLUGIN_SOURCES

plugin.c
)

# add plugin as a sysrepo-plugind library
add_library(
${PLUGIN_LIBRARY_NAME}
MODULE
${PLUGIN_SOURCES}
)

add_executable(
${PLUGIN_EXECUTABLE_NAME}

${PLUGIN_SOURCES}
${CMAKE_SOURCE_DIR}/src/main.c
)

target_link_libraries(
${PLUGIN_EXECUTABLE_NAME}

# link against the core plugin library
${PLUGIN_CORE_LIBRARY_NAME}

# link other external libraries
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${UMGMT_LIBRARIES}
)

install(TARGETS ${PLUGIN_LIBRARY_NAME} DESTINATION lib)
install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin)
11 changes: 11 additions & 0 deletions src/plugins/ietf-system-augeas/plugin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "plugin.h"

int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data)
{
int error = SR_ERR_OK;
return error;
}

void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data)
{
}
21 changes: 21 additions & 0 deletions src/plugins/ietf-system-augeas/plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* telekom / sysrepo-plugin-system
*
* This program is made available under the terms of the
* BSD 3-Clause license which is available at
* https://opensource.org/licenses/BSD-3-Clause
*
* SPDX-FileCopyrightText: 2022 Deutsche Telekom AG
* SPDX-FileContributor: Sartura Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SYSTEM_AUGEAS_PLUGIN_H
#define SYSTEM_AUGEAS_PLUGIN_H

#include <sysrepo_types.h>

int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_data);
void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *private_data);

#endif // SYSTEM_AUGEAS_PLUGIN_H
48 changes: 48 additions & 0 deletions src/plugins/ietf-system/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.0)

set(PLUGIN_LIBRARY_NAME "srplg-ietf-system")
set(PLUGIN_EXECUTABLE_NAME "ietf-system-plugin")

set(
PLUGIN_SOURCES

plugin.c
)

# check for systemd flag
if(DEFINED SYSTEMD_IFINDEX)
add_compile_definitions(SYSTEMD_IFINDEX=${SYSTEMD_IFINDEX})
else()
message(SEND_ERROR "No SYSTEMD_IFINDEX value set for default interface index to use with systemd... Unable to build without it")
endif()

# add plugin as a sysrepo-plugind library
add_library(
${PLUGIN_LIBRARY_NAME}
MODULE
${PLUGIN_SOURCES}
)

add_executable(
${PLUGIN_EXECUTABLE_NAME}

${PLUGIN_SOURCES}
${CMAKE_SOURCE_DIR}/src/main.c
)

target_link_libraries(
${PLUGIN_EXECUTABLE_NAME}

# link against the core plugin library
${PLUGIN_CORE_LIBRARY_NAME}

# link other external libraries
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${UMGMT_LIBRARIES}
${SYSTEMD_LIBRARIES}
)

install(TARGETS ${PLUGIN_LIBRARY_NAME} DESTINATION lib)
install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_executable(
target_link_libraries(
system_utest

${PLUGIN_LIRBARY_NAME}
${PLUGIN_CORE_LIBRARY_NAME}
${CMOCKA_LIBRARIES}
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
Expand Down

0 comments on commit 4660991

Please sign in to comment.