xref: /freebsd/contrib/libfido2/src/CMakeLists.txt (revision b07549f3c15637af6064d2f52b572f239f5ba870)
1# Copyright (c) 2018-2021 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	rs1.c
34	rs256.c
35	time.c
36	tpm.c
37	types.c
38	u2f.c
39)
40
41if(FUZZ)
42	list(APPEND FIDO_SOURCES ../fuzz/clock.c)
43	list(APPEND FIDO_SOURCES ../fuzz/prng.c)
44	list(APPEND FIDO_SOURCES ../fuzz/uniform_random.c)
45	list(APPEND FIDO_SOURCES ../fuzz/udev.c)
46	list(APPEND FIDO_SOURCES ../fuzz/wrap.c)
47endif()
48if(NFC_LINUX)
49	list(APPEND FIDO_SOURCES netlink.c nfc_linux.c)
50endif()
51
52if(USE_HIDAPI)
53	list(APPEND FIDO_SOURCES hid_hidapi.c)
54	if(NOT WIN32 AND NOT APPLE)
55		list(APPEND FIDO_SOURCES hid_unix.c)
56	endif()
57elseif(WIN32)
58	list(APPEND FIDO_SOURCES hid_win.c)
59	if(USE_WINHELLO)
60		list(APPEND FIDO_SOURCES winhello.c)
61	endif()
62elseif(APPLE)
63	list(APPEND FIDO_SOURCES hid_osx.c)
64elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
65	list(APPEND FIDO_SOURCES hid_linux.c hid_unix.c)
66elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
67	list(APPEND FIDO_SOURCES hid_netbsd.c hid_unix.c)
68elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
69	list(APPEND FIDO_SOURCES hid_openbsd.c hid_unix.c)
70elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
71    CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD")
72	list(APPEND FIDO_SOURCES hid_freebsd.c hid_unix.c)
73else()
74	message(FATAL_ERROR "please define a hid backend for your platform")
75endif()
76
77if(NOT MSVC)
78	set_source_files_properties(${FIDO_SOURCES} PROPERTIES COMPILE_FLAGS
79	    "-Wconversion -Wsign-conversion")
80endif()
81
82list(APPEND COMPAT_SOURCES
83	../openbsd-compat/bsd-getpagesize.c
84	../openbsd-compat/clock_gettime.c
85	../openbsd-compat/endian_win32.c
86	../openbsd-compat/explicit_bzero.c
87	../openbsd-compat/explicit_bzero_win32.c
88	../openbsd-compat/freezero.c
89	../openbsd-compat/recallocarray.c
90	../openbsd-compat/strlcat.c
91	../openbsd-compat/timingsafe_bcmp.c
92)
93
94if(WIN32)
95	list(APPEND BASE_LIBRARIES wsock32 ws2_32 bcrypt setupapi hid)
96elseif(APPLE)
97	list(APPEND BASE_LIBRARIES "-framework CoreFoundation" "-framework IOKit")
98endif()
99
100list(APPEND TARGET_LIBRARIES
101	${CBOR_LIBRARIES}
102	${CRYPTO_LIBRARIES}
103	${UDEV_LIBRARIES}
104	${BASE_LIBRARIES}
105	${HIDAPI_LIBRARIES}
106	${ZLIB_LIBRARIES}
107)
108
109# static library
110if(BUILD_STATIC_LIBS)
111	add_library(fido2 STATIC ${FIDO_SOURCES} ${COMPAT_SOURCES})
112	if(WIN32 AND NOT MINGW)
113		set_target_properties(fido2 PROPERTIES OUTPUT_NAME fido2_static)
114	endif()
115	target_link_libraries(fido2 ${TARGET_LIBRARIES})
116	install(TARGETS fido2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
117		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
118endif()
119
120# dynamic library
121if(BUILD_SHARED_LIBS)
122	add_library(fido2_shared SHARED ${FIDO_SOURCES} ${COMPAT_SOURCES})
123	set_target_properties(fido2_shared PROPERTIES OUTPUT_NAME fido2
124		VERSION ${FIDO_VERSION} SOVERSION ${FIDO_MAJOR})
125	target_link_libraries(fido2_shared ${TARGET_LIBRARIES})
126	install(TARGETS fido2_shared
127		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
128		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
129		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
130endif()
131
132install(FILES fido.h DESTINATION include)
133install(DIRECTORY fido DESTINATION include)
134
135if(NOT MSVC)
136	configure_file(libfido2.pc.in libfido2.pc @ONLY)
137	install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfido2.pc"
138		DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
139endif()
140