blob: d1b0b4ba6a79f22dc16cfa667a6cdcb9d12577d6 [file] [log] [blame]
Radek Krejcib2258822020-07-14 08:39:30 +02001# generate API/ABI report
Michal Vasko62c84ed2021-05-25 07:51:23 +02002macro(LIB_ABI_CHECK LIB_TARGET 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
Radek Krejcif54e7bc2020-08-16 10:30:47 +02007 find_program(ABI_DUMPER abi-dumper)
8 find_package_handle_standard_args(abi-dumper DEFAULT_MSG ABI_DUMPER)
Michal Vasko62c84ed2021-05-25 07:51:23 +02009 if(NOT ABI_DUMPER)
10 message(FATAL_ERROR "Program abi-dumper not found!")
Radek Krejcif54e7bc2020-08-16 10:30:47 +020011 endif()
12
Michal Vasko62c84ed2021-05-25 07:51:23 +020013 # find abi-checker
Radek Krejcif54e7bc2020-08-16 10:30:47 +020014 find_program(ABI_CHECKER abi-compliance-checker)
15 find_package_handle_standard_args(abi-compliance-checker DEFAULT_MSG ABI_CHECKER)
Michal Vasko62c84ed2021-05-25 07:51:23 +020016 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 ${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
Radek Krejcib2258822020-07-14 08:39:30 +020039if [ ! -d abibase ]; then mkdir abibase; fi
40cd abibase
Michal Vasko62c84ed2021-05-25 07:51:23 +020041if [ ! -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
Radek Krejcib2258822020-07-14 08:39:30 +020043 if [ ! -d .git ]; then
Michal Vasko62c84ed2021-05-25 07:51:23 +020044 git init --initial-branch=master
45 git remote add origin ${ORIGIN_URL}
46 git fetch origin --depth 1 ${ABI_BASE_HASH}
Radek Krejcib2258822020-07-14 08:39:30 +020047 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")
Michal Vasko62c84ed2021-05-25 07:51:23 +020055
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}")
Radek Krejcib2258822020-07-14 08:39:30 +020066endmacro()