Enforce explicit use of project() command
The project()
command documentation states:
The top-level
CMakeLists.txt
file for a project must contain a literal, direct call to theproject()
command; loading one through theinclude()
command is not sufficient. If no such call exists CMake will implicitly add one to the top that enables the default languages (C and CXX).
Injecting the missing project()
command is done before any call to cmake_minimum_required()
and therefore its invocation to enable languages does not benefit from modern policy settings. This leads to problems like #17712 (closed).
We should consider ways to enforce explicit use of project()
, such as a warning when the injection is done.
The canonical top-level CMakeLists.txt
file should be:
cmake_minimum_required(VERSION 3.10) # or some other version
project(MyProject) # optionally list languages or use NONE to suppress them
# ... rest of the code