blob: 814c5f9aac41da010b724de31cf008bff09b666a [file] [log] [blame]
Michal Vaskoe7402142021-05-26 13:45:43 +02001# generate API/ABI report
2macro(LIB_ABI_CHECK LIB_TARGET LIB_HEADERS LIB_SOVERSION_FULL ABI_BASE_HASH)
3 # get short hash
4 string(SUBSTRING "${ABI_BASE_HASH}" 0 8 ABI_BASE_HASH_SHORT)
5
6 # find abi-dumper
7 find_program(ABI_DUMPER abi-dumper)
8 find_package_handle_standard_args(abi-dumper DEFAULT_MSG ABI_DUMPER)
9 if(NOT ABI_DUMPER)
10 message(FATAL_ERROR "Program abi-dumper not found!")
11 endif()
12
13 # find abi-checker
14 find_program(ABI_CHECKER abi-compliance-checker)
15 find_package_handle_standard_args(abi-compliance-checker DEFAULT_MSG ABI_CHECKER)
16 if(NOT ABI_CHECKER)
17 message(FATAL_ERROR "Program abi-compliance-checker not found!")
18 endif()
19
20 # abi-dump target - generating an ABI dump
21 set(PUBLIC_HEADERS ${LIB_HEADERS})
22 string(PREPEND PUBLIC_HEADERS "${CMAKE_SOURCE_DIR}/")
23 string(REPLACE ";" "\n${CMAKE_SOURCE_DIR}/" PUBLIC_HEADERS "${PUBLIC_HEADERS}")
24 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/public_headers CONTENT "${PUBLIC_HEADERS}")
25 add_custom_target(abi-dump
26 COMMAND ${ABI_DUMPER} ./lib${LIB_TARGET}${CMAKE_SHARED_LIBRARY_SUFFIX}
27 -o lib${LIB_TARGET}.${LIB_SOVERSION_FULL}.dump
28 -lver ${LIB_SOVERSION_FULL} -public-headers ${CMAKE_BINARY_DIR}/public_headers
29 DEPENDS ${LIB_TARGET}
30 BYPRODUCTS ${CMAKE_BINARY_DIR}/lib${LIB_TARGET}.${LIB_SOVERSION_FULL}.dump
31 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
32 COMMENT "Dumping ABI information of version ${LIB_SOVERSION_FULL} for abi-check")
33
34 # get URL for fetching origin
35 execute_process(COMMAND git remote get-url origin OUTPUT_VARIABLE ORIGIN_URL OUTPUT_STRIP_TRAILING_WHITESPACE)
36
37 # generate script for generating the base ABI dump
38 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/abibase.sh CONTENT "#!/bin/sh
39if [ ! -d abibase ]; then mkdir abibase; fi
40cd abibase
41if [ ! -f build/lib${LIB_TARGET}.*.dump ]; then
42 if [ -d .git ] && [ \"${ABI_BASE_HASH}\" != \"`git log --pretty=oneline | cut -d' ' -f1`\" ]; then rm -rf .* 2> /dev/null; fi
43 if [ ! -d .git ]; then
44 git init --initial-branch=master
45 git remote add origin ${ORIGIN_URL}
46 git fetch origin --depth 1 ${ABI_BASE_HASH}
47 git reset --hard FETCH_HEAD
48 fi
49 if [ ! -d build ]; then mkdir build; fi
50 cd build
51 cmake -DCMAKE_BUILD_TYPE=ABICheck ..
52 make abi-dump
53fi
54")
55
56 # abi-check target - check ABI compatibility of current version and the base hash version
57 add_custom_target(abi-check
58 COMMAND bash ./abibase.sh
59 COMMAND ${ABI_CHECKER} -l lib${LIB_TARGET}${CMAKE_SHARED_LIBRARY_SUFFIX}
60 -old abibase/build/lib${LIB_TARGET}.*.dump
61 -new ./lib${LIB_TARGET}.${LIB_SOVERSION_FULL}.dump -s
62 DEPENDS ${LIB_TARGET} abi-dump
63 BYPRODUCTS ${CMAKE_BINARY_DIR}/compat_reports/lib${LIB_TARGET}${CMAKE_SHARED_LIBRARY_SUFFIX}/*_to_${LIB_SOVERSION_FULL}/compat_report.html
64 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
65 COMMENT "Checking ABI compatibility of version ${LIB_SOVERSION_FULL} and revision ${ABI_BASE_HASH_SHORT}")
66endmacro()