Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lzaoral opened this issue Feb 19, 2022 · 4 comments · Fixed by #68549
Closed

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

lzaoral opened this issue Feb 19, 2022 · 4 comments · Fixed by #68549
Labels
cmake Build system in general and CMake in particular

Comments

@lzaoral
Copy link
Contributor

lzaoral commented Feb 19, 2022

  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

@EugeneZelenko EugeneZelenko added cmake Build system in general and CMake in particular and removed new issue labels Feb 19, 2022
@lzaoral
Copy link
Contributor Author

lzaoral commented Mar 24, 2022

Ping.

@sjoubert
Copy link

sjoubert commented Apr 4, 2022

+1 For now this completely blocks me to update to LLVM 14 as I really don't want to enable the C language in my all C++ project.

I suppose a solution could be for the FindFFI and FindTerminfo modules to fallback to check_cxx_source_compiles if the C language is not enabled or something like that.

@lzaoral lzaoral changed the title [CMake] find_package(LLVM CONFIG) may fail then the project does not use C [CMake] find_package(LLVM CONFIG) may fail when the project does not use C Apr 8, 2022
lzaoral added a commit to lzaoral/dg that referenced this issue May 2, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
lzaoral added a commit to lzaoral/dg that referenced this issue May 2, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
lzaoral added a commit to lzaoral/symbiotic that referenced this issue May 3, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
lzaoral added a commit to lzaoral/symbiotic that referenced this issue May 16, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
lzaoral added a commit to lzaoral/dg that referenced this issue May 17, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
mchalupa pushed a commit to mchalupa/dg that referenced this issue May 18, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
lzaoral added a commit to lzaoral/ProStatA that referenced this issue Jun 15, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
versokova pushed a commit to VeriFIT/ProStatA that referenced this issue Jun 17, 2022
... due to a bug.

See: llvm/llvm-project#53950
Fixes:
CMake Error at /usr/local/share/cmake-3.22/Modules/Internal/CheckSourceCompiles.cmake:44 (message):
  check_source_compiles: C: needs to be enabled before use.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/FindFFI.cmake:44 (check_c_source_compiles)
  /usr/lib/llvm-14/lib/cmake/llvm/LLVMConfig.cmake:242 (find_package)
  CMakeLists.txt:31 (find_package)
richardmembarth added a commit to AnyDSL/runtime that referenced this issue Aug 11, 2022
kateinoigakukun added a commit to swiftwasm/swift-corelibs-xctest that referenced this issue Aug 20, 2022
bjodah added a commit to bjodah/symengine that referenced this issue Nov 27, 2022
@lzaoral
Copy link
Contributor Author

lzaoral commented Dec 12, 2022

Ping?

@ekilmer
Copy link
Contributor

ekilmer commented Oct 9, 2023

I've opened PR #68549, which should fix this issue.

I did some testing with the minimal example in the OP and a few other projects, and it seems okay.

If anyone wants to try modifying their local installation files and test their projects, please report back with any bugs, suggestions, or react with 👍 (if it works) on the PR page.

JDevlieghere pushed a commit that referenced this issue Oct 18, 2023
If a CMake project doesn't enable the C language, then the CMake FFI and
Terminfo find modules will fail their checks for compilation and
linking.

This commit allows projects to enable only C++ by first checking if a C
compiler is set before testing C source compilation; if not, it checks
whether C++ compilation succeeds.

Fixes #53950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants