blob: bd46415939514eecc66228f4a23b6c726ae523ef [file] [log] [blame]
Radek Krejcib2258822020-07-14 08:39:30 +02001cmake_minimum_required(VERSION 2.8.12)
2
3# generate API/ABI report
4macro(LIBYANG_ABICHECK)
5 find_program(ABI_DUMPER abi-dumper)
6 find_package_handle_standard_args(abi-dumper DEFAULT_MSG ABI_DUMPER)
7 if(ABI_DUMPER)
8 set(PUBLIC_HEADERS ${headers})
9 string(PREPEND PUBLIC_HEADERS "${CMAKE_SOURCE_DIR}/")
10 string(REPLACE ";" "\n${CMAKE_SOURCE_DIR}/" PUBLIC_HEADERS "${PUBLIC_HEADERS}")
11 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/public_headers CONTENT "${PUBLIC_HEADERS}")
12 add_custom_target(abi-dump
13 COMMAND ${ABI_DUMPER} ./libyang${CMAKE_SHARED_LIBRARY_SUFFIX} -o libyang.${LIBYANG_SOVERSION_FULL}.dump
14 -lver ${LIBYANG_SOVERSION_FULL} -public-headers ${CMAKE_BINARY_DIR}/public_headers
15 DEPENDS yang
16 BYPRODUCTS ${CMAKE_BINARY_DIR}/libyang.${LIBYANG_SOVERSION_FULL}.dump
17 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
18 COMMENT Dumping ABI information for abi-check.)
19 endif()
20
21 # check correctness of the SO version according to the API/ABI changes
22 find_program(ABI_CHECKER abi-compliance-checker)
23 find_package_handle_standard_args(abi-compliance-checker DEFAULT_MSG ABI_CHECKER)
24 if(ABI_DUMPER AND ABI_CHECKER)
25 set(ABIBASE_HASH "" CACHE STRING "GIT hash for the commit to compare current ABI to. If not set, base SO version commit is found.")
26 if (NOT ABIBASE_HASH)
27 # check that we have some ABI base version already and get its hash in GIT
28 set(ABIBASE_VERSION "${LIBYANG_MAJOR_VERSION}.0.0")
29 execute_process(COMMAND bash "-c" "git log --pretty=oneline --grep=\"SOVERSION .* ${ABIBASE_VERSION}\$\" | cut -d' ' -f1"
30 OUTPUT_VARIABLE ABIBASE_HASH)
31 else()
32 string(SUBSTRING ${ABIBASE_HASH} 0 8 ABIBASE_HASH_SHORT)
33 set(ABIBASE_VERSION "git-${ABIBASE_HASH_SHORT}")
34 endif()
35 if(ABIBASE_HASH)
36 # we have the ABI base version, so generate script for abi-check target
37 string(REPLACE "\n" "" ABIBASE_HASH ${ABIBASE_HASH})
38 file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/abibase.sh CONTENT "#!/bin/sh
39if [ ! -d abibase ]; then mkdir abibase; fi
40cd abibase
41if [ ! -f build/libyang.*.dump ]; then
42 if [ -d .git ] && [ \"${ABIBASE_HASH}\" != \"`git log --pretty=oneline | cut -d' ' -f1`\" ]; then rm -rf .* 2> /dev/null; fi
43 if [ ! -d .git ]; then
44 git init
45 git remote add origin https://github.com/CESNET/libyang
46 git fetch origin --depth 1 ${ABIBASE_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 # abi-check target itself using abi-compliance-checker
56 add_custom_target(abi-check
57 COMMAND bash ./abibase.sh
58 COMMAND ${ABI_CHECKER} -l libyang${CMAKE_SHARED_LIBRARY_SUFFIX} -old abibase/build/libyang.*.dump
59 -new ./libyang.${LIBYANG_SOVERSION_FULL}.dump -s
60 DEPENDS yang abi-dump
61 BYPRODUCTS ${CMAKE_BINARY_DIR}/compat_reports/libyang${CMAKE_SHARED_LIBRARY_SUFFIX}/*_to_${LIBYANG_SOVERSION_FULL}/compat_report.html
62 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
63 COMMENT Checking ABI compatibility with the ${ABIBASE_VERSION} version.)
64 else()
65 add_custom_target(abi-check
66 COMMENT Nothing to check - missing base SOVERSION commit for ${ABIBASE_VERSION} version.)
67 endif()
68 endif()
69endmacro()