Description
When building LLVM without terminfo support by passing -DLLVM_ENABLE_TERMINFO=OFF
to CMake, the llvm-config
executable fails to link because the CMakeLists.txt for llvm-config
does not check LLVM_ENABLE_TERMINFO
, but passes -ltinfo
in the link arguments regardless of whether or not the option is set. Build output looks as follows:
[1/1] Linking CXX executable bin/llvm-config
FAILED: bin/llvm-config
: && /usr/sbin/aarch64-linux-gnu-g++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-rpath-link,/home/user/llvm-target-build/NATIVE/./lib -Wl,-O3 -Wl,--gc-sections tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o -o bin/llvm-config -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMSupport.a -lpthread -lrt -ldl -lpthread -lm -ltinfo lib/libLLVMDemangle.a && :
/usr/lib/gcc/aarch64-linux-gnu/10.2.0/../../../../aarch64-linux-gnu/bin/ld: cannot find -ltinfo
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Expected behaviour is the same as all the other parts of the system that respect LLVM_ENABLE_TERMINFO
, i.e. that -ltinfo
should not be passed as a link flag in the linking command. What is actually happening is that in the CMakeLists.txt for llvm-config
the link line is assembled by adding in all the libraries from LLVM_SYSTEM_LIBS
. However, if LLVM_ENABLE_TERMINFO
is false, -ltinfo
should be removed from the linked libraries.
This problem crops up whenever LLVM is being cross-compiled and a target version of libtinfo is not available. Without a fix, LLVM cannot be cross-compiled without first cross-compiling ncurses for the target platform and providing a custom linking environment for the build, which seems like exactly the problem LLVM_ENABLE_TERMINFO
exists to prevent.