summaryrefslogtreecommitdiff
path: root/src/CMakeLists.txt
blob: 926e7f256a2036754be4bf8546a9ca41c68a1ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) 2018 Yubico AB. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

add_definitions(-D_FIDO_INTERNAL)

list(APPEND FIDO_SOURCES
	aes256.c
	assert.c
	authkey.c
	bio.c
	blob.c
	buf.c
	cbor.c
	cred.c
	credman.c
	dev.c
	ecdh.c
	eddsa.c
	err.c
	es256.c
	hid.c
	info.c
	io.c
	iso7816.c
	log.c
	pin.c
	reset.c
	rs256.c
	u2f.c
)

if(FUZZ)
	list(APPEND FIDO_SOURCES ../fuzz/uniform_random.c)
	list(APPEND FIDO_SOURCES ../fuzz/wrap.c)
endif()

if(WIN32)
	list(APPEND COMPAT_SOURCES hid_win.c)
elseif(APPLE)
	list(APPEND COMPAT_SOURCES hid_osx.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	list(APPEND COMPAT_SOURCES hid_linux.c)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
	list(APPEND COMPAT_SOURCES hid_openbsd.c)
endif()

list(APPEND COMPAT_SOURCES
	../openbsd-compat/bsd-getpagesize.c
	../openbsd-compat/explicit_bzero.c
	../openbsd-compat/explicit_bzero_win32.c
	../openbsd-compat/recallocarray.c
	../openbsd-compat/timingsafe_bcmp.c
)

# static library
add_library(fido2 STATIC ${FIDO_SOURCES} ${COMPAT_SOURCES})
target_link_libraries(fido2 ${CBOR_LIBRARIES} ${CRYPTO_LIBRARIES}
	${UDEV_LIBRARIES} ${BASE_LIBRARIES})
if(WIN32)
	if (MINGW)
		target_link_libraries(fido2 wsock32 ws2_32 bcrypt setupapi hid)
	else()
		target_link_libraries(fido2 wsock32 ws2_32 bcrypt SetupAPI hid)
		set_target_properties(fido2 PROPERTIES OUTPUT_NAME fido2_static)
	endif()
elseif(APPLE)
	target_link_libraries(fido2 "-framework CoreFoundation"
		"-framework IOKit")
endif()
install(TARGETS fido2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

# dynamic library
add_library(fido2_shared SHARED ${FIDO_SOURCES} ${COMPAT_SOURCES})
target_link_libraries(fido2_shared ${CBOR_LIBRARIES} ${CRYPTO_LIBRARIES}
	${UDEV_LIBRARIES} ${BASE_LIBRARIES})
if(WIN32)
	if (MINGW)
		target_link_libraries(fido2_shared wsock32 ws2_32 bcrypt
			setupapi hid)
	else()
		target_link_libraries(fido2_shared wsock32 ws2_32 bcrypt
			SetupAPI hid)
	endif()
elseif(APPLE)
	target_link_libraries(fido2_shared "-framework CoreFoundation"
		"-framework IOKit")
endif()
set_target_properties(fido2_shared PROPERTIES OUTPUT_NAME fido2
	VERSION ${LIB_VERSION} SOVERSION ${LIB_SOVERSION})
install(TARGETS fido2_shared
	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
	RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES fido.h DESTINATION include)
install(DIRECTORY fido DESTINATION include)

if(NOT WIN32)
	configure_file(libfido2.pc.in libfido2.pc @ONLY)
	install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfido2.pc"
		DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()