Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularize library build #218

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 63 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(DEV OFF)

include(GNUInstallDirs)

Expand All @@ -43,35 +44,67 @@ MESSAGE("${PROJECT_NAME}: Build type: ${CMAKE_BUILD_TYPE}")

include_directories(hidapi)
include_directories(libnitrokey)

set(COMMON_FILES
libnitrokey/command.h
libnitrokey/command_id.h
libnitrokey/cxx_semantics.h
libnitrokey/device.h
libnitrokey/device_proto.h
libnitrokey/dissect.h
libnitrokey/log.h
libnitrokey/misc.h
libnitrokey/NitrokeyManager.h
libnitrokey/stick10_commands.h
libnitrokey/stick20_commands.h
libnitrokey/CommandFailedException.h
libnitrokey/LibraryException.h
libnitrokey/LongOperationInProgressException.h
libnitrokey/stick10_commands_0.8.h
command_id.cc
device.cc
log.cc
misc.cc
nk_strndup.c
DeviceCommunicationExceptions.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cc
)

set(SOURCE_FILES
libnitrokey/command.h
libnitrokey/command_id.h
libnitrokey/cxx_semantics.h
libnitrokey/device.h
libnitrokey/device_proto.h
libnitrokey/dissect.h
libnitrokey/log.h
libnitrokey/misc.h
libnitrokey/NitrokeyManager.h
libnitrokey/stick10_commands.h
libnitrokey/stick20_commands.h
libnitrokey/CommandFailedException.h
libnitrokey/LibraryException.h
libnitrokey/LongOperationInProgressException.h
libnitrokey/stick10_commands_0.8.h
command_id.cc
device.cc
log.cc
misc.cc
${COMMON_FILES}
NitrokeyManager.cc
NitrokeyManagerStorage.cpp
NitrokeyManagerStorage.h
NitrokeyManagerOTP.cc
NitrokeyManagerOTP.h
NitrokeyManagerPWS.h
NitrokeyManagerPWS.cc
NK_C_API.h
NK_C_API.cc
DeviceCommunicationExceptions.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cc
NK_C_API_pws.cpp
NK_C_API_otp.cpp
NK_C_API_helpers.cpp
NK_C_API_helpers.h
NK_C_API_storage.h
NK_C_API_storage.cpp
)

set(SOURCE_FILES_storage
${COMMON_FILES}
NitrokeyManager.cc
NitrokeyManagerStorage.cpp
NitrokeyManagerStorage.h
NK_C_API.h
NK_C_API.cc
NK_C_API_helpers.cpp
NK_C_API_helpers.h
NK_C_API_storage.h
NK_C_API_storage.cpp
)

set(BUILD_SHARED_LIBS ON CACHE BOOL "Build all libraries as shared")
add_library(nitrokey ${SOURCE_FILES})
add_library(nitrokey-storage ${SOURCE_FILES_storage})

IF(APPLE)
include_directories(hidapi/hidapi)
Expand All @@ -82,8 +115,12 @@ ELSEIF(UNIX)
# add_library(hidapi-libusb STATIC hidapi/libusb/hid.c )
find_package(PkgConfig)
pkg_search_module(HIDAPI_LIBUSB REQUIRED hidapi-libusb)
target_compile_options(nitrokey PRIVATE ${HIDAPI_LIBUSB_CFLAGS})
IF(DEV)
target_compile_options(nitrokey PRIVATE "${HIDAPI_LIBUSB_CFLAGS} -Os")
target_link_options(nitrokey PRIVATE "-Wl,-Map=output.map")
ENDIF()
target_link_libraries(nitrokey ${HIDAPI_LIBUSB_LDFLAGS})
target_link_libraries(nitrokey-storage ${HIDAPI_LIBUSB_LDFLAGS})
ELSEIF(WIN32)
include_directories(hidapi/hidapi)
add_library(hidapi-libusb STATIC hidapi/windows/hid.c )
Expand All @@ -94,6 +131,9 @@ ENDIF()
set_target_properties(nitrokey PROPERTIES
VERSION ${libnitrokey_VERSION}
SOVERSION ${libnitrokey_VERSION_MAJOR})
set_target_properties(nitrokey-storage PROPERTIES
VERSION ${libnitrokey_VERSION}
SOVERSION ${libnitrokey_VERSION_MAJOR})

OPTION(ERROR_ON_WARNING "Stop compilation on warning found (not supported for MSVC)" OFF)
if (NOT MSVC)
Expand All @@ -109,6 +149,7 @@ endif()
OPTION(NO_LOG "Compile without logging functionality and its strings (decreases size)" OFF)
IF (NO_LOG)
SET_TARGET_PROPERTIES(nitrokey PROPERTIES COMPILE_DEFINITIONS "NO_LOG")
SET_TARGET_PROPERTIES(nitrokey-storage PROPERTIES COMPILE_DEFINITIONS "NO_LOG")
ENDIF()

OPTION(LOG_VOLATILE_DATA "Log volatile data (debug)" OFF)
Expand Down
Loading