Skip to content

[CMake] find_package(LLVM CONFIG) may fail when the project does not use C #53950

Closed
@lzaoral

Description

@lzaoral
  1. Build LLVM 14 rc1 with LLVM_ENABLE_FFI and LLVM_ENABLE_TERMINFO options enabled.
  2. Create a C++ only CMake project :
cmake_minimum_required(VERSION 3.16)  # just to silence the warning when this line is missing
project(test LANGUAGES CXX)
find_package(LLVM CONFIG REQUIRED)
  1. Configure this project:
$ cmake -Bbuild . -DLLVM_DIR=/root/llvm-project-14.0.0rc1.src/llvm/build/lib/cmake/llvm/
-- The CXX compiler identification is GNU 12.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /root/llvm-project-14.0.0rc1.src/llvm/build/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /root/llvm-project-14.0.0rc1.src/llvm/build/lib/cmake/llvm/LLVMConfig.cmake:145 (find_package)
  CMakeLists.txt:3 (find_package)


-- Could NOT find FFI (missing: HAVE_FFI_CALL)
CMake Error at /usr/share/cmake/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/share/cmake/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /root/llvm-project-14.0.0rc1.src/llvm/build/lib/cmake/llvm/FindTerminfo.cmake:21 (check_c_source_compiles)
  /root/llvm-project-14.0.0rc1.src/llvm/build/lib/cmake/llvm/LLVMConfig.cmake:152 (find_package)
  CMakeLists.txt:3 (find_package)


-- Could NOT find Terminfo (missing: Terminfo_LINKABLE)
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.11")
-- Found LibXml2: /usr/lib64/libxml2.so (found version "2.9.12")
-- Configuring incomplete, errors occurred!
See also "/root/test/build/CMakeFiles/CMakeOutput.log".

Changing the project(test LANGUAGES CXX) line to project(test LANGUAGES C CXX) makes the error go away, but that's just a work-around than a solution.

CMake version: 3.22.2
Introduced by: https://reviews.llvm.org/D114327

Metadata

Metadata

Assignees

No one assigned

    Labels

    cmakeBuild system in general and CMake in particular

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions