summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt111
1 files changed, 51 insertions, 60 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0bb2e87..dbd5fa5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -10,6 +10,8 @@ cmake_minimum_required(VERSION 3.0)
10 10
11include(CheckCCompilerFlag) 11include(CheckCCompilerFlag)
12include(CheckFunctionExists) 12include(CheckFunctionExists)
13include(CheckLibraryExists)
14include(CheckSymbolExists)
13include(CheckIncludeFiles) 15include(CheckIncludeFiles)
14include(CheckTypeSize) 16include(CheckTypeSize)
15include(GNUInstallDirs) 17include(GNUInstallDirs)
@@ -19,7 +21,7 @@ set(CMAKE_VERBOSE_MAKEFILE on)
19set(CMAKE_POSITION_INDEPENDENT_CODE ON) 21set(CMAKE_POSITION_INDEPENDENT_CODE ON)
20 22
21set(FIDO_MAJOR "1") 23set(FIDO_MAJOR "1")
22set(FIDO_MINOR "4") 24set(FIDO_MINOR "5")
23set(FIDO_PATCH "0") 25set(FIDO_PATCH "0")
24set(FIDO_VERSION ${FIDO_MAJOR}.${FIDO_MINOR}.${FIDO_PATCH}) 26set(FIDO_VERSION ${FIDO_MAJOR}.${FIDO_MINOR}.${FIDO_PATCH})
25 27
@@ -33,21 +35,12 @@ if(CYGWIN OR MSYS)
33endif() 35endif()
34 36
35if(WIN32) 37if(WIN32)
36 add_definitions(-DWIN32_LEAN_AND_MEAN) 38 add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600)
37endif() 39endif()
38 40
39if(APPLE) 41if(APPLE)
40 set(CMAKE_INSTALL_NAME_DIR 42 set(CMAKE_INSTALL_NAME_DIR
41 "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") 43 "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
42endif()
43
44# Observe OpenBSD's library versioning scheme.
45if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
46 set(LIB_VERSION ${FIDO_MAJOR}.${FIDO_MINOR})
47 set(LIB_SOVERSION ${LIB_VERSION})
48else()
49 set(LIB_VERSION ${FIDO_VERSION})
50 set(LIB_SOVERSION ${FIDO_MAJOR})
51endif() 44endif()
52 45
53if(MSVC) 46if(MSVC)
@@ -58,7 +51,7 @@ if(MSVC)
58 "under msvc") 51 "under msvc")
59 endif() 52 endif()
60 set(CBOR_LIBRARIES cbor) 53 set(CBOR_LIBRARIES cbor)
61 set(CRYPTO_LIBRARIES crypto-45) 54 set(CRYPTO_LIBRARIES crypto-46)
62 set(MSVC_DISABLED_WARNINGS_LIST 55 set(MSVC_DISABLED_WARNINGS_LIST
63 "C4200" # nonstandard extension used: zero-sized array in 56 "C4200" # nonstandard extension used: zero-sized array in
64 # struct/union; 57 # struct/union;
@@ -71,9 +64,9 @@ if(MSVC)
71 # The construction in the following 3 lines was taken from LibreSSL's 64 # The construction in the following 3 lines was taken from LibreSSL's
72 # CMakeLists.txt. 65 # CMakeLists.txt.
73 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR 66 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
74 ${MSVC_DISABLED_WARNINGS_LIST}) 67 ${MSVC_DISABLED_WARNINGS_LIST})
75 string(REGEX REPLACE "[/-]W[1234][ ]?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) 68 string(REGEX REPLACE "[/-]W[1234][ ]?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
76 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 ${MSVC_DISABLED_WARNINGS_STR}") 69 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MP -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}")
77 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7") 70 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7")
78 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi") 71 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
79else() 72else()
@@ -102,13 +95,18 @@ else()
102 if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 95 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
103 pkg_search_module(UDEV libudev REQUIRED) 96 pkg_search_module(UDEV libudev REQUIRED)
104 set(UDEV_NAME "udev") 97 set(UDEV_NAME "udev")
98 include_directories(${UDEV_INCLUDE_DIRS})
99 link_directories(${UDEV_LIBRARY_DIRS})
105 # Define be32toh(). 100 # Define be32toh().
106 add_definitions(-D_GNU_SOURCE) 101 add_definitions(-D_GNU_SOURCE)
107 # If using hidapi, use hidapi-hidraw. 102 # If using hidapi, use hidapi-hidraw.
108 set(HIDAPI_SUFFIX -hidraw) 103 set(HIDAPI_SUFFIX -hidraw)
109 elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR 104 # Look for clock_gettime in librt.
110 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") 105 check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
111 set(BASE_LIBRARIES usbhid) 106 if(HAVE_CLOCK_GETTIME)
107 set(BASE_LIBRARIES ${BASE_LIBRARIES} rt)
108 add_definitions(-DHAVE_CLOCK_GETTIME)
109 endif()
112 endif() 110 endif()
113 111
114 if(MINGW) 112 if(MINGW)
@@ -122,6 +120,8 @@ else()
122 add_definitions(-DUSE_HIDAPI) 120 add_definitions(-DUSE_HIDAPI)
123 pkg_search_module(HIDAPI hidapi${HIDAPI_SUFFIX} REQUIRED) 121 pkg_search_module(HIDAPI hidapi${HIDAPI_SUFFIX} REQUIRED)
124 if(HIDAPI_FOUND) 122 if(HIDAPI_FOUND)
123 include_directories(${HIDAPI_INCLUDE_DIRS})
124 link_directories(${HIDAPI_LIBRARY_DIRS})
125 set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX}) 125 set(HIDAPI_LIBRARIES hidapi${HIDAPI_SUFFIX})
126 endif() 126 endif()
127 endif() 127 endif()
@@ -153,24 +153,6 @@ else()
153 endif() 153 endif()
154 add_definitions(-DFIDO_FUZZ) 154 add_definitions(-DFIDO_FUZZ)
155 endif() 155 endif()
156
157 if(ASAN)
158 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,leak")
159 endif()
160
161 if(MSAN)
162 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory")
163 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins")
164 endif()
165
166 if(UBSAN)
167 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
168 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-trap=undefined")
169 endif()
170
171 if(COVERAGE)
172 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
173 endif()
174endif() 156endif()
175 157
176# Use -Wshorten-64-to-32 if available. 158# Use -Wshorten-64-to-32 if available.
@@ -333,6 +315,20 @@ if(UNIX)
333 add_definitions(-DHAVE_DEV_URANDOM) 315 add_definitions(-DHAVE_DEV_URANDOM)
334endif() 316endif()
335 317
318# clock_gettime
319if(NOT HAVE_CLOCK_GETTIME)
320 check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
321 if(HAVE_CLOCK_GETTIME)
322 add_definitions(-DHAVE_CLOCK_GETTIME)
323 endif()
324endif()
325
326# timespecsub
327check_symbol_exists(timespecsub sys/time.h HAVE_TIMESPECSUB)
328if(HAVE_TIMESPECSUB)
329 add_definitions(-DHAVE_TIMESPECSUB)
330endif()
331
336# export list 332# export list
337if(APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 333if(APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
338 CMAKE_C_COMPILER_ID STREQUAL "AppleClang")) 334 CMAKE_C_COMPILER_ID STREQUAL "AppleClang"))
@@ -366,7 +362,7 @@ elseif(NOT MSVC)
366 endif() 362 endif()
367else() 363else()
368 string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} 364 string(CONCAT CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}
369 " /def:\"${CMAKE_CURRENT_SOURCE_DIR}/src/export.msvc\"") 365 " /def:\"${CMAKE_CURRENT_SOURCE_DIR}/src/export.msvc\"")
370endif() 366endif()
371 367
372include_directories(${CMAKE_SOURCE_DIR}/src) 368include_directories(${CMAKE_SOURCE_DIR}/src)
@@ -376,38 +372,33 @@ include_directories(${CRYPTO_INCLUDE_DIRS})
376link_directories(${CBOR_LIBRARY_DIRS}) 372link_directories(${CBOR_LIBRARY_DIRS})
377link_directories(${CRYPTO_LIBRARY_DIRS}) 373link_directories(${CRYPTO_LIBRARY_DIRS})
378 374
375message(STATUS "BASE_LIBRARIES: ${BASE_LIBRARIES}")
376message(STATUS "CBOR_INCLUDE_DIRS: ${CBOR_INCLUDE_DIRS}")
377message(STATUS "CBOR_LIBRARIES: ${CBOR_LIBRARIES}")
378message(STATUS "CBOR_LIBRARY_DIRS: ${CBOR_LIBRARY_DIRS}")
379message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
379message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") 380message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
380message(STATUS "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}") 381message(STATUS "CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
381message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
382message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}") 382message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}")
383message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 383message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
384message(STATUS "CBOR_INCLUDE_DIRS: ${CBOR_INCLUDE_DIRS}")
385message(STATUS "CBOR_LIBRARY_DIRS: ${CBOR_LIBRARY_DIRS}")
386message(STATUS "CBOR_LIBRARIES: ${CBOR_LIBRARIES}")
387message(STATUS "CRYPTO_INCLUDE_DIRS: ${CRYPTO_INCLUDE_DIRS}") 384message(STATUS "CRYPTO_INCLUDE_DIRS: ${CRYPTO_INCLUDE_DIRS}")
388message(STATUS "CRYPTO_LIBRARY_DIRS: ${CRYPTO_LIBRARY_DIRS}")
389message(STATUS "CRYPTO_LIBRARIES: ${CRYPTO_LIBRARIES}") 385message(STATUS "CRYPTO_LIBRARIES: ${CRYPTO_LIBRARIES}")
390message(STATUS "BASE_LIBRARIES: ${BASE_LIBRARIES}") 386message(STATUS "CRYPTO_LIBRARY_DIRS: ${CRYPTO_LIBRARY_DIRS}")
391message(STATUS "HIDAPI_LIBRARIES: ${HIDAPI_LIBRARIES}") 387message(STATUS "FIDO_VERSION: ${FIDO_VERSION}")
392message(STATUS "VERSION: ${FIDO_VERSION}")
393message(STATUS "LIB_VERSION: ${LIB_VERSION}")
394message(STATUS "LIB_SOVERSION: ${LIB_SOVERSION}")
395message(STATUS "FUZZ: ${FUZZ}") 388message(STATUS "FUZZ: ${FUZZ}")
396message(STATUS "AFL: ${AFL}") 389if(USE_HIDAPI)
390 message(STATUS "HIDAPI_INCLUDE_DIRS: ${HIDAPI_INCLUDE_DIRS}")
391 message(STATUS "HIDAPI_LIBRARIES: ${HIDAPI_LIBRARIES}")
392 message(STATUS "HIDAPI_LIBRARY_DIRS: ${HIDAPI_LIBRARY_DIRS}")
393endif()
397message(STATUS "LIBFUZZER: ${LIBFUZZER}") 394message(STATUS "LIBFUZZER: ${LIBFUZZER}")
398message(STATUS "ASAN: ${ASAN}")
399message(STATUS "MSAN: ${MSAN}")
400message(STATUS "COVERAGE: ${COVERAGE}")
401message(STATUS "TLS: ${TLS}") 395message(STATUS "TLS: ${TLS}")
396message(STATUS "UDEV_INCLUDE_DIRS: ${UDEV_INCLUDE_DIRS}")
397message(STATUS "UDEV_LIBRARIES: ${UDEV_LIBRARIES}")
398message(STATUS "UDEV_LIBRARY_DIRS: ${UDEV_LIBRARY_DIRS}")
399message(STATUS "UDEV_RULES_DIR: ${UDEV_RULES_DIR}")
402message(STATUS "USE_HIDAPI: ${USE_HIDAPI}") 400message(STATUS "USE_HIDAPI: ${USE_HIDAPI}")
403 401
404if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
405 message(STATUS "UDEV_INCLUDE_DIRS: ${UDEV_INCLUDE_DIRS}")
406 message(STATUS "UDEV_LIBRARY_DIRS: ${UDEV_LIBRARY_DIRS}")
407 message(STATUS "UDEV_LIBRARIES: ${UDEV_LIBRARIES}")
408 message(STATUS "UDEV_RULES_DIR: ${UDEV_RULES_DIR}")
409endif()
410
411subdirs(src) 402subdirs(src)
412subdirs(examples) 403subdirs(examples)
413subdirs(tools) 404subdirs(tools)
@@ -415,7 +406,7 @@ subdirs(man)
415 406
416if(NOT WIN32) 407if(NOT WIN32)
417 if(CMAKE_BUILD_TYPE STREQUAL "Debug") 408 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
418 if(NOT MSAN AND NOT LIBFUZZER) 409 if(NOT LIBFUZZER AND NOT FUZZ)
419 subdirs(regress) 410 subdirs(regress)
420 endif() 411 endif()
421 endif() 412 endif()