Deprecation warnings with clang when setting LANGUAGE property

With CMake 3.16.3 and 3.23.1 at least, when using CC=clang CXX=clang++ and doing a CMakeLists.txt like the following (simplified from the case in the WebKit code) I see a deprecation warning about .c files being treated as c++ when in c++ mode:

cmake_minimum_required(VERSION 3.13)
project(testproj)
add_executable(app app.c)
set_source_files_properties(app.c PROPERTIES LANGUAGE CXX)

and a simple app.c

int main() {}

The command being run seems to be

/usr/bin/clang++     -o CMakeFiles/app.dir/app.c.o -c /home/szabos1/cmtest/app.c

which gives

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

Using app.q rather than app.c, I got an error instead as it doesn’t generate an output file for ‘linker’ input.

I’m not sure if these sorts of cases where one overrides the language for a file is expected to work without the warning/errors.

I don’t think it can.
You have told CMake to use C++ compiler to compile app.c and it did. The C++ compiler you use warns in this situation. If you know, what you’re doing either ignore the warning or add -Wno-deprecated for that file but rather don’t expect some auto-magic :wink:

See policy CMP0119, which updates the LANGUAGE property to also add -x c++. If you bump your cmake_minimum_required call to 3.20 or higher, the policy’s NEW behavior will be used automatically.

Thanks, I forgot to check for a policy. I think the WebKit side needs to support pre 3.20 for some ports, but we’re past that for our port anyway.