From dabdcaefbe7f3d268258fe25869fe1f3f54e3d83 Mon Sep 17 00:00:00 2001 From: Florian Uekermann Date: Wed, 5 Apr 2017 16:09:29 +0200 Subject: [PATCH 1/2] Simplify and clean up build. Stop using cmake Remove unnecessary hidapi submodule and header Build shared and static library by default Use consistent file extensions --- .gitmodules | 3 - .travis.yml | 39 +- CMakeLists.txt | 149 ------- CMakeSettings.json | 37 -- ...ns.cpp => DeviceCommunicationExceptions.cc | 0 hidapi | 1 - include/hidapi/hidapi.h | 391 ------------------ makefile | 24 ++ 8 files changed, 39 insertions(+), 605 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 CMakeSettings.json rename DeviceCommunicationExceptions.cpp => DeviceCommunicationExceptions.cc (100%) delete mode 160000 hidapi delete mode 100644 include/hidapi/hidapi.h create mode 100644 makefile diff --git a/.gitmodules b/.gitmodules index 46084960..acf652a7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "unittest/Catch"] path = unittest/Catch url = https://github.com/philsquared/Catch.git -[submodule "hidapi"] - path = hidapi - url = https://github.com/Nitrokey/hidapi.git diff --git a/.travis.yml b/.travis.yml index ba4465b1..f5c57f61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,58 +1,49 @@ language: generic sudo: false -os: osx -env: CF= matrix: include: -# - osx_image: xcode7.3 #default -# before_install: &brew -# - brew update -# - brew install hidapi - - osx_image: xcode6.4 - - osx_image: xcode8.2 + - os: osx + osx_image: xcode7.3 + before_install: &brew + - brew update + - brew install hidapi + - os: osx + osx_image: xcode6.4 + before_install: *brew + - os: osx + osx_image: xcode8.2 + before_install: *brew - os: linux dist: trusty - env: COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CF=-DCOMPILE_TESTS=ON + env: CXX=g++-5 addons: apt: packages: - - cmake - libhidapi-dev - g++-5 sources: &sources - ubuntu-toolchain-r-test - os: linux dist: trusty - env: COMPILER_NAME=gcc CXX=g++-6 CC=gcc-6 CF=-DCOMPILE_TESTS=ON + env: CXX=g++-6 addons: apt: packages: - - cmake - libhidapi-dev - g++-6 sources: *sources - os: linux dist: trusty - env: COMPILER_NAME=clang CXX=clang++-3.8 CC=clang-3.8 CF=-DCOMPILE_TESTS=ON + env: CXX=clang++-3.8 addons: apt: packages: - - cmake - libhidapi-dev - g++-5 - clang-3.8 sources: *sources - -install: - - mkdir -p build - - cd build -# - export CXXFLAGS="${CXX_FLAGS} -Wall -Wextra -Werror" # TODO enable when fixed - - ${CXX} --version || true - - cmake --version - - cmake .. ${CF} - script: - - make -j2 + - make -j # - make test # TODO add library device-less tests \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 5fea2f61..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,149 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -IF (UNIX) - OPTION(USE_CLANG "Use CLang" FALSE) - IF(USE_CLANG) - set(CMAKE_CXX_COMPILER "/usr/bin/clang++" CACHE string "clang++ compiler" FORCE) - ELSE() - set(CMAKE_CXX_COMPILER) - ENDIF() - OPTION(ADD_ASAN "Use ASAN to show memory issues" FALSE) - OPTION(ADD_TSAN "Use TSAN to show thread issues" FALSE) - IF(ADD_ASAN) - SET(EXTRA_LIBS ${EXTRA_LIBS} asan ) - ADD_DEFINITIONS(-fsanitize=address -fno-omit-frame-pointer) - ENDIF() - IF(ADD_TSAN) - SET(EXTRA_LIBS ${EXTRA_LIBS} tsan ) - SET(USE_CLANG TRUE) - ADD_DEFINITIONS(-fsanitize=thread -fno-omit-frame-pointer -fPIC -g) #use with clang - ENDIF() - IF(ADD_TSAN AND ADD_ASAN) - message(FATAL_ERROR "TSAN and ASAN cannot be used at the same time") - ENDIF() -ENDIF() - -project(libnitrokey) -SET(PROJECT_VERSION "3.0-alpha") -set(CMAKE_CXX_STANDARD 14) - -OPTION(LIBNITROKEY_STATIC "Build libnitrokey statically" TRUE) - - -OPTION(COMPILE_TESTS "Compile tests" FALSE) -IF (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo) -ENDIF() -MESSAGE("${PROJECT_NAME}: Build type: ${CMAKE_BUILD_TYPE}") - -include_directories(hidapi) -include_directories(include) -set(SOURCE_FILES - include/command.h - include/command_id.h - include/cxx_semantics.h - include/device.h - include/device_proto.h - include/dissect.h - include/inttypes.h - include/log.h - include/misc.h - include/NitrokeyManager.h - include/stick10_commands.h - include/stick20_commands.h - include/CommandFailedException.h - include/LibraryException.h - include/LongOperationInProgressException.h - include/stick10_commands_0.8.h - command_id.cc - device.cc - log.cc - misc.cc - NitrokeyManager.cc - NK_C_API.h - NK_C_API.cc - DeviceCommunicationExceptions.cpp) - -IF(APPLE) - include_directories(hidapi/hidapi) - add_library(hidapi-libusb STATIC hidapi/mac/hid.c ) - target_link_libraries(hidapi-libusb "-framework CoreFoundation" "-framework IOKit") -ELSEIF(UNIX) -# add_library(hidapi-libusb STATIC hidapi/libusb/hid.c ) -ELSEIF(WIN32) - include_directories(hidapi/hidapi) - add_library(hidapi-libusb STATIC hidapi/windows/hid.c ) - target_link_libraries(hidapi-libusb setupapi) -ENDIF() - - -IF (NOT LIBNITROKEY_STATIC) - add_library(nitrokey SHARED ${SOURCE_FILES}) - add_library(nitrokey-log SHARED ${SOURCE_FILES}) - install (TARGETS nitrokey DESTINATION "lib") - SET(LIBNAME nitrokey) -ELSE() - add_library(nitrokey-static STATIC ${SOURCE_FILES}) - add_library(nitrokey-static-log STATIC ${SOURCE_FILES}) - SET(LIBNAME nitrokey-static) -ENDIF() - - -target_link_libraries(${LIBNAME} hidapi-libusb) -target_link_libraries(${LIBNAME}-log hidapi-libusb) - -OPTION(ERROR_ON_WARNING "Stop compilation on warning found (not supported for MSVC)" ON) -if (NOT MSVC) - set(COMPILE_FLAGS "-Wall -Wno-unused-function -Wcast-qual -Woverloaded-virtual") - if (ERROR_ON_WARNING) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -Werror") - endif() - SET_TARGET_PROPERTIES(${LIBNAME} ${LIBNAME}-log PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} ) - IF(APPLE) - SET_TARGET_PROPERTIES(hidapi-libusb PROPERTIES COMPILE_FLAGS "" ) - ENDIF() -endif() - -SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES COMPILE_DEFINITIONS "NO_LOG") - - -file(GLOB LIB_INCLUDES "include/libnitrokey/*.h") -install (FILES ${LIB_INCLUDES} DESTINATION "include") - -IF (COMPILE_TESTS) - include_directories(unittest/Catch/include) - - add_library(catch SHARED unittest/catch_main.cpp ) - - add_executable (test_C_API unittest/test_C_API.cpp) - target_link_libraries (test_C_API ${EXTRA_LIBS} ${LIBNAME} catch) - - add_executable (test2 unittest/test2.cc) - target_link_libraries (test2 ${EXTRA_LIBS} ${LIBNAME} catch) - - add_executable (test3 unittest/test3.cc) - target_link_libraries (test3 ${EXTRA_LIBS} ${LIBNAME} catch) - - add_executable (test_HOTP unittest/test_HOTP.cc) - target_link_libraries (test_HOTP ${EXTRA_LIBS} ${LIBNAME} catch) - - add_executable (test1 unittest/test.cc) - target_link_libraries (test1 ${EXTRA_LIBS} ${LIBNAME} catch) - - #run with 'make test' or 'ctest' - #needs connected PRO device for success - #warning: it may delete data on the device - include (CTest) - add_test (runs test_C_API) -ENDIF() - - - - -#SET(CPACK_GENERATOR -# "DEB;RPM") -# build a CPack driven installer package -include (InstallRequiredSystemLibraries) -set (CPACK_RESOURCE_FILE_LICENSE - "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") -set (CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") -include (CPack) diff --git a/CMakeSettings.json b/CMakeSettings.json deleted file mode 100644 index e8c1f1df..00000000 --- a/CMakeSettings.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file. - "configurations": [ - { - "name": "x86-Debug", - "generator": "Visual Studio 15 2017", - "configurationType" : "Debug", - "buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-m -v:minimal" - }, - { - "name": "x86-Release", - "generator": "Visual Studio 15 2017", - "configurationType" : "Release", - "buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-m -v:minimal" - }, - { - "name": "x64-Debug", - "generator": "Visual Studio 15 2017 Win64", - "configurationType" : "Debug", - "buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-m -v:minimal" - }, - { - "name": "x64-Release", - "generator": "Visual Studio 15 2017 Win64", - "configurationType" : "Release", - "buildRoot": "${env.LOCALAPPDATA}\\CMakeBuild\\${workspaceHash}\\build\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-m -v:minimal" - } - ] -} \ No newline at end of file diff --git a/DeviceCommunicationExceptions.cpp b/DeviceCommunicationExceptions.cc similarity index 100% rename from DeviceCommunicationExceptions.cpp rename to DeviceCommunicationExceptions.cc diff --git a/hidapi b/hidapi deleted file mode 160000 index b24dd9c3..00000000 --- a/hidapi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b24dd9c36c4aacfd5ba7b1f0277d98bbbee43f1b diff --git a/include/hidapi/hidapi.h b/include/hidapi/hidapi.h deleted file mode 100644 index e5bc2dc4..00000000 --- a/include/hidapi/hidapi.h +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************* - HIDAPI - Multi-Platform library for - communication with HID devices. - - Alan Ott - Signal 11 Software - - 8/22/2009 - - Copyright 2009, All Rights Reserved. - - At the discretion of the user of this library, - this software may be licensed under the terms of the - GNU General Public License v3, a BSD-Style license, or the - original HIDAPI license as outlined in the LICENSE.txt, - LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt - files located at the root of the source distribution. - These files may also be found in the public source - code repository located at: - http://github.com/signal11/hidapi . -********************************************************/ - -/** @file - * @defgroup API hidapi API - */ - -#ifndef HIDAPI_H__ -#define HIDAPI_H__ - -#include - -#ifdef _WIN32 - #define HID_API_EXPORT __declspec(dllexport) - #define HID_API_CALL -#else - #define HID_API_EXPORT /**< API export macro */ - #define HID_API_CALL /**< API call macro */ -#endif - -#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/ - -#ifdef __cplusplus -extern "C" { -#endif - struct hid_device_; - typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ - - /** hidapi info structure */ - struct hid_device_info { - /** Platform-specific device path */ - char *path; - /** Device Vendor ID */ - unsigned short vendor_id; - /** Device Product ID */ - unsigned short product_id; - /** Serial Number */ - wchar_t *serial_number; - /** Device Release Number in binary-coded decimal, - also known as Device Version Number */ - unsigned short release_number; - /** Manufacturer String */ - wchar_t *manufacturer_string; - /** Product string */ - wchar_t *product_string; - /** Usage Page for this Device/Interface - (Windows/Mac only). */ - unsigned short usage_page; - /** Usage for this Device/Interface - (Windows/Mac only).*/ - unsigned short usage; - /** The USB interface which this logical device - represents. Valid on both Linux implementations - in all cases, and valid on the Windows implementation - only if the device contains more than one interface. */ - int interface_number; - - /** Pointer to the next device */ - struct hid_device_info *next; - }; - - - /** @brief Initialize the HIDAPI library. - - This function initializes the HIDAPI library. Calling it is not - strictly necessary, as it will be called automatically by - hid_enumerate() and any of the hid_open_*() functions if it is - needed. This function should be called at the beginning of - execution however, if there is a chance of HIDAPI handles - being opened by different threads simultaneously. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_init(void); - - /** @brief Finalize the HIDAPI library. - - This function frees all of the static data associated with - HIDAPI. It should be called at the end of execution to avoid - memory leaks. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_exit(void); - - /** @brief Enumerate the HID Devices. - - This function returns a linked list of all the HID devices - attached to the system which match vendor_id and product_id. - If @p vendor_id is set to 0 then any vendor matches. - If @p product_id is set to 0 then any product matches. - If @p vendor_id and @p product_id are both set to 0, then - all HID devices will be returned. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the types of device - to open. - @param product_id The Product ID (PID) of the types of - device to open. - - @returns - This function returns a pointer to a linked list of type - struct #hid_device, containing information about the HID devices - attached to the system, or NULL in the case of failure. Free - this linked list by calling hid_free_enumeration(). - */ - struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id); - - /** @brief Free an enumeration Linked List - - This function frees a linked list created by hid_enumerate(). - - @ingroup API - @param devs Pointer to a list of struct_device returned from - hid_enumerate(). - */ - void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs); - - /** @brief Open a HID device using a Vendor ID (VID), Product ID - (PID) and optionally a serial number. - - If @p serial_number is NULL, the first device with the - specified VID and PID is opened. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the device to open. - @param product_id The Product ID (PID) of the device to open. - @param serial_number The Serial Number of the device to open - (Optionally NULL). - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number); - - /** @brief Open a HID device by its path name. - - The path name be determined by calling hid_enumerate(), or a - platform-specific path name can be used (eg: /dev/hidraw0 on - Linux). - - @ingroup API - @param path The path name of the device to open - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path); - - /** @brief Write an Output report to a HID device. - - The first byte of @p data[] must contain the Report ID. For - devices which only support a single report, this must be set - to 0x0. The remaining bytes contain the report data. Since - the Report ID is mandatory, calls to hid_write() will always - contain one more byte than the report contains. For example, - if a hid report is 16 bytes long, 17 bytes must be passed to - hid_write(), the Report ID (or 0x0, for devices with a - single report), followed by the report data (16 bytes). In - this example, the length passed in would be 17. - - hid_write() will send the data on the first OUT endpoint, if - one exists. If it does not, it will send the data through - the Control Endpoint (Endpoint 0). - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Read an Input report from a HID device with timeout. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - @param milliseconds timeout in milliseconds or -1 for blocking wait. - - @returns - This function returns the actual number of bytes read and - -1 on error. If no packet was available to be read within - the timeout period, this function returns 0. - */ - int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds); - - /** @brief Read an Input report from a HID device. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - - @returns - This function returns the actual number of bytes read and - -1 on error. If no packet was available to be read and - the handle is in non-blocking mode, this function returns 0. - */ - int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length); - - /** @brief Set the device handle to be non-blocking. - - In non-blocking mode calls to hid_read() will return - immediately with a value of 0 if there is no data to be - read. In blocking mode, hid_read() will wait (block) until - there is data to read before returning. - - Nonblocking can be turned on and off at any time. - - @ingroup API - @param device A device handle returned from hid_open(). - @param nonblock enable or not the nonblocking reads - - 1 to enable nonblocking - - 0 to disable nonblocking. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock); - - /** @brief Send a Feature report to the device. - - Feature reports are sent over the Control endpoint as a - Set_Report transfer. The first byte of @p data[] must - contain the Report ID. For devices which only support a - single report, this must be set to 0x0. The remaining bytes - contain the report data. Since the Report ID is mandatory, - calls to hid_send_feature_report() will always contain one - more byte than the report contains. For example, if a hid - report is 16 bytes long, 17 bytes must be passed to - hid_send_feature_report(): the Report ID (or 0x0, for - devices which do not use numbered reports), followed by the - report data (16 bytes). In this example, the length passed - in would be 17. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send, including - the report number. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Get a feature report from a HID device. - - Set the first byte of @p data[] to the Report ID of the - report to be read. Make sure to allow space for this - extra byte in @p data[]. Upon return, the first byte will - still contain the Report ID, and the report data will - start in data[1]. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into, including - the Report ID. Set the first byte of @p data[] to the - Report ID of the report to be read, or set it to zero - if your device does not use numbered reports. - @param length The number of bytes to read, including an - extra byte for the report ID. The buffer can be longer - than the actual report. - - @returns - This function returns the number of bytes read plus - one for the report ID (which is still in the first - byte), or -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length); - - /** @brief Close a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - */ - void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device); - - /** @brief Get The Manufacturer String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Product String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Serial Number String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get a string from a HID device, based on its string index. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string_index The index of the string to get. - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen); - - /** @brief Get a string describing the last error which occurred. - - @ingroup API - @param device A device handle returned from hid_open(). - - @returns - This function returns a string containing the last error - which occurred or NULL if none has occurred. - */ - HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/makefile b/makefile new file mode 100644 index 00000000..f318bcac --- /dev/null +++ b/makefile @@ -0,0 +1,24 @@ +OBJECTS = $(patsubst %.cc,build/%.o,$(wildcard *.cc)) +HEADERS = $(wildcard include/*.h) +OPTS = -g -Wall -Wextra -O3 -fPIC + +ifeq ($(shell uname), Linux) +LIBS = -lhidapi-hidraw +else +LIBS = -lhidapi +endif + +all: build/libnitrokey.so build/libnitrokey.a +.PHONY: all + +build/libnitrokey.so: $(OBJECTS) + $(CXX) -shared $(LIBS) $(OPTS) -o $@ $(OBJECTS) + +build/libnitrokey.a: $(OBJECTS) + ar rcs $@ $(OBJECTS) + +build/%.o: %.cc $(HEADERS) + $(CXX) -std=c++14 -I include $(OPTS) -c $< -o $@ + +clean: + rm -f build/*.o build/*.a build/*.so From 8dfe33583fb745e5f4b5abb8d5347ad99dbb89da Mon Sep 17 00:00:00 2001 From: Florian Uekermann Date: Wed, 5 Apr 2017 16:47:56 +0200 Subject: [PATCH 2/2] Make C API header compatible with C --- NK_C_API.cc | 2 ++ NK_C_API.h | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NK_C_API.cc b/NK_C_API.cc index 16099db0..432810e1 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -1,6 +1,8 @@ #include +#include #include "NK_C_API.h" #include "include/LibraryException.h" +#include "include/NitrokeyManager.h" #include "include/cxx_semantics.h" using namespace nitrokey; diff --git a/NK_C_API.h b/NK_C_API.h index 97e9ea51..57c4fb4a 100644 --- a/NK_C_API.h +++ b/NK_C_API.h @@ -1,15 +1,16 @@ #ifndef LIBNITROKEY_NK_C_API_H #define LIBNITROKEY_NK_C_API_H -#include -#include -#include "include/NitrokeyManager.h" -#include "include/inttypes.h" +#include +#include #define NK_C_API +#ifdef __cplusplus extern "C" { +#endif + /** * Set debug level of messages written on stderr * @param state state=True - all messages, state=False - only errors level @@ -467,7 +468,9 @@ NK_C_API const char* NK_get_SD_usage_data_as_string(); */ NK_C_API int NK_get_progress_bar_value(); +#ifdef __cplusplus } +#endif #endif //LIBNITROKEY_NK_C_API_H