Page MenuHomePhabricator

[CMAKE] Fix version mismatch during crosscompilation due to pkg-config
ClosedPublic

Authored by Fabien on Oct 1 2020, 16:53.

Details

Summary

The pkg config file is used for some cmake modules to help finding the
libraries. This is used as a last resort for searching paths to headers
and libraries, but it is also used to determine the version for some
libraries where there is no better way.
This can cause a mismatch if the library is found without the need for
pkg-config, but pkg-config also found the library as the version can be
used in place of the one from the found library. During a cross
compilation this can cause a mismatch between the library found from the
depends and the version reported by pkg-config, from the host.
This diff adds a check so that the pkg-config version is only used when
the library path match the pkg-config path to prevent any mismatch.

Test Plan

On Ubuntu Xenial:

cmake -GNinja .. -DCMAKE_TOOLCHAIN_FILE=../cmake/platforms/Linux64.cmake
ninja

Check that libevent is found. The version will be 99.99.99 because there
is no way to determine the correct event version during
crosscompilation. Before this patch cmake reported an error due to an
insufficient libevent version 2.0.21 (the system version).

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fabien requested review of this revision.Oct 1 2020, 16:53

Snippet of first build failure:

[319/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/str.cpp.o
[320/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/logging.cpp.o
[321/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/transaction_utils.cpp.o
[322/482] Building CXX object src/CMakeFiles/bitcoin-cli.dir/bitcoin-cli.cpp.o
[323/482] Building CXX object src/CMakeFiles/bitcoin-wallet.dir/bitcoin-wallet.cpp.o
[324/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/blockfilter.cpp.o
[325/482] Building C object src/secp256k1/CMakeFiles/internal-bench.dir/src/bench_internal.c.o
[326/482] Linking C executable src/secp256k1/internal-bench
[327/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/mining.cpp.o
[328/482] Building CXX object src/CMakeFiles/script.dir/script/signingprovider.cpp.o
[329/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/db.cpp.o
FAILED: src/wallet/CMakeFiles/wallet.dir/db.cpp.o 
/usr/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache --tidy="/usr/bin/clang-tidy-8;-warnings-as-errors=*" --source=../../src/wallet/db.cpp -- /usr/bin/clang++  -DBOOST_AC_USE_STD_ATOMIC -DBOOST_SP_USE_STD_ATOMIC -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -isystem /usr/include/jemalloc -g -O2 -fPIC -fvisibility=hidden   -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety-analysis -Wshadow -Wshadow-field -Wrange-loop-analysis -Wredundant-decls -Wformat-security -Wredundant-move -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++14 -MD -MT src/wallet/CMakeFiles/wallet.dir/db.cpp.o -MF src/wallet/CMakeFiles/wallet.dir/db.cpp.o.d -o src/wallet/CMakeFiles/wallet.dir/db.cpp.o -c ../../src/wallet/db.cpp
/work/abc-ci-builds/build-clang-tidy/../../src/wallet/db.cpp:869:30: error: statement should be inside braces [readability-braces-around-statements,-warnings-as-errors]
                if (!fMockDb) dbenv->lsn_reset(strFile.c_str(), 0);
                             ^
                              {
2458 warnings generated.
Suppressed 2457 warnings (2457 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
1 warning treated as error
[330/482] Building CXX object src/CMakeFiles/script.dir/script/descriptor.cpp.o
[331/482] Linking CXX static library src/libscript.a
[332/482] Linking CXX static library src/libcommon.a
[333/482] Linking CXX executable src/bitcoin-cli
[334/482] Linking CXX static library src/libbitcoinconsensus.a
[335/482] Linking CXX shared library src/libbitcoinconsensus.so.0.22.4
[336/482] Creating library symlink src/libbitcoinconsensus.so.0 src/libbitcoinconsensus.so
[337/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/coincontrol.cpp.o
[338/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/coinselection.cpp.o
[339/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/crypter.cpp.o
[340/482] Building CXX object src/CMakeFiles/bitcoin-tx.dir/bitcoin-tx.cpp.o
[341/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/wallet.cpp.o
[342/482] Linking CXX executable src/bitcoin-tx
[343/482] Building CXX object src/zmq/CMakeFiles/zmq.dir/zmqabstractnotifier.cpp.o
[344/482] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
[345/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/load.cpp.o
[346/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/fees.cpp.o
[347/482] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
[348/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/psbtwallet.cpp.o
[349/482] Building CXX object src/wallet/CMakeFiles/wallet-tool.dir/wallettool.cpp.o
[350/482] Building CXX object src/seeder/CMakeFiles/seeder.dir/dns.cpp.o
[351/482] Building CXX object src/seeder/CMakeFiles/seeder.dir/bitcoin.cpp.o
[352/482] Building CXX object src/seeder/CMakeFiles/seeder.dir/db.cpp.o
[353/482] Linking CXX static library src/seeder/libseeder.a
[354/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletutil.cpp.o
[355/482] Building CXX object src/zmq/CMakeFiles/zmq.dir/zmqnotificationinterface.cpp.o
[356/482] Building CXX object src/zmq/CMakeFiles/zmq.dir/zmqpublishnotifier.cpp.o
[357/482] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[358/482] Linking CXX executable src/seeder/bitcoin-seeder
[359/482] Building CXX object src/zmq/CMakeFiles/zmq.dir/zmqrpc.cpp.o
[360/482] Linking CXX static library src/zmq/libzmq.a
[361/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/__/interfaces/wallet.cpp.o
[362/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[363/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/scriptpubkeyman.cpp.o
[364/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcdump.cpp.o
[365/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
[366/482] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang-tidy failed with exit code 1
This revision is now accepted and ready to land.Oct 1 2020, 20:44