Skip to content

[Bug]: [SOLUTION]: JUCEModuleSupport.cmake: CMAKE_C_COMPILE_OBJECT check at module scope fails with CMake 4.x even when C compiler is available #1668

Description

@0x07dc

Detailed steps on how to reproduce the bug

In JUCE/extras/Build/CMake/JUCEModuleSupport.cmake at line 47, there's a check:

if(NOT CMAKE_C_COMPILE_OBJECT)
message(FATAL_ERROR "A C compiler is required to build JUCE. Add 'C' to your project's LANGUAGES.")
endif()
This check runs at module scope when JUCEModuleSupport.cmake is included (via add_subdirectory(JUCE)). At that point, if the user's CMakeLists.txt only declares LANGUAGES CXX, the C compiler hasn't been initialized yet — even though JUCE's own juce_add_* macros call enable_language(C) later.

What is the expected behaviour?

With CMake 4.x, this causes a hard FATAL_ERROR:

CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_C_COMPILE_OBJECT
With CMake 3.x it may work by accident since the variable gets set later.

Workaround: Users must add C to their project languages:

project(MyApp VERSION 1.0.0 LANGUAGES CXX C) # C required even if no C sources
Proposed fix: Move the CMAKE_C_COMPILE_OBJECT check from module scope into the juce_add_console_app, juce_add_gui_app, and juce_add_plugin functions — after the enable_language(C) call has had a chance to run.

Operating systems

Linux

What versions of the operating systems?

endeavourOS. It's an arch-based, so always latest.

Architectures

x86_64

Stacktrace

Plug-in formats (if applicable)

No response

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

  • I agree to follow the Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions