Skip to content

Commit

Permalink
interfaces-plugin: refactor plugin build as a module and as a standal…
Browse files Browse the repository at this point in the history
…one executable
  • Loading branch information
zinccyy committed Jan 14, 2023
1 parent b7d1172 commit 8055d75
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 59 deletions.
119 changes: 63 additions & 56 deletions src/interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,20 @@
cmake_minimum_required(VERSION 3.0)
project(sysrepo-plugin-interfaces C)

set(PLUGIN_LIBRARY_NAME srplg-interfaces)
set(PLUGIN_CORE_LIBRARY_NAME "srplg-ietf-interfaces-core")
set(PLUGIN_MODULE_NAME "srplg-ietf-interfaces")
set(PLUGIN_EXECUTABLE_NAME "ietf-interfaces-plugin")

include_directories(
${CMAKE_SOURCE_DIR}/src/interfaces/src
${CMAKE_SOURCE_DIR}/deps/uthash
)

set(PLUGIN 0 CACHE BOOL "Build a plugin")
# set(PLUGIN 0 CACHE BOOL "Build a plugin")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules")

set(
SOURCES

# startup
src/plugin/startup/load.c
src/plugin/startup/store.c

# running
src/plugin/running/load.c
src/plugin/running/store.c
CORE_SOURCES

# subscription
src/plugin/subscription/change.c
Expand Down Expand Up @@ -80,10 +74,23 @@ set(
src/plugin/data/interfaces/interface/ipv6/neighbor.c

# main files
src/plugin.c
${CMAKE_SOURCE_DIR}/src/utils/memory.c
)

set(
PLUGIN_SOURCES

src/plugin.c

# startup
src/plugin/startup/load.c
src/plugin/startup/store.c

# running
src/plugin/running/load.c
src/plugin/running/store.c
)

# packages
find_package(AUGYANG)
find_package(PTHREAD REQUIRED)
Expand All @@ -92,65 +99,65 @@ find_package(SYSREPO REQUIRED)
find_package(SRPC REQUIRED)
find_package(NL REQUIRED)

# plugin library
include_directories(
${SYSREPO_INCLUDE_DIRS}
${LIBYANG_INCLUDE_DIRS}
${SRPC_INCLUDE_DIRS}
${NL_INCLUDE_DIRS}
${PTHREAD_INCLUDE_DIRS}
)

# build core library
add_library(${PLUGIN_CORE_LIBRARY_NAME} SHARED ${CORE_SOURCES})
install(TARGETS ${PLUGIN_CORE_LIBRARY_NAME} DESTINATION lib)

# build plugin as a module
add_library(
${PLUGIN_LIBRARY_NAME}
STATIC
${SOURCES}
${PLUGIN_MODULE_NAME}
MODULE
${PLUGIN_SOURCES}
# ${CORE_SOURCES}
)

# link plugin library
target_link_libraries(
${PLUGIN_LIBRARY_NAME}
${PLUGIN_MODULE_NAME}

${PLUGIN_CORE_LIBRARY_NAME}

# link external dependencies
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${NL_LIBRARIES}
${PTHREAD_LIBRARIES}
)

if(PLUGIN)
# ignore plugin library and compile PROJECT_NAME as a module
add_library(
${PROJECT_NAME}
MODULE ${SOURCES}
)
target_link_libraries(
${PROJECT_NAME}
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${NL_LIBRARIES}
${PTHREAD_LIBRARIES}
)
else()
add_executable(
${PROJECT_NAME}
src/main.c
)
target_link_libraries(
${PROJECT_NAME}

# link plugin library with executable
${PLUGIN_LIBRARY_NAME}

${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${NL_LIBRARIES}
${PTHREAD_LIBRARIES}
)
endif()
# build plugin as a standalone executable
add_executable(
${PLUGIN_EXECUTABLE_NAME}
${PLUGIN_SOURCES}

include_directories(
${SYSREPO_INCLUDE_DIRS}
${LIBYANG_INCLUDE_DIRS}
${SRPC_INCLUDE_DIRS}
${NL_INCLUDE_DIRS}
${PTHREAD_INCLUDE_DIRS}
# add main
src/main.c
)
target_link_libraries(
${PLUGIN_EXECUTABLE_NAME}

# link core lib
${PLUGIN_CORE_LIBRARY_NAME}

# link external dependencies
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${NL_LIBRARIES}
${PTHREAD_LIBRARIES}
)

# install to appropriate directories
install(TARGETS ${PLUGIN_MODULE_NAME} DESTINATION lib)
install(TARGETS ${PLUGIN_EXECUTABLE_NAME} DESTINATION bin)

# augyang support
if(AUGYANG_FOUND)
add_compile_definitions(AUGYANG)
Expand Down
11 changes: 8 additions & 3 deletions src/interfaces/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ target_link_libraries(
${INTERFACES_UTEST_NAME}

${CMOCKA_LIBRARIES}
${PLUGIN_LIBRARY_NAME}
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}

${PLUGIN_CORE_LIBRARY_NAME}

${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SRPC_LIBRARIES}
${NL_LIBRARIES}
${PTHREAD_LIBRARIES}
)

add_test(
Expand Down

0 comments on commit 8055d75

Please sign in to comment.