Skip to content

Commit

Permalink
netopeer2 REFACTOR major repository reorganization
Browse files Browse the repository at this point in the history
Most importantly, there are no 2 separate projects
now but instead one main project netopeer2-server
with additional side tool netopeer2-cli.
Refs #608
  • Loading branch information
michalvasko committed May 5, 2020
1 parent 8301291 commit 53ecbbc
Show file tree
Hide file tree
Showing 48 changed files with 325 additions and 343 deletions.
70 changes: 37 additions & 33 deletions server/CMakeLists.txt → CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
cmake_minimum_required(VERSION 2.8.9)

project(netopeer2 C)
set(NETOPEER2_DESC "NETCONF tools suite including a server and command-line client")

# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../CMakeModules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

project(netopeer2-server C)
include(GNUInstallDirs)
include(CheckFunctionExists)
include(CheckIncludeFile)
Expand Down Expand Up @@ -31,12 +33,13 @@ set(NP2SRV_VERSION 1.1.26)

# build options
if(CMAKE_BUILD_TYPE STREQUAL debug)
option(ENABLE_BUILD_TESTS "Build tests" ON)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
option(BUILD_TESTS "Build tests" ON)
option(VALGRIND_TESTS "Build tests with valgrind" ON)
else()
option(ENABLE_BUILD_TESTS "Build tests" OFF)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(VALGRIND_TESTS "Build tests with valgrind" OFF)
endif()
option(BUILD_CLI "Build and install neotpeer2-cli" ON)
option(ENABLE_URL "Enable URL capability" ON)
set(THREAD_COUNT 5 CACHE STRING "Number of threads accepting new sessions and handling requests")
set(NACM_RECOVERY_UID 0 CACHE STRING "NACM recovery session UID that has unrestricted access")
Expand Down Expand Up @@ -75,7 +78,7 @@ if(NOT MODULES_GROUP)
endif()
endif()
set(MODULES_GROUP "${MODULES_GROUP}" CACHE STRING "System group that the server modules will belong to")
set(MODULES_DIR "${PROJECT_SOURCE_DIR}/../modules" CACHE STRING "Directory with the YANG modules to install")
set(MODULES_DIR "${PROJECT_SOURCE_DIR}/modules" CACHE STRING "Directory with the YANG modules to install")

# set prefix for the PID file
if(NOT PIDFILE_PREFIX)
Expand All @@ -101,25 +104,23 @@ else()
endif()

# source files
set(srcs
common.c
netconf.c
netconf_monitoring.c
netconf_server.c
netconf_server_ssh.c
netconf_server_tls.c
netconf_acm.c
netconf_nmda.c
log.c)

# object library to build source codes only once for the main binary
add_library(serverobj OBJECT ${srcs})
set(SERVER_SRC
src/common.c
src/netconf.c
src/netconf_monitoring.c
src/netconf_server.c
src/netconf_server_ssh.c
src/netconf_server_tls.c
src/netconf_acm.c
src/netconf_nmda.c
src/log.c)

# link compat
use_compat()

# netopeer2-server target
add_executable(netopeer2-server $<TARGET_OBJECTS:serverobj> main.c $<TARGET_OBJECTS:compat>)
# netopeer2-server
add_library(serverobj OBJECT ${SERVER_SRC})
add_executable(netopeer2-server $<TARGET_OBJECTS:serverobj> src/main.c $<TARGET_OBJECTS:compat>)

# dependencies - libcurl
if(ENABLE_URL)
Expand Down Expand Up @@ -158,19 +159,13 @@ list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBSSH_INCLUDE_DIRS})

# dependencies - libyang
find_package(LibYANG REQUIRED)
if(NOT LIBYANG_FOUND)
message(FATAL_ERROR "libyang library not found!")
endif()
target_link_libraries(netopeer2-server ${LIBYANG_LIBRARIES})
include_directories(${LIBYANG_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBYANG_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBYANG_LIBRARIES})

# dependencies - libnetconf2
find_package(LibNETCONF2 REQUIRED)
if(NOT LIBNETCONF2_FOUND)
message(FATAL_ERROR "libnetconf2 library not found!")
endif()
if(NOT LIBNETCONF2_ENABLED_SSH)
message(FATAL_ERROR "Missing SSH support in libnetconf2, server requires SSH to be supported.")
endif()
Expand All @@ -180,9 +175,13 @@ list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBNETCONF2_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBNETCONF2_LIBRARIES})

# dependencies - sysrepo
find_package(SYSREPO REQUIRED)
find_package(Sysrepo REQUIRED)
target_link_libraries(netopeer2-server ${SYSREPO_LIBRARIES})
include_directories(${SYSREPO_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_INCLUDES ${SYSREPO_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${SYSREPO_LIBRARIES})

# sysrepo tools
find_program(SYSREPOCTL "sysrepoctl")
if(SYSREPOCTL-NOTFOUND)
message(FATAL_ERROR "sysrepoctl utility not found.")
Expand All @@ -201,12 +200,12 @@ if(GENERATE_HOSTKEY)
endif()

# generate files
configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/src/config.h.in" "${PROJECT_BINARY_DIR}/config.h" ESCAPE_QUOTES @ONLY)
include_directories(${PROJECT_BINARY_DIR})

configure_file("${PROJECT_SOURCE_DIR}/setup.sh.in" "${PROJECT_BINARY_DIR}/setup.sh" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/merge_hostkey.sh.in" "${PROJECT_BINARY_DIR}/merge_hostkey.sh" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/merge_config.sh.in" "${PROJECT_BINARY_DIR}/merge_config.sh" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/scripts/setup.sh.in" "${PROJECT_BINARY_DIR}/setup.sh" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/scripts/merge_hostkey.sh.in" "${PROJECT_BINARY_DIR}/merge_hostkey.sh" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/scripts/merge_config.sh.in" "${PROJECT_BINARY_DIR}/merge_config.sh" ESCAPE_QUOTES @ONLY)

# install the binary, required modules, and default configuration
install(TARGETS netopeer2-server DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -238,6 +237,11 @@ if(MERGE_LISTEN_CONFIG)
")
endif()

# cli
if(BUILD_CLI)
add_subdirectory(cli)
endif()

# clean cmake cache
add_custom_target(cleancache
COMMAND make clean
Expand Down
85 changes: 40 additions & 45 deletions CMakeModules/FindLibNETCONF2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# LIBNETCONF2_ENABLED_TLS - LibNETCONF2 was compiled with TLS support
#
# Author Michal Vasko <mvasko@cesnet.cz>
# Copyright (c) 2015 CESNET, z.s.p.o.
# Copyright (c) 2020 CESNET, z.s.p.o.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand All @@ -33,58 +33,53 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
include(FindPackageHandleStandardArgs)
include(CheckSymbolExists)

INCLUDE(CheckSymbolExists)
if(LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS)
# in cache already
set(LIBNETCONF2_FOUND TRUE)
else()
find_path(LIBNETCONF2_INCLUDE_DIR
NAMES
nc_client.h
nc_server.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)

if (LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS)
# in cache already
set(LIBNETCONF2_FOUND TRUE)
else (LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS)
find_library(LIBNETCONF2_LIBRARY
NAMES
netconf2
libnetconf2
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)

find_path(LIBNETCONF2_INCLUDE_DIR
NAMES
nc_client.h
nc_server.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)
set(LIBNETCONF2_INCLUDE_DIRS ${LIBNETCONF2_INCLUDE_DIR})
set(LIBNETCONF2_LIBRARIES ${LIBNETCONF2_LIBRARY})
mark_as_advanced(LIBNETCONF2_INCLUDE_DIRS LIBNETCONF2_LIBRARIES)

find_library(LIBNETCONF2_LIBRARY
NAMES
netconf2
libnetconf2
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)
# handle the QUIETLY and REQUIRED arguments and set SYSREPO_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(LibNETCONF2 DEFAULT_MSG LIBNETCONF2_LIBRARY LIBNETCONF2_INCLUDE_DIR)

if (LIBNETCONF2_INCLUDE_DIR AND LIBNETCONF2_LIBRARY)
set(LIBNETCONF2_FOUND TRUE)
# check the configured options and make them available through cmake
list(INSERT CMAKE_REQUIRED_INCLUDES 0 "${LIBNETCONF2_INCLUDE_DIR}")
check_symbol_exists("NC_ENABLED_SSH" "nc_client.h" LIBNETCONF2_ENABLED_SSH)
check_symbol_exists("NC_ENABLED_TLS" "nc_client.h" LIBNETCONF2_ENABLED_TLS)
list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0)
else (LIBNETCONF2_INCLUDE_DIR AND LIBNETCONF2_LIBRARY)
set(LIBNETCONF2_FOUND FALSE)
endif (LIBNETCONF2_INCLUDE_DIR AND LIBNETCONF2_LIBRARY)

set(LIBNETCONF2_INCLUDE_DIRS ${LIBNETCONF2_INCLUDE_DIR})
set(LIBNETCONF2_LIBRARIES ${LIBNETCONF2_LIBRARY})

# show the LIBNETCONF2_INCLUDE_DIRS and LIBNETCONF2_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBNETCONF2_INCLUDE_DIRS LIBNETCONF2_LIBRARIES)

endif (LIBNETCONF2_LIBRARIES AND LIBNETCONF2_INCLUDE_DIRS)
endif()

86 changes: 45 additions & 41 deletions CMakeModules/FindLibYANG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# LIBYANG_FOUND - system has LibYANG
# LIBYANG_INCLUDE_DIRS - the LibYANG include directory
# LIBYANG_LIBRARIES - Link these to use LibYANG
# LIBYANG_VERSION - SO version of the found libyang library
#
# Author Radek Krejci <rkrejci@cesnet.cz>
# Copyright (c) 2015 CESNET, z.s.p.o.
Expand Down Expand Up @@ -31,50 +32,53 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
include(FindPackageHandleStandardArgs)

if (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
# in cache already
set(LIBYANG_FOUND TRUE)
else (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)

find_path(LIBYANG_INCLUDE_DIR
NAMES
libyang/libyang.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)

find_library(LIBYANG_LIBRARY
NAMES
yang
libyang
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)

if (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
# in cache already
set(LIBYANG_FOUND TRUE)
else (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
set(LIBYANG_FOUND FALSE)
endif (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
else()
find_path(LIBYANG_INCLUDE_DIR
NAMES
libyang/libyang.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
${CMAKE_INCLUDE_PATH}
${CMAKE_INSTALL_PREFIX}/include
)

set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
find_library(LIBYANG_LIBRARY
NAMES
yang
libyang
PATHS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/local/lib
/sw/lib
${CMAKE_LIBRARY_PATH}
${CMAKE_INSTALL_PREFIX}/lib
)

# show the LIBYANG_INCLUDE_DIRS and LIBYANG_LIBRARIES variables only in the advanced view
mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
if(LIBYANG_INCLUDE_DIR)
find_path(LY_HEADER_PATH "libyang/libyang.h" HINTS ${LIBYANG_INCLUDE_DIR})
file(READ "${LY_HEADER_PATH}/libyang/libyang.h" LY_HEADER)
string(REGEX MATCH "#define LY_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\"" LY_VERSION_MACRO "${LY_HEADER}")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LIBYANG_VERSION "${LY_VERSION_MACRO}")
endif()

endif (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)

# handle the QUIETLY, REQUIRED and VERSION arguments and set LIBYANG_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(LibYANG FOUND_VAR LIBYANG_FOUND
REQUIRED_VARS LIBYANG_LIBRARY LIBYANG_INCLUDE_DIR
VERSION_VAR LIBYANG_VERSION)
endif()
26 changes: 0 additions & 26 deletions CMakeModules/FindSYSREPO.cmake

This file was deleted.

Loading

0 comments on commit 53ecbbc

Please sign in to comment.