a small C library to connect to the moolticuted daemon

moolticute library


CMakeLists.txt/
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project (libmoolticute-c VERSION 0.1.0 LANGUAGES  C)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
include(GNUInstallDirs)
include(CTest)
enable_testing()
include(add_my_test)

option(DOXYGEN "Also build the doxygen documentation" OFF)

find_package(Git)
find_package(Threads)
find_package(JSON-C REQUIRED)
find_package(websockets REQUIRED)

SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Dominik Meyer <dmeyer@federationhq.de>") #required
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Library for communicating with the moolticute daemon for accessing mooltipass hardware password vaults")
SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE https://gitcloud.federationhq.de/repositories/libmoolticute-c.git/heads/master/)
INCLUDE(CPack)

set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

set(moolticute_sources
              include/moolticute.h
              src/mooltipass_memory.c
              src/moolticute_register_cb.c
              src/moolticute_init.c
              src/moolticute_connect.c
              src/moolticute_callback.c
              src/moolticute_array.h
              src/moolticute_array.c
              src/callbacks/moolticute_cb_application_id.c
              src/callbacks/moolticute_cb_application_id.h
              src/callbacks/moolticute_cb_card_db_metadata.c
              src/callbacks/moolticute_cb_card_db_metadata.h
              src/callbacks/moolticute_cb_connected.c
              src/callbacks/moolticute_cb_connected.h
              src/callbacks/moolticute_cb_failed_memorymgmt.h
              src/callbacks/moolticute_cb_failed_memorymgmt.c
              src/callbacks/moolticute_cb_memorymgmt_changed.c
              src/callbacks/moolticute_cb_memorymgmt_changed.h
              src/callbacks/moolticute_cb_memorymgmt_data.h
              src/callbacks/moolticute_cb_memorymgmt_data.c
              src/callbacks/moolticute_cb_not_found.h
              src/callbacks/moolticute_cb_not_found.c
              src/callbacks/moolticute_cb_param_changed.c
              src/callbacks/moolticute_cb_param_changed.h
              src/callbacks/moolticute_cb_progress.h
              src/callbacks/moolticute_cb_progress.c
              src/callbacks/moolticute_cb_status_changed.h
              src/callbacks/moolticute_cb_status_changed.c
              src/callbacks/moolticute_cb_version_changed.h
              src/callbacks/moolticute_cb_version_changed.c
              src/cmds/moolticute_cmd_get_application_id.c
              src/cmds/moolticute_cmd_query_random_number.c
              src/cmds/moolticute_cmd_request_device_uid.c
              src/cmds/moolticute_cmd_request_password.c
              src/cmds/moolticute_cmd_service_exist.c
              src/cmds/moolticute_cmd_start_memory_management.c
              src/cmds/moolticute_cmd_stop_memory_management.c
              src/cmds/moolticute_cmd_add_update_credential.c
          )

add_library(objlib OBJECT ${moolticute_sources})
set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1)
target_include_directories(objlib
  PUBLIC
          include
  PRIVATE
          src
)


add_library(moolticute SHARED $<TARGET_OBJECTS:objlib>)
add_library(moolticute-static STATIC $<TARGET_OBJECTS:objlib>)

target_link_libraries(moolticute ${CMAKE_THREAD_LIBS_INIT} ${WEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES})
target_link_libraries(moolticute-static ${CMAKE_THREAD_LIBS_INIT} ${WEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES})


target_include_directories(moolticute
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  PRIVATE src
)

target_include_directories(moolticute-static
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  PRIVATE src
)
set_target_properties(moolticute-static PROPERTIES OUTPUT_NAME moolticute)

if (${CMAKE_BUILD_TYPE} MATCHES DEBUG)
  target_compile_options(objlib PUBLIC -Wall -g -O0)
  target_compile_options(moolticute PUBLIC -Wall -g -O0)
endif()



install(TARGETS moolticute EXPORT MoolticuteConfig
    ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})  # This is for Windows
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS moolticute-static EXPORT MoolticuteStaticConfig
    ARCHIVE  DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY  DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})  # This is for Windows

# This makes the project importable from the install directory
# Put config file in per-project dir (name MUST match), can also
# just go into 'cmake'.
install(EXPORT MoolticuteConfig DESTINATION share/libmoolticute/cmake)

# This makes the project importable from the build directory
export(TARGETS moolticute-static FILE MoolticuteConfig.cmake)


#
# Everything TEST related
#
add_my_test(TEST test_simple_connect
            SOURCES tests/test_simple_connect.c
            LIBS moolticute
          )

get_property(_mytests GLOBAL PROPERTY _mytests)
FOREACH( _test ${_mytests})
  target_include_directories(${_test} PRIVATE src )

IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
  target_compile_options(${_test} PUBLIC -Wall -g -O0)
ELSE()
  IF(CMAKE_BUILD_TYPE MATCHES COVERAGE)
    target_compile_options(${_test} PUBLIC -g -O0 --coverage -fprofile-arcs -ftest-coverage)
    set_target_properties(${_test} PROPERTIES LINK_FLAGS "-fprofile-arcs")
  ELSE()
    target_compile_options(${_test} PUBLIC -O4)
  ENDIF()
ENDIF()
ENDFOREACH()