aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 17:18:59 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 17:18:59 +0100
commit22d05ce647281056d71fbd3c31df3bcd6396188d (patch)
tree90208930f54c47987bfd5ffcf0a0acaaad2510da /CMakeLists.txt
parented5044da43172d86a1aa475473561a4818b7c69c (diff)
parentac6b9c18ef55f4cd36e85069cf0cf82c14e04404 (diff)
downloadlibnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.gz
libnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.bz2
Merge branch 'libnitrokey_3'
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt123
1 files changed, 105 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c324067..46405a9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,14 +1,41 @@
-cmake_minimum_required(VERSION 3.5)
-project(libnitrokey)
+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()
-set(CMAKE_CXX_COMPILER "/usr/bin/clang++-3.8" CACHE string "clang++ compiler" FORCE)
+project(libnitrokey)
+SET(PROJECT_VERSION "3.0-alpha")
+set(CMAKE_CXX_STANDARD 14)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-gnu-variable-sized-type-not-at-end -g3" )
-SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lhidapi-libusb" )
+OPTION(LIBNITROKEY_STATIC "Build libnitrokey statically" TRUE)
-include_directories(include unittest/Catch/include)
+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
@@ -22,19 +49,79 @@ set(SOURCE_FILES
include/NitrokeyManager.h
include/stick10_commands.h
include/stick20_commands.h
- NK_C_API.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.cc include/CommandFailedException.h include/LibraryException.h
- unittest/test_C_API.cpp
- unittest/catch_main.cpp
- unittest/test2.cc
- unittest/test3.cc
- include/LongOperationInProgressException.h
- include/stick10_commands_0.8.h
- )
-
-add_executable(libnitrokey ${SOURCE_FILES}) \ No newline at end of file
+ NK_C_API.h
+ NK_C_API.cc
+ DeviceCommunicationExceptions.cpp)
+
+IF(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)
+
+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) \ No newline at end of file