1# Copyright (c) 2018-2022 Yubico AB. All rights reserved. 2# Use of this source code is governed by a BSD-style 3# license that can be found in the LICENSE file. 4# SPDX-License-Identifier: BSD-2-Clause 5 6add_definitions(-D_FIDO_INTERNAL) 7 8list(APPEND FIDO_SOURCES 9 aes256.c 10 assert.c 11 authkey.c 12 bio.c 13 blob.c 14 buf.c 15 cbor.c 16 compress.c 17 config.c 18 cred.c 19 credman.c 20 dev.c 21 ecdh.c 22 eddsa.c 23 err.c 24 es256.c 25 es384.c 26 hid.c 27 info.c 28 io.c 29 iso7816.c 30 largeblob.c 31 log.c 32 pin.c 33 random.c 34 reset.c 35 rs1.c 36 rs256.c 37 time.c 38 touch.c 39 tpm.c 40 types.c 41 u2f.c 42 util.c 43) 44 45if(FUZZ) 46 list(APPEND FIDO_SOURCES ../fuzz/clock.c) 47 list(APPEND FIDO_SOURCES ../fuzz/pcsc.c) 48 list(APPEND FIDO_SOURCES ../fuzz/prng.c) 49 list(APPEND FIDO_SOURCES ../fuzz/udev.c) 50 list(APPEND FIDO_SOURCES ../fuzz/uniform_random.c) 51 list(APPEND FIDO_SOURCES ../fuzz/wrap.c) 52endif() 53 54if(NFC_LINUX) 55 list(APPEND FIDO_SOURCES netlink.c nfc.c nfc_linux.c) 56endif() 57 58if(USE_PCSC) 59 list(APPEND FIDO_SOURCES nfc.c pcsc.c) 60endif() 61 62if(USE_HIDAPI) 63 list(APPEND FIDO_SOURCES hid_hidapi.c) 64 if(NOT WIN32 AND NOT APPLE) 65 list(APPEND FIDO_SOURCES hid_unix.c) 66 endif() 67elseif(WIN32) 68 list(APPEND FIDO_SOURCES hid_win.c) 69 if(USE_WINHELLO) 70 list(APPEND FIDO_SOURCES winhello.c) 71 endif() 72elseif(APPLE) 73 list(APPEND FIDO_SOURCES hid_osx.c) 74elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 75 list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c) 76elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") 77 list(APPEND FIDO_SOURCES hid_netbsd.c hid_unix.c) 78elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") 79 list(APPEND FIDO_SOURCES hid_openbsd.c hid_unix.c) 80elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR 81 CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD") 82 list(APPEND FIDO_SOURCES hid_freebsd.c hid_unix.c) 83else() 84 message(FATAL_ERROR "please define a hid backend for your platform") 85endif() 86 87if(NOT MSVC) 88 set_source_files_properties(${FIDO_SOURCES} 89 PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}") 90endif() 91 92list(APPEND COMPAT_SOURCES 93 ../openbsd-compat/bsd-asprintf.c 94 ../openbsd-compat/bsd-getpagesize.c 95 ../openbsd-compat/clock_gettime.c 96 ../openbsd-compat/endian_win32.c 97 ../openbsd-compat/explicit_bzero.c 98 ../openbsd-compat/explicit_bzero_win32.c 99 ../openbsd-compat/freezero.c 100 ../openbsd-compat/recallocarray.c 101 ../openbsd-compat/strlcat.c 102 ../openbsd-compat/timingsafe_bcmp.c 103) 104 105if(WIN32) 106 list(APPEND BASE_LIBRARIES wsock32 ws2_32 bcrypt setupapi hid) 107 if(USE_PCSC) 108 list(APPEND BASE_LIBRARIES winscard) 109 endif() 110elseif(APPLE) 111 list(APPEND BASE_LIBRARIES "-framework CoreFoundation" 112 "-framework IOKit") 113 if(USE_PCSC) 114 list(APPEND BASE_LIBRARIES "-framework PCSC") 115 endif() 116endif() 117 118list(APPEND TARGET_LIBRARIES 119 ${CBOR_LIBRARIES} 120 ${CRYPTO_LIBRARIES} 121 ${UDEV_LIBRARIES} 122 ${BASE_LIBRARIES} 123 ${HIDAPI_LIBRARIES} 124 ${ZLIB_LIBRARIES} 125 ${PCSC_LIBRARIES} 126) 127 128# static library 129if(BUILD_STATIC_LIBS) 130 add_library(fido2 STATIC ${FIDO_SOURCES} ${COMPAT_SOURCES}) 131 if(WIN32 AND NOT MINGW) 132 set_target_properties(fido2 PROPERTIES OUTPUT_NAME fido2_static) 133 endif() 134 target_link_libraries(fido2 ${TARGET_LIBRARIES}) 135 install(TARGETS fido2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 136 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 137endif() 138 139# dynamic library 140if(BUILD_SHARED_LIBS) 141 add_library(fido2_shared SHARED ${FIDO_SOURCES} ${COMPAT_SOURCES}) 142 set_target_properties(fido2_shared PROPERTIES OUTPUT_NAME fido2 143 VERSION ${FIDO_VERSION} SOVERSION ${FIDO_MAJOR}) 144 target_link_libraries(fido2_shared ${TARGET_LIBRARIES}) 145 install(TARGETS fido2_shared 146 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 147 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 148 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 149endif() 150 151install(FILES fido.h DESTINATION include) 152install(DIRECTORY fido DESTINATION include) 153 154if(NOT MSVC) 155 configure_file(libfido2.pc.in libfido2.pc @ONLY) 156 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfido2.pc" 157 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 158endif() 159