diff --git a/src/interfaces/CMakeLists.txt b/src/interfaces/CMakeLists.txt index dbd8d1b4..6bf46b7e 100644 --- a/src/interfaces/CMakeLists.txt +++ b/src/interfaces/CMakeLists.txt @@ -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 @@ -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) @@ -92,17 +99,32 @@ 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} @@ -110,47 +132,32 @@ target_link_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) diff --git a/src/interfaces/tests/CMakeLists.txt b/src/interfaces/tests/CMakeLists.txt index 8029f3d6..a7bf65cb 100644 --- a/src/interfaces/tests/CMakeLists.txt +++ b/src/interfaces/tests/CMakeLists.txt @@ -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(