summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/command/project.rst3
-rw-r--r--Help/release/dev/top-level-command-order.rst6
-rw-r--r--Source/cmProjectCommand.cxx9
-rw-r--r--Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt2
-rw-r--r--Tests/RunCMake/project/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/project/NoMinimumRequired-stderr.txt5
-rw-r--r--Tests/RunCMake/project/NoMinimumRequired.cmake0
-rw-r--r--Tests/RunCMake/project/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/project_injected/RunCMakeTest.cmake1
9 files changed, 30 insertions, 2 deletions
diff --git a/Help/command/project.rst b/Help/command/project.rst
index 8f32fa3..4e57d09 100644
--- a/Help/command/project.rst
+++ b/Help/command/project.rst
@@ -188,5 +188,6 @@ call exists, CMake will issue a warning and pretend there is a
Call the ``project()`` command near the top of the top-level
``CMakeLists.txt``, but *after* calling :command:`cmake_minimum_required`.
It is important to establish version and policy settings before invoking
- other commands whose behavior they may affect.
+ other commands whose behavior they may affect and for this reason the
+ ``project()`` command will issue a warning if this order is not kept.
See also policy :policy:`CMP0000`.
diff --git a/Help/release/dev/top-level-command-order.rst b/Help/release/dev/top-level-command-order.rst
new file mode 100644
index 0000000..07f87fb
--- /dev/null
+++ b/Help/release/dev/top-level-command-order.rst
@@ -0,0 +1,6 @@
+top-level-command-order
+-----------------------
+
+* The top-level :command:`project` call will now emit an author warning if the
+ documented command order in relation to :command:`cmake_minimum_required` is
+ not respected.
diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx
index 249fe2d..4d1ccfe 100644
--- a/Source/cmProjectCommand.cxx
+++ b/Source/cmProjectCommand.cxx
@@ -34,6 +34,15 @@ bool cmProjectCommand(std::vector<std::string> const& args,
}
cmMakefile& mf = status.GetMakefile();
+ if (mf.IsRootMakefile() &&
+ !mf.GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) {
+ mf.IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ "cmake_minimum_required() should be called prior to this top-level "
+ "project() call. Please see the cmake-commands(7) manual for usage "
+ "documentation of both commands.");
+ }
+
if (!IncludeByVariable(status, "CMAKE_PROJECT_INCLUDE_BEFORE")) {
return false;
}
diff --git a/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt b/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt
index adc125b..ce1cce3 100644
--- a/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt
+++ b/Tests/RunCMake/CommandLine/C_buildsrcdir/initial-cache.txt
@@ -1,3 +1,5 @@
+set(CMAKE_MINIMUM_REQUIRED_VERSION "" CACHE STRING "")
+
# Used to verify that the values match what is passed via -S and -B, and are retained in cache.
set(INITIAL_SOURCE_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "defined in initial.cmake")
set(INITIAL_BINARY_DIR "${CMAKE_BINARY_DIR}" CACHE PATH "defined in initial.cmake")
diff --git a/Tests/RunCMake/project/CMakeLists.txt b/Tests/RunCMake/project/CMakeLists.txt
index 4b3de84..fdcaee9 100644
--- a/Tests/RunCMake/project/CMakeLists.txt
+++ b/Tests/RunCMake/project/CMakeLists.txt
@@ -1,3 +1,5 @@
-cmake_minimum_required(VERSION 2.8.12)
+if(NOT "x${RunCMake_TEST}" STREQUAL "xNoMinimumRequired")
+ cmake_minimum_required(VERSION 2.8.12)
+endif()
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/project/NoMinimumRequired-stderr.txt b/Tests/RunCMake/project/NoMinimumRequired-stderr.txt
new file mode 100644
index 0000000..83e2ac9
--- /dev/null
+++ b/Tests/RunCMake/project/NoMinimumRequired-stderr.txt
@@ -0,0 +1,5 @@
+CMake Warning \(dev\) at CMakeLists\.txt:[0-9]+ \(project\):
+ cmake_minimum_required\(\) should be called prior to this top-level project\(\)
+ call\. Please see the cmake-commands\(7\) manual for usage documentation of
+ both commands\.
+This warning is for project developers\. Use -Wno-dev to suppress it\.$
diff --git a/Tests/RunCMake/project/NoMinimumRequired.cmake b/Tests/RunCMake/project/NoMinimumRequired.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/project/NoMinimumRequired.cmake
diff --git a/Tests/RunCMake/project/RunCMakeTest.cmake b/Tests/RunCMake/project/RunCMakeTest.cmake
index 6d9f52f..0f3716f 100644
--- a/Tests/RunCMake/project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/project/RunCMakeTest.cmake
@@ -52,3 +52,5 @@ run_cmake(CMP0048-NEW)
run_cmake(CMP0096-WARN)
run_cmake(CMP0096-OLD)
run_cmake(CMP0096-NEW)
+
+run_cmake(NoMinimumRequired)
diff --git a/Tests/RunCMake/project_injected/RunCMakeTest.cmake b/Tests/RunCMake/project_injected/RunCMakeTest.cmake
index ba1a003..cf63e12 100644
--- a/Tests/RunCMake/project_injected/RunCMakeTest.cmake
+++ b/Tests/RunCMake/project_injected/RunCMakeTest.cmake
@@ -1,6 +1,7 @@
include(RunCMake)
set(RunCMake_TEST_OPTIONS
+ -DCMAKE_MINIMUM_REQUIRED_VERSION:STATIC=
# Simulate a previous CMake run that used `project(... VERSION ...)`
# in a non-injected call site.
-DCMAKE_PROJECT_VERSION:STATIC=1.2.3