Skip to content

Commit

Permalink
unit-testing: modify CMake to compile plugin code as a library first
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateo Cindrić committed Jul 25, 2022
1 parent 29b2cc3 commit e96610e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
21 changes: 12 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(sysrepo-plugin-system C)

include(CompileOptions.cmake)

set(PLUGIN_LIRBARY_NAME srplg-ietf-system)

set(PLUGIN 0 CACHE BOOL "Build a plugin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
option(ENABLE_BUILD_TESTS, "Build tests" OFF)
Expand Down Expand Up @@ -60,10 +62,6 @@ set(
src/system/api/authentication/change.c
)

if(NOT PLUGIN)
set(SOURCES ${SOURCES} src/main.c)
endif()

# get sysrepo version
find_package(PkgConfig)

Expand All @@ -80,11 +78,16 @@ if(PKG_CONFIG_FOUND)
endif()
endif()

if(PLUGIN)
add_library(${CMAKE_PROJECT_NAME} MODULE ${SOURCES})
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION lib)
else()
add_executable(${CMAKE_PROJECT_NAME} ${SOURCES})
add_library(${PLUGIN_LIRBARY_NAME} STATIC ${SOURCES})
install(TARGETS ${PLUGIN_LIRBARY_NAME} DESTINATION lib)

if(NOT PLUGIN)
add_executable(
${CMAKE_PROJECT_NAME}
${SOURCES}
src/main.c
)
target_link_libraries(${CMAKE_PROJECT_NAME} ${PLUGIN_LIRBARY_NAME})
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION bin)
endif()

Expand Down
1 change: 1 addition & 0 deletions tests/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_link_libraries(
${SYSREPO_LIBRARIES}
${LIBYANG_LIBRARIES}
${SYSTEMD_LIBRARIES}
${PLUGIN_LIRBARY_NAME}

"-Wl,--wrap=gethostname"
)
Expand Down

0 comments on commit e96610e

Please sign in to comment.