14
14
15
15
# No linker for Mach-O supports the linker argument `--wrap`. Since we use
16
16
# that, unit tests will never work on macos. Use linux/arm64 in docker instead.
17
- if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
18
- message ("No linker for Mach-O supports --wrap, will not generate unit-tests" )
19
- return ()
20
- endif ()
21
17
22
18
# We use FindPkgConfig instead of FindPackage because it finds libraries in
23
19
# both linux and macos
@@ -26,7 +22,11 @@ find_package(PkgConfig REQUIRED)
26
22
# Unit testing uses CMocka
27
23
pkg_check_modules (CMOCKA REQUIRED cmocka )
28
24
# u2f tests with hardware uses hidapi-hidraw
29
- pkg_check_modules (HIDAPI REQUIRED hidapi-hidraw )
25
+ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
26
+ pkg_check_modules (HIDAPI REQUIRED hidapi )
27
+ else ()
28
+ pkg_check_modules (HIDAPI REQUIRED hidapi-hidraw )
29
+ endif ()
30
30
31
31
#-----------------------------------------------------------------------------
32
32
# Build bitbox lib to use in tests
@@ -176,7 +176,7 @@ target_compile_definitions(bitbox PUBLIC TESTING _UNIT_TEST_)
176
176
target_link_libraries (bitbox
177
177
PUBLIC
178
178
secp256k1
179
- ${CMOCKA_LIBRARIES }
179
+ ${CMOCKA_LDFLAGS }
180
180
PRIVATE
181
181
wallycore
182
182
fatfs
@@ -219,7 +219,7 @@ target_include_directories(
219
219
target_compile_definitions (u2f-util PUBLIC "TESTING" _UNIT_TEST_ PRODUCT_BITBOX_MULTI "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1" )
220
220
target_compile_definitions (u2f-util PUBLIC "USE_KECCAK" )
221
221
222
- target_link_libraries (u2f-util PUBLIC ${HIDAPI_LIBRARIES } )
222
+ target_link_libraries (u2f-util PUBLIC ${HIDAPI_LDFLAGS } )
223
223
224
224
225
225
#-----------------------------------------------------------------------------
@@ -258,28 +258,32 @@ set(TEST_LIST
258
258
""
259
259
)
260
260
261
- list (LENGTH TEST_LIST TEST_LIST_LEN )
262
- math (EXPR TEST_LIST_LEN ${TEST_LIST_LEN} -1 )
263
- foreach (I RANGE 0 ${TEST_LIST_LEN} 2 )
264
- math (EXPR I2 ${I} +1 )
265
- list (GET TEST_LIST ${I} TEST_NAME )
266
- list (GET TEST_LIST ${I2} TEST_LINK_ARGS )
267
- set (EXE test_${TEST_NAME} )
268
- add_executable (${EXE} test_${TEST_NAME}.c framework /eh_personality.c )
269
- # asan must be first library in linking order
270
- target_link_libraries (${EXE} PRIVATE
271
- $< $< BOOL:${SANITIZE_ADDRESS} > :asan>
272
- $< $< BOOL:${SANITIZE_UNDEFINED} > :-fsanitize=undefined>
273
- -Wl,--start-group
274
- c-unit-tests_rust_c
275
- bitbox
276
- -Wl,--end-group
277
- ${TEST_LINK_ARGS}
278
- )
279
- if (NOT ${TEST_NAME} STREQUAL "simulator" )
280
- add_test (NAME test_${TEST_NAME} COMMAND ${EXE} )
281
- endif ()
282
- endforeach ()
261
+ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
262
+ message ("No linker for Mach-O supports --wrap, will not generate unit-tests" )
263
+ else ()
264
+ list (LENGTH TEST_LIST TEST_LIST_LEN )
265
+ math (EXPR TEST_LIST_LEN ${TEST_LIST_LEN} -1 )
266
+ foreach (I RANGE 0 ${TEST_LIST_LEN} 2 )
267
+ math (EXPR I2 ${I} +1 )
268
+ list (GET TEST_LIST ${I} TEST_NAME )
269
+ list (GET TEST_LIST ${I2} TEST_LINK_ARGS )
270
+ set (EXE test_${TEST_NAME} )
271
+ add_executable (${EXE} test_${TEST_NAME}.c framework /eh_personality.c )
272
+ # asan must be first library in linking order
273
+ target_link_libraries (${EXE} PRIVATE
274
+ $< $< BOOL:${SANITIZE_ADDRESS} > :asan>
275
+ $< $< BOOL:${SANITIZE_UNDEFINED} > :-fsanitize=undefined>
276
+ -Wl,--start-group
277
+ c-unit-tests_rust_c
278
+ bitbox
279
+ -Wl,--end-group
280
+ ${TEST_LINK_ARGS}
281
+ )
282
+ if (NOT ${TEST_NAME} STREQUAL "simulator" )
283
+ add_test (NAME test_${TEST_NAME} COMMAND ${EXE} )
284
+ endif ()
285
+ endforeach ()
286
+ endif ()
283
287
284
288
285
289
# These unit tests for U2F are special because they don't call any bitbox functions directly, instead they go through hid_read/write.
@@ -297,10 +301,10 @@ foreach(TEST_NAME ${U2F_TESTS})
297
301
target_link_libraries (${EXE} PRIVATE
298
302
$< $< BOOL:${SANITIZE_ADDRESS} > :asan>
299
303
$< $< BOOL:${SANITIZE_UNDEFINED} > :-fsanitize=undefined>
300
- -Wl,--start-group
304
+ $< $< NOT: $< PLATFORM_ID:Darwin > > : -Wl,--start-group>
301
305
c-unit-tests_rust_c
302
306
bitbox
303
- -Wl,--end-group
307
+ $< $< NOT: $< PLATFORM_ID:Darwin > > : -Wl,--end-group>
304
308
u2f-util
305
309
)
306
310
target_compile_definitions (${EXE} PRIVATE "TESTING" )
0 commit comments