12ccfa855SEd Maste# Copyright (c) 2018-2022 Yubico AB. All rights reserved. 20afa8e06SEd Maste# Use of this source code is governed by a BSD-style 30afa8e06SEd Maste# license that can be found in the LICENSE file. 42ccfa855SEd Maste# SPDX-License-Identifier: BSD-2-Clause 5*60a517b6SEd Mastecmake_minimum_required(VERSION 3.7) 60afa8e06SEd Maste 70afa8e06SEd Maste# detect AppleClang; needs to come before project() 80afa8e06SEd Mastecmake_policy(SET CMP0025 NEW) 90afa8e06SEd Maste 100afa8e06SEd Masteproject(libfido2 C) 110afa8e06SEd Maste# Set PIE flags for POSITION_INDEPENDENT_CODE targets, added in CMake 3.14. 120afa8e06SEd Masteif(POLICY CMP0083) 130afa8e06SEd Maste cmake_policy(SET CMP0083 NEW) 140afa8e06SEd Masteendif() 150afa8e06SEd Maste 160afa8e06SEd Masteinclude(CheckCCompilerFlag) 170afa8e06SEd Masteinclude(CheckFunctionExists) 180afa8e06SEd Masteinclude(CheckLibraryExists) 190afa8e06SEd Masteinclude(CheckSymbolExists) 200afa8e06SEd Masteinclude(CheckIncludeFiles) 210afa8e06SEd Masteinclude(CheckTypeSize) 220afa8e06SEd Masteinclude(GNUInstallDirs) 230afa8e06SEd Masteinclude(CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED) 240afa8e06SEd Masteif(CHECK_PIE_SUPPORTED) 250afa8e06SEd Maste check_pie_supported(LANGUAGES C) 260afa8e06SEd Masteendif() 270afa8e06SEd Maste 280afa8e06SEd Masteset(CMAKE_POSITION_INDEPENDENT_CODE ON) 290afa8e06SEd Masteset(CMAKE_COLOR_MAKEFILE OFF) 300afa8e06SEd Masteset(CMAKE_VERBOSE_MAKEFILE ON) 310afa8e06SEd Masteset(FIDO_MAJOR "1") 32*60a517b6SEd Masteset(FIDO_MINOR "14") 330afa8e06SEd Masteset(FIDO_PATCH "0") 340afa8e06SEd Masteset(FIDO_VERSION ${FIDO_MAJOR}.${FIDO_MINOR}.${FIDO_PATCH}) 350afa8e06SEd Maste 362ccfa855SEd Masteoption(BUILD_TESTS "Build the regress tests" ON) 370afa8e06SEd Masteoption(BUILD_EXAMPLES "Build example programs" ON) 380afa8e06SEd Masteoption(BUILD_MANPAGES "Build man pages" ON) 392ccfa855SEd Masteoption(BUILD_SHARED_LIBS "Build a shared library" ON) 402ccfa855SEd Masteoption(BUILD_STATIC_LIBS "Build a static library" ON) 410afa8e06SEd Masteoption(BUILD_TOOLS "Build tool programs" ON) 420afa8e06SEd Masteoption(FUZZ "Enable fuzzing instrumentation" OFF) 430afa8e06SEd Masteoption(USE_HIDAPI "Use hidapi as the HID backend" OFF) 442ccfa855SEd Masteoption(USE_PCSC "Enable experimental PCSC support" OFF) 453e696dfbSEd Masteoption(USE_WINHELLO "Abstract Windows Hello as a FIDO device" ON) 463e696dfbSEd Masteoption(NFC_LINUX "Enable NFC support on Linux" ON) 470afa8e06SEd Maste 480afa8e06SEd Masteadd_definitions(-D_FIDO_MAJOR=${FIDO_MAJOR}) 490afa8e06SEd Masteadd_definitions(-D_FIDO_MINOR=${FIDO_MINOR}) 500afa8e06SEd Masteadd_definitions(-D_FIDO_PATCH=${FIDO_PATCH}) 510afa8e06SEd Maste 522ccfa855SEd Masteif(BUILD_SHARED_LIBS) 532ccfa855SEd Maste set(_FIDO2_LIBRARY fido2_shared) 542ccfa855SEd Masteelseif(BUILD_STATIC_LIBS) 552ccfa855SEd Maste set(_FIDO2_LIBRARY fido2) 562ccfa855SEd Masteelse() 572ccfa855SEd Maste message(FATAL_ERROR "Nothing to build (BUILD_*_LIBS=OFF)") 582ccfa855SEd Masteendif() 592ccfa855SEd Maste 603e696dfbSEd Masteif(CYGWIN OR MSYS OR MINGW) 610afa8e06SEd Maste set(WIN32 1) 620afa8e06SEd Masteendif() 630afa8e06SEd Maste 640afa8e06SEd Masteif(WIN32) 650afa8e06SEd Maste add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600) 660afa8e06SEd Masteendif() 670afa8e06SEd Maste 680afa8e06SEd Masteif(APPLE) 690afa8e06SEd Maste set(CMAKE_INSTALL_NAME_DIR 700afa8e06SEd Maste "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") 710afa8e06SEd Masteendif() 720afa8e06SEd Maste 730afa8e06SEd Masteif(NOT MSVC) 740afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_POSIX_C_SOURCE=200809L") 750afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_BSD_SOURCE") 760afa8e06SEd Maste if(APPLE) 770afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DARWIN_C_SOURCE") 780afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__STDC_WANT_LIB_EXT1__=1") 792ccfa855SEd Maste elseif((CMAKE_SYSTEM_NAME STREQUAL "Linux") OR MINGW OR CYGWIN) 800afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_GNU_SOURCE") 810afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_DEFAULT_SOURCE") 82f540a430SEd Maste elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR 83f540a430SEd Maste CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD") 840afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D__BSD_VISIBLE=1") 853e696dfbSEd Maste elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD") 863e696dfbSEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -D_NETBSD_SOURCE") 870afa8e06SEd Maste endif() 880afa8e06SEd Maste set(FIDO_CFLAGS "${FIDO_CFLAGS} -std=c99") 890afa8e06SEd Maste set(CMAKE_C_FLAGS "${FIDO_CFLAGS} ${CMAKE_C_FLAGS}") 900afa8e06SEd Masteendif() 910afa8e06SEd Maste 920afa8e06SEd Mastecheck_c_compiler_flag("-Wshorten-64-to-32" HAVE_SHORTEN_64_TO_32) 93f540a430SEd Mastecheck_c_compiler_flag("-Werror -fstack-protector-all" HAVE_STACK_PROTECTOR_ALL) 940afa8e06SEd Maste 950afa8e06SEd Mastecheck_include_files(cbor.h HAVE_CBOR_H) 960afa8e06SEd Mastecheck_include_files(endian.h HAVE_ENDIAN_H) 970afa8e06SEd Mastecheck_include_files(err.h HAVE_ERR_H) 980afa8e06SEd Mastecheck_include_files(openssl/opensslv.h HAVE_OPENSSLV_H) 990afa8e06SEd Mastecheck_include_files(signal.h HAVE_SIGNAL_H) 1000afa8e06SEd Mastecheck_include_files(sys/random.h HAVE_SYS_RANDOM_H) 1010afa8e06SEd Mastecheck_include_files(unistd.h HAVE_UNISTD_H) 1020afa8e06SEd Maste 1030afa8e06SEd Mastecheck_symbol_exists(arc4random_buf stdlib.h HAVE_ARC4RANDOM_BUF) 1042ccfa855SEd Mastecheck_symbol_exists(asprintf stdio.h HAVE_ASPRINTF) 1050afa8e06SEd Mastecheck_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) 1060afa8e06SEd Mastecheck_symbol_exists(explicit_bzero string.h HAVE_EXPLICIT_BZERO) 1070afa8e06SEd Mastecheck_symbol_exists(freezero stdlib.h HAVE_FREEZERO) 1080afa8e06SEd Mastecheck_symbol_exists(getline stdio.h HAVE_GETLINE) 1090afa8e06SEd Mastecheck_symbol_exists(getopt unistd.h HAVE_GETOPT) 1100afa8e06SEd Mastecheck_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) 1110afa8e06SEd Mastecheck_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM) 1120afa8e06SEd Mastecheck_symbol_exists(memset_s string.h HAVE_MEMSET_S) 1130afa8e06SEd Mastecheck_symbol_exists(readpassphrase readpassphrase.h HAVE_READPASSPHRASE) 1140afa8e06SEd Mastecheck_symbol_exists(recallocarray stdlib.h HAVE_RECALLOCARRAY) 1150afa8e06SEd Mastecheck_symbol_exists(strlcat string.h HAVE_STRLCAT) 1160afa8e06SEd Mastecheck_symbol_exists(strlcpy string.h HAVE_STRLCPY) 117f540a430SEd Mastecheck_symbol_exists(strsep string.h HAVE_STRSEP) 1180afa8e06SEd Mastecheck_symbol_exists(sysconf unistd.h HAVE_SYSCONF) 1190afa8e06SEd Mastecheck_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB) 1200afa8e06SEd Mastecheck_symbol_exists(timingsafe_bcmp string.h HAVE_TIMINGSAFE_BCMP) 1210afa8e06SEd Maste 1220afa8e06SEd Masteset(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 1230afa8e06SEd Mastetry_compile(HAVE_POSIX_IOCTL 1240afa8e06SEd Maste "${CMAKE_CURRENT_BINARY_DIR}/posix_ioctl_check.o" 1250afa8e06SEd Maste "${CMAKE_CURRENT_SOURCE_DIR}/openbsd-compat/posix_ioctl_check.c" 1260afa8e06SEd Maste COMPILE_DEFINITIONS "-Werror -Woverflow -Wsign-conversion") 1270afa8e06SEd Maste 1280afa8e06SEd Mastelist(APPEND CHECK_VARIABLES 1290afa8e06SEd Maste HAVE_ARC4RANDOM_BUF 1302ccfa855SEd Maste HAVE_ASPRINTF 1310afa8e06SEd Maste HAVE_CBOR_H 1320afa8e06SEd Maste HAVE_CLOCK_GETTIME 1330afa8e06SEd Maste HAVE_ENDIAN_H 1340afa8e06SEd Maste HAVE_ERR_H 1350afa8e06SEd Maste HAVE_FREEZERO 1360afa8e06SEd Maste HAVE_GETLINE 1370afa8e06SEd Maste HAVE_GETOPT 1380afa8e06SEd Maste HAVE_GETPAGESIZE 1390afa8e06SEd Maste HAVE_GETRANDOM 1400afa8e06SEd Maste HAVE_MEMSET_S 1410afa8e06SEd Maste HAVE_OPENSSLV_H 1420afa8e06SEd Maste HAVE_POSIX_IOCTL 1430afa8e06SEd Maste HAVE_READPASSPHRASE 1440afa8e06SEd Maste HAVE_RECALLOCARRAY 1450afa8e06SEd Maste HAVE_SIGNAL_H 1460afa8e06SEd Maste HAVE_STRLCAT 1470afa8e06SEd Maste HAVE_STRLCPY 148f540a430SEd Maste HAVE_STRSEP 1490afa8e06SEd Maste HAVE_SYSCONF 1500afa8e06SEd Maste HAVE_SYS_RANDOM_H 1510afa8e06SEd Maste HAVE_TIMESPECSUB 1520afa8e06SEd Maste HAVE_TIMINGSAFE_BCMP 1530afa8e06SEd Maste HAVE_UNISTD_H 1540afa8e06SEd Maste) 1550afa8e06SEd Maste 1560afa8e06SEd Masteforeach(v ${CHECK_VARIABLES}) 1570afa8e06SEd Maste if (${v}) 1580afa8e06SEd Maste add_definitions(-D${v}) 1590afa8e06SEd Maste endif() 1600afa8e06SEd Masteendforeach() 1610afa8e06SEd Maste 1622ccfa855SEd Masteif(HAVE_EXPLICIT_BZERO AND NOT FUZZ) 1630afa8e06SEd Maste add_definitions(-DHAVE_EXPLICIT_BZERO) 1640afa8e06SEd Masteendif() 1650afa8e06SEd Maste 1660afa8e06SEd Masteif(UNIX) 1670afa8e06SEd Maste add_definitions(-DHAVE_DEV_URANDOM) 1680afa8e06SEd Masteendif() 1690afa8e06SEd Maste 1702ccfa855SEd Maste 1710afa8e06SEd Masteif(MSVC) 1720afa8e06SEd Maste if((NOT CBOR_INCLUDE_DIRS) OR (NOT CBOR_LIBRARY_DIRS) OR 1732ccfa855SEd Maste (NOT CRYPTO_INCLUDE_DIRS) OR (NOT CRYPTO_LIBRARY_DIRS) OR 1742ccfa855SEd Maste (NOT ZLIB_INCLUDE_DIRS) OR (NOT ZLIB_LIBRARY_DIRS)) 175f540a430SEd Maste message(FATAL_ERROR "please define " 1762ccfa855SEd Maste "{CBOR,CRYPTO,ZLIB}_{INCLUDE,LIBRARY}_DIRS when " 177f540a430SEd Maste "building under msvc") 1780afa8e06SEd Maste endif() 1792ccfa855SEd Maste if(BUILD_TESTS AND BUILD_SHARED_LIBS AND 1802ccfa855SEd Maste ((NOT CBOR_BIN_DIRS) OR (NOT ZLIB_BIN_DIRS) OR (NOT CRYPTO_BIN_DIRS))) 1812ccfa855SEd Maste message(FATAL_ERROR "please define {CBOR,CRYPTO,ZLIB}_BIN_DIRS " 1822ccfa855SEd Maste "when building tests") 1832ccfa855SEd Maste endif() 1842ccfa855SEd Maste if(NOT CBOR_LIBRARIES) 1850afa8e06SEd Maste set(CBOR_LIBRARIES cbor) 1862ccfa855SEd Maste endif() 1872ccfa855SEd Maste if(NOT ZLIB_LIBRARIES) 1882ccfa855SEd Maste set(ZLIB_LIBRARIES zlib1) 1892ccfa855SEd Maste endif() 1902ccfa855SEd Maste if(NOT CRYPTO_LIBRARIES) 1912ccfa855SEd Maste set(CRYPTO_LIBRARIES crypto) 1922ccfa855SEd Maste endif() 1932ccfa855SEd Maste 1940afa8e06SEd Maste set(MSVC_DISABLED_WARNINGS_LIST 195f540a430SEd Maste "C4152" # nonstandard extension used: function/data pointer 196f540a430SEd Maste # conversion in expression; 1970afa8e06SEd Maste "C4200" # nonstandard extension used: zero-sized array in 1980afa8e06SEd Maste # struct/union; 1993e696dfbSEd Maste "C4201" # nonstandard extension used: nameless struct/union; 2000afa8e06SEd Maste "C4204" # nonstandard extension used: non-constant aggregate 2010afa8e06SEd Maste # initializer; 2020afa8e06SEd Maste "C4706" # assignment within conditional expression; 2030afa8e06SEd Maste "C4996" # The POSIX name for this item is deprecated. Instead, 2040afa8e06SEd Maste # use the ISO C and C++ conformant name; 2050afa8e06SEd Maste "C6287" # redundant code: the left and right subexpressions are identical 2060afa8e06SEd Maste ) 2070afa8e06SEd Maste # The construction in the following 3 lines was taken from LibreSSL's 2080afa8e06SEd Maste # CMakeLists.txt. 2090afa8e06SEd Maste string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR 2100afa8e06SEd Maste ${MSVC_DISABLED_WARNINGS_LIST}) 2110afa8e06SEd Maste string(REGEX REPLACE "[/-]W[1234][ ]?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) 2120afa8e06SEd Maste set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}") 213f540a430SEd Maste set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Od /Z7 /guard:cf /sdl /RTCcsu") 2140afa8e06SEd Maste set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi /guard:cf /sdl") 2153e696dfbSEd Maste if(USE_WINHELLO) 2160afa8e06SEd Maste add_definitions(-DUSE_WINHELLO) 2173e696dfbSEd Maste endif() 2183e696dfbSEd Maste set(NFC_LINUX OFF) 2190afa8e06SEd Masteelse() 2200afa8e06SEd Maste include(FindPkgConfig) 2210afa8e06SEd Maste pkg_search_module(CBOR libcbor) 2220afa8e06SEd Maste pkg_search_module(CRYPTO libcrypto) 2230afa8e06SEd Maste pkg_search_module(ZLIB zlib) 2240afa8e06SEd Maste 2250afa8e06SEd Maste if(NOT CBOR_FOUND AND NOT HAVE_CBOR_H) 2260afa8e06SEd Maste message(FATAL_ERROR "could not find libcbor") 2270afa8e06SEd Maste endif() 2280afa8e06SEd Maste if(NOT CRYPTO_FOUND AND NOT HAVE_OPENSSLV_H) 2290afa8e06SEd Maste message(FATAL_ERROR "could not find libcrypto") 2300afa8e06SEd Maste endif() 2310afa8e06SEd Maste if(NOT ZLIB_FOUND) 2320afa8e06SEd Maste message(FATAL_ERROR "could not find zlib") 2330afa8e06SEd Maste endif() 2340afa8e06SEd Maste 2352ccfa855SEd Maste if(NOT CBOR_LIBRARIES) 2360afa8e06SEd Maste set(CBOR_LIBRARIES "cbor") 2372ccfa855SEd Maste endif() 2382ccfa855SEd Maste if(NOT CRYPTO_LIBRARIES) 2390afa8e06SEd Maste set(CRYPTO_LIBRARIES "crypto") 2402ccfa855SEd Maste endif() 2410afa8e06SEd Maste 2420afa8e06SEd Maste if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 2430afa8e06SEd Maste pkg_search_module(UDEV libudev REQUIRED) 2440afa8e06SEd Maste set(UDEV_NAME "udev") 2450afa8e06SEd Maste # If using hidapi, use hidapi-hidraw. 2460afa8e06SEd Maste set(HIDAPI_SUFFIX -hidraw) 2470afa8e06SEd Maste if(NOT HAVE_CLOCK_GETTIME) 2480afa8e06SEd Maste # Look for clock_gettime in librt. 2490afa8e06SEd Maste check_library_exists(rt clock_gettime "time.h" 2500afa8e06SEd Maste HAVE_CLOCK_GETTIME) 2510afa8e06SEd Maste if (HAVE_CLOCK_GETTIME) 2520afa8e06SEd Maste add_definitions(-DHAVE_CLOCK_GETTIME) 2530afa8e06SEd Maste set(BASE_LIBRARIES ${BASE_LIBRARIES} rt) 2540afa8e06SEd Maste endif() 2550afa8e06SEd Maste endif() 2563e696dfbSEd Maste else() 2573e696dfbSEd Maste set(NFC_LINUX OFF) 2580afa8e06SEd Maste endif() 2590afa8e06SEd Maste 2600afa8e06SEd Maste if(MINGW) 2610afa8e06SEd Maste # MinGW is stuck with a flavour of C89. 2620afa8e06SEd Maste add_definitions(-DFIDO_NO_DIAGNOSTIC) 2630afa8e06SEd Maste add_definitions(-DWC_ERR_INVALID_CHARS=0x80) 2640afa8e06SEd Maste add_compile_options(-Wno-unused-parameter) 2650afa8e06SEd Maste endif() 2660afa8e06SEd Maste 2672ccfa855SEd Maste if(FUZZ) 2682ccfa855SEd Maste set(USE_PCSC ON) 2692ccfa855SEd Maste add_definitions(-DFIDO_FUZZ) 2702ccfa855SEd Maste endif() 2712ccfa855SEd Maste 2722ccfa855SEd Maste # If building with PCSC, look for pcsc-lite. 2732ccfa855SEd Maste if(USE_PCSC AND NOT (APPLE OR CYGWIN OR MSYS OR MINGW)) 2742ccfa855SEd Maste pkg_search_module(PCSC libpcsclite REQUIRED) 2752ccfa855SEd Maste set(PCSC_LIBRARIES pcsclite) 2762ccfa855SEd Maste endif() 2772ccfa855SEd Maste 2780afa8e06SEd Maste if(USE_HIDAPI) 2790afa8e06SEd Maste add_definitions(-DUSE_HIDAPI) 2800afa8e06SEd Maste pkg_search_module(HIDAPI hidapi${HIDAPI_SUFFIX} REQUIRED) 2810afa8e06SEd Maste set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX}) 2820afa8e06SEd Maste endif() 2830afa8e06SEd Maste 2840afa8e06SEd Maste if(NFC_LINUX) 2852ccfa855SEd Maste add_definitions(-DUSE_NFC) 2860afa8e06SEd Maste endif() 2870afa8e06SEd Maste 2883e696dfbSEd Maste if(WIN32) 2893e696dfbSEd Maste if(USE_WINHELLO) 2903e696dfbSEd Maste add_definitions(-DUSE_WINHELLO) 2913e696dfbSEd Maste endif() 2923e696dfbSEd Maste else() 2933e696dfbSEd Maste set(USE_WINHELLO OFF) 2943e696dfbSEd Maste endif() 2953e696dfbSEd Maste 2960afa8e06SEd Maste add_compile_options(-Wall) 2970afa8e06SEd Maste add_compile_options(-Wextra) 2980afa8e06SEd Maste add_compile_options(-Werror) 2990afa8e06SEd Maste add_compile_options(-Wshadow) 3000afa8e06SEd Maste add_compile_options(-Wcast-qual) 3010afa8e06SEd Maste add_compile_options(-Wwrite-strings) 3020afa8e06SEd Maste add_compile_options(-Wmissing-prototypes) 3030afa8e06SEd Maste add_compile_options(-Wbad-function-cast) 3042ccfa855SEd Maste add_compile_options(-Wimplicit-fallthrough) 3050afa8e06SEd Maste add_compile_options(-pedantic) 3060afa8e06SEd Maste add_compile_options(-pedantic-errors) 3070afa8e06SEd Maste 3082ccfa855SEd Maste set(EXTRA_CFLAGS "-Wconversion -Wsign-conversion") 3092ccfa855SEd Maste 3103e696dfbSEd Maste if(WIN32) 3113e696dfbSEd Maste add_compile_options(-Wno-type-limits) 3123e696dfbSEd Maste add_compile_options(-Wno-cast-function-type) 3133e696dfbSEd Maste endif() 3142ccfa855SEd Maste 3150afa8e06SEd Maste if(HAVE_SHORTEN_64_TO_32) 3160afa8e06SEd Maste add_compile_options(-Wshorten-64-to-32) 3170afa8e06SEd Maste endif() 3182ccfa855SEd Maste 3190afa8e06SEd Maste if(HAVE_STACK_PROTECTOR_ALL) 3200afa8e06SEd Maste add_compile_options(-fstack-protector-all) 3210afa8e06SEd Maste endif() 3220afa8e06SEd Maste 3230afa8e06SEd Maste set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g2") 3240afa8e06SEd Maste set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer") 3250afa8e06SEd Maste set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") 3260afa8e06SEd Maste 327f540a430SEd Maste if(CRYPTO_VERSION VERSION_GREATER_EQUAL 3.0) 328f540a430SEd Maste add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) 329f540a430SEd Maste endif() 330f540a430SEd Maste 3312ccfa855SEd Maste if(NOT FUZZ) 3322ccfa855SEd Maste set(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wframe-larger-than=2047") 3330afa8e06SEd Maste endif() 3340afa8e06SEd Masteendif() 3350afa8e06SEd Maste 3360afa8e06SEd Maste# Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 3370afa8e06SEd Masteif(CMAKE_COMPILER_IS_GNUCC) 3380afa8e06SEd Maste add_compile_options(-Wno-unused-result) 3390afa8e06SEd Masteendif() 3400afa8e06SEd Maste 3410afa8e06SEd Maste# Decide which keyword to use for thread-local storage. 3420afa8e06SEd Masteif(CMAKE_COMPILER_IS_GNUCC OR 3430afa8e06SEd Maste CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 3440afa8e06SEd Maste CMAKE_C_COMPILER_ID STREQUAL "AppleClang") 3450afa8e06SEd Maste set(TLS "__thread") 3460afa8e06SEd Masteelseif(WIN32) 3470afa8e06SEd Maste set(TLS "__declspec(thread)") 3480afa8e06SEd Masteendif() 3490afa8e06SEd Masteadd_definitions(-DTLS=${TLS}) 3500afa8e06SEd Maste 3512ccfa855SEd Masteif(USE_PCSC) 3522ccfa855SEd Maste add_definitions(-DUSE_PCSC) 3532ccfa855SEd Masteendif() 3542ccfa855SEd Maste 3550afa8e06SEd Maste# export list 3560afa8e06SEd Masteif(APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 3570afa8e06SEd Maste CMAKE_C_COMPILER_ID STREQUAL "AppleClang")) 3580afa8e06SEd Maste # clang + lld 3590afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} 3600afa8e06SEd Maste " -exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/src/export.llvm") 3610afa8e06SEd Masteelseif(NOT MSVC) 3620afa8e06SEd Maste # clang/gcc + gnu ld 3630afa8e06SEd Maste if(FUZZ) 3640afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} 3650afa8e06SEd Maste " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fuzz/export.gnu") 3660afa8e06SEd Maste else() 3670afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} 3680afa8e06SEd Maste " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/export.gnu") 3690afa8e06SEd Maste endif() 3700afa8e06SEd Maste if(NOT WIN32) 3710afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS 3720afa8e06SEd Maste ${CMAKE_SHARED_LINKER_FLAGS} 3730afa8e06SEd Maste " -Wl,-z,noexecstack -Wl,-z,relro,-z,now") 3740afa8e06SEd Maste string(CONCAT CMAKE_EXE_LINKER_FLAGS 3750afa8e06SEd Maste ${CMAKE_EXE_LINKER_FLAGS} 3760afa8e06SEd Maste " -Wl,-z,noexecstack -Wl,-z,relro,-z,now") 3770afa8e06SEd Maste if(FUZZ) 3780afa8e06SEd Maste file(STRINGS fuzz/wrapped.sym WRAPPED_SYMBOLS) 3790afa8e06SEd Maste foreach(s ${WRAPPED_SYMBOLS}) 3800afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS 3810afa8e06SEd Maste ${CMAKE_SHARED_LINKER_FLAGS} 3820afa8e06SEd Maste " -Wl,--wrap=${s}") 3830afa8e06SEd Maste endforeach() 3840afa8e06SEd Maste endif() 3850afa8e06SEd Maste endif() 3860afa8e06SEd Masteelse() 3870afa8e06SEd Maste string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} 3880afa8e06SEd Maste " /def:\"${CMAKE_CURRENT_SOURCE_DIR}/src/export.msvc\"") 3890afa8e06SEd Masteendif() 3900afa8e06SEd Maste 3912ccfa855SEd Masteinclude_directories(${PROJECT_SOURCE_DIR}/src) 3920afa8e06SEd Masteinclude_directories(${CBOR_INCLUDE_DIRS}) 3930afa8e06SEd Masteinclude_directories(${CRYPTO_INCLUDE_DIRS}) 3940afa8e06SEd Masteinclude_directories(${HIDAPI_INCLUDE_DIRS}) 3952ccfa855SEd Masteinclude_directories(${PCSC_INCLUDE_DIRS}) 3960afa8e06SEd Masteinclude_directories(${UDEV_INCLUDE_DIRS}) 3970afa8e06SEd Masteinclude_directories(${ZLIB_INCLUDE_DIRS}) 3980afa8e06SEd Maste 3990afa8e06SEd Mastelink_directories(${CBOR_LIBRARY_DIRS}) 4000afa8e06SEd Mastelink_directories(${CRYPTO_LIBRARY_DIRS}) 4010afa8e06SEd Mastelink_directories(${HIDAPI_LIBRARY_DIRS}) 4022ccfa855SEd Mastelink_directories(${PCSC_LIBRARY_DIRS}) 4030afa8e06SEd Mastelink_directories(${UDEV_LIBRARY_DIRS}) 4040afa8e06SEd Mastelink_directories(${ZLIB_LIBRARY_DIRS}) 4050afa8e06SEd Maste 4060afa8e06SEd Mastemessage(STATUS "BASE_LIBRARIES: ${BASE_LIBRARIES}") 4070afa8e06SEd Mastemessage(STATUS "BUILD_EXAMPLES: ${BUILD_EXAMPLES}") 4080afa8e06SEd Mastemessage(STATUS "BUILD_MANPAGES: ${BUILD_MANPAGES}") 4090afa8e06SEd Mastemessage(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}") 4100afa8e06SEd Mastemessage(STATUS "BUILD_STATIC_LIBS: ${BUILD_STATIC_LIBS}") 4110afa8e06SEd Mastemessage(STATUS "BUILD_TOOLS: ${BUILD_TOOLS}") 4120afa8e06SEd Mastemessage(STATUS "CBOR_INCLUDE_DIRS: ${CBOR_INCLUDE_DIRS}") 4130afa8e06SEd Mastemessage(STATUS "CBOR_LIBRARIES: ${CBOR_LIBRARIES}") 4140afa8e06SEd Mastemessage(STATUS "CBOR_LIBRARY_DIRS: ${CBOR_LIBRARY_DIRS}") 4152ccfa855SEd Masteif(BUILD_TESTS) 4162ccfa855SEd Maste message(STATUS "CBOR_BIN_DIRS: ${CBOR_BIN_DIRS}") 4172ccfa855SEd Masteendif() 4180afa8e06SEd Mastemessage(STATUS "CBOR_VERSION: ${CBOR_VERSION}") 4190afa8e06SEd Mastemessage(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 4200afa8e06SEd Mastemessage(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") 4210afa8e06SEd Mastemessage(STATUS "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}") 4220afa8e06SEd Mastemessage(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") 4232ccfa855SEd Mastemessage(STATUS "CMAKE_CROSSCOMPILING: ${CMAKE_CROSSCOMPILING}") 4242ccfa855SEd Mastemessage(STATUS "CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}") 4252ccfa855SEd Mastemessage(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}") 4262ccfa855SEd Mastemessage(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR: ${CMAKE_HOST_SYSTEM_PROCESSOR}") 4270afa8e06SEd Mastemessage(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") 4280afa8e06SEd Mastemessage(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") 4290afa8e06SEd Mastemessage(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") 4302ccfa855SEd Mastemessage(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") 4310afa8e06SEd Mastemessage(STATUS "CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION}") 4320afa8e06SEd Mastemessage(STATUS "CRYPTO_INCLUDE_DIRS: ${CRYPTO_INCLUDE_DIRS}") 4330afa8e06SEd Mastemessage(STATUS "CRYPTO_LIBRARIES: ${CRYPTO_LIBRARIES}") 4340afa8e06SEd Mastemessage(STATUS "CRYPTO_LIBRARY_DIRS: ${CRYPTO_LIBRARY_DIRS}") 4352ccfa855SEd Masteif(BUILD_TESTS) 4362ccfa855SEd Maste message(STATUS "CRYPTO_BIN_DIRS: ${CRYPTO_BIN_DIRS}") 4372ccfa855SEd Masteendif() 4380afa8e06SEd Mastemessage(STATUS "CRYPTO_VERSION: ${CRYPTO_VERSION}") 4390afa8e06SEd Mastemessage(STATUS "FIDO_VERSION: ${FIDO_VERSION}") 4400afa8e06SEd Mastemessage(STATUS "FUZZ: ${FUZZ}") 4412ccfa855SEd Masteif(FUZZ) 4422ccfa855SEd Maste message(STATUS "FUZZ_LDFLAGS: ${FUZZ_LDFLAGS}") 4432ccfa855SEd Masteendif() 4440afa8e06SEd Mastemessage(STATUS "ZLIB_INCLUDE_DIRS: ${ZLIB_INCLUDE_DIRS}") 4450afa8e06SEd Mastemessage(STATUS "ZLIB_LIBRARIES: ${ZLIB_LIBRARIES}") 4460afa8e06SEd Mastemessage(STATUS "ZLIB_LIBRARY_DIRS: ${ZLIB_LIBRARY_DIRS}") 4472ccfa855SEd Masteif(BUILD_TESTS) 4482ccfa855SEd Maste message(STATUS "ZLIB_BIN_DIRS: ${ZLIB_BIN_DIRS}") 4492ccfa855SEd Masteendif() 4500afa8e06SEd Mastemessage(STATUS "ZLIB_VERSION: ${ZLIB_VERSION}") 4510afa8e06SEd Masteif(USE_HIDAPI) 4520afa8e06SEd Maste message(STATUS "HIDAPI_INCLUDE_DIRS: ${HIDAPI_INCLUDE_DIRS}") 4530afa8e06SEd Maste message(STATUS "HIDAPI_LIBRARIES: ${HIDAPI_LIBRARIES}") 4540afa8e06SEd Maste message(STATUS "HIDAPI_LIBRARY_DIRS: ${HIDAPI_LIBRARY_DIRS}") 4550afa8e06SEd Maste message(STATUS "HIDAPI_VERSION: ${HIDAPI_VERSION}") 4560afa8e06SEd Masteendif() 4572ccfa855SEd Mastemessage(STATUS "PCSC_INCLUDE_DIRS: ${PCSC_INCLUDE_DIRS}") 4582ccfa855SEd Mastemessage(STATUS "PCSC_LIBRARIES: ${PCSC_LIBRARIES}") 4592ccfa855SEd Mastemessage(STATUS "PCSC_LIBRARY_DIRS: ${PCSC_LIBRARY_DIRS}") 4602ccfa855SEd Mastemessage(STATUS "PCSC_VERSION: ${PCSC_VERSION}") 4610afa8e06SEd Mastemessage(STATUS "TLS: ${TLS}") 4620afa8e06SEd Mastemessage(STATUS "UDEV_INCLUDE_DIRS: ${UDEV_INCLUDE_DIRS}") 4630afa8e06SEd Mastemessage(STATUS "UDEV_LIBRARIES: ${UDEV_LIBRARIES}") 4640afa8e06SEd Mastemessage(STATUS "UDEV_LIBRARY_DIRS: ${UDEV_LIBRARY_DIRS}") 4650afa8e06SEd Mastemessage(STATUS "UDEV_RULES_DIR: ${UDEV_RULES_DIR}") 4660afa8e06SEd Mastemessage(STATUS "UDEV_VERSION: ${UDEV_VERSION}") 4670afa8e06SEd Mastemessage(STATUS "USE_HIDAPI: ${USE_HIDAPI}") 4682ccfa855SEd Mastemessage(STATUS "USE_PCSC: ${USE_PCSC}") 4690afa8e06SEd Mastemessage(STATUS "USE_WINHELLO: ${USE_WINHELLO}") 4700afa8e06SEd Mastemessage(STATUS "NFC_LINUX: ${NFC_LINUX}") 4710afa8e06SEd Maste 4722ccfa855SEd Masteif(BUILD_TESTS) 4732ccfa855SEd Maste enable_testing() 4742ccfa855SEd Masteendif() 4752ccfa855SEd Maste 4762ccfa855SEd Masteadd_subdirectory(src) 4772ccfa855SEd Maste 4782ccfa855SEd Masteif(BUILD_TESTS) 4792ccfa855SEd Maste add_subdirectory(regress) 4802ccfa855SEd Masteendif() 4810afa8e06SEd Masteif(BUILD_EXAMPLES) 4822ccfa855SEd Maste add_subdirectory(examples) 4830afa8e06SEd Masteendif() 4840afa8e06SEd Masteif(BUILD_TOOLS) 4852ccfa855SEd Maste add_subdirectory(tools) 4860afa8e06SEd Masteendif() 4870afa8e06SEd Masteif(BUILD_MANPAGES) 4882ccfa855SEd Maste add_subdirectory(man) 4890afa8e06SEd Masteendif() 4900afa8e06SEd Maste 4910afa8e06SEd Masteif(NOT WIN32) 4920afa8e06SEd Maste if(FUZZ) 4932ccfa855SEd Maste add_subdirectory(fuzz) 4940afa8e06SEd Maste endif() 4950afa8e06SEd Maste if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 4962ccfa855SEd Maste add_subdirectory(udev) 4970afa8e06SEd Maste endif() 4980afa8e06SEd Masteendif() 499