1# Copyright (c) 2018 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 5add_definitions(-D_FIDO_INTERNAL) 6 7list(APPEND FIDO_SOURCES 8 aes256.c 9 assert.c 10 authkey.c 11 bio.c 12 blob.c 13 buf.c 14 cbor.c 15 compress.c 16 config.c 17 cred.c 18 credman.c 19 dev.c 20 ecdh.c 21 eddsa.c 22 err.c 23 es256.c 24 hid.c 25 info.c 26 io.c 27 iso7816.c 28 largeblob.c 29 log.c 30 pin.c 31 random.c 32 reset.c 33 rs256.c 34 u2f.c 35) 36 37if(FUZZ) 38 list(APPEND FIDO_SOURCES ../fuzz/prng.c) 39 list(APPEND FIDO_SOURCES ../fuzz/uniform_random.c) 40 list(APPEND FIDO_SOURCES ../fuzz/udev.c) 41 list(APPEND FIDO_SOURCES ../fuzz/wrap.c) 42endif() 43if(NFC_LINUX) 44 list(APPEND FIDO_SOURCES netlink.c nfc_linux.c) 45endif() 46 47if(USE_HIDAPI) 48 list(APPEND FIDO_SOURCES hid_hidapi.c) 49 if(NOT WIN32 AND NOT APPLE) 50 list(APPEND FIDO_SOURCES hid_unix.c) 51 endif() 52elseif(WIN32) 53 list(APPEND FIDO_SOURCES hid_win.c) 54 if(USE_WINHELLO) 55 list(APPEND FIDO_SOURCES winhello.c) 56 endif() 57elseif(APPLE) 58 list(APPEND FIDO_SOURCES hid_osx.c) 59elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 60 list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c) 61elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") 62 list(APPEND FIDO_SOURCES hid_netbsd.c hid_unix.c) 63elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") 64 list(APPEND FIDO_SOURCES hid_openbsd.c hid_unix.c) 65elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") 66 list(APPEND FIDO_SOURCES hid_freebsd.c hid_unix.c) 67else() 68 message(FATAL_ERROR "please define a hid backend for your platform") 69endif() 70 71if(NOT MSVC) 72 set_source_files_properties(${FIDO_SOURCES} PROPERTIES COMPILE_FLAGS 73 "-Wconversion -Wsign-conversion") 74endif() 75 76list(APPEND COMPAT_SOURCES 77 ../openbsd-compat/bsd-getpagesize.c 78 ../openbsd-compat/endian_win32.c 79 ../openbsd-compat/explicit_bzero.c 80 ../openbsd-compat/explicit_bzero_win32.c 81 ../openbsd-compat/freezero.c 82 ../openbsd-compat/hkdf.c 83 ../openbsd-compat/recallocarray.c 84 ../openbsd-compat/strlcat.c 85 ../openbsd-compat/timingsafe_bcmp.c 86) 87 88if(WIN32) 89 list(APPEND BASE_LIBRARIES wsock32 ws2_32 bcrypt setupapi hid) 90 if(USE_WINHELLO) 91 list(APPEND BASE_LIBRARIES webauthn) 92 endif() 93elseif(APPLE) 94 list(APPEND BASE_LIBRARIES "-framework CoreFoundation" "-framework IOKit") 95endif() 96 97list(APPEND TARGET_LIBRARIES 98 ${CBOR_LIBRARIES} 99 ${CRYPTO_LIBRARIES} 100 ${UDEV_LIBRARIES} 101 ${BASE_LIBRARIES} 102 ${HIDAPI_LIBRARIES} 103 ${ZLIB_LIBRARIES} 104) 105 106# static library 107if(BUILD_STATIC_LIBS) 108 add_library(fido2 STATIC ${FIDO_SOURCES} ${COMPAT_SOURCES}) 109 if(WIN32 AND NOT MINGW) 110 set_target_properties(fido2 PROPERTIES OUTPUT_NAME fido2_static) 111 endif() 112 target_link_libraries(fido2 ${TARGET_LIBRARIES}) 113 install(TARGETS fido2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 114 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 115endif() 116 117# dynamic library 118if(BUILD_SHARED_LIBS) 119 add_library(fido2_shared SHARED ${FIDO_SOURCES} ${COMPAT_SOURCES}) 120 set_target_properties(fido2_shared PROPERTIES OUTPUT_NAME fido2 121 VERSION ${FIDO_VERSION} SOVERSION ${FIDO_MAJOR}) 122 target_link_libraries(fido2_shared ${TARGET_LIBRARIES}) 123 install(TARGETS fido2_shared 124 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 125 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 126 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 127endif() 128 129install(FILES fido.h DESTINATION include) 130install(DIRECTORY fido DESTINATION include) 131 132if(NOT WIN32) 133 configure_file(libfido2.pc.in libfido2.pc @ONLY) 134 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfido2.pc" 135 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") 136endif() 137