浏览代码

Merge topic 'ExternalProject-check-explicit-include'

df1ddeec12 ExternalProject: Report error if local variables are not defined

Acked-by: Kitware Robot <[email protected]>
Acked-by: Brad King <[email protected]>
Merge-request: !2281
Craig Scott 7 年之前
父节点
当前提交
49cb2a504d

+ 5 - 0
Modules/ExternalProject.cmake

@@ -934,6 +934,11 @@ function(_ep_parse_arguments f name ns args)
   # We loop through ARGN and consider the namespace starting with an
   # upper-case letter followed by at least two more upper-case letters,
   # numbers or underscores to be keywords.
+
+  if(NOT DEFINED _ExternalProject_SELF)
+    message(FATAL_ERROR "error: ExternalProject module must be explicitly included before using ${f} function")
+  endif()
+
   set(key)
 
   foreach(arg IN LISTS args)

+ 1 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add-stderr.txt

@@ -0,0 +1,7 @@
+^CMake Error at .*/Modules/ExternalProject.cmake:[0-9]+ \(message\):
+  error: ExternalProject module must be explicitly included before using
+  ExternalProject_Add function
+Call Stack \(most recent call first\):
+  .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_parse_arguments\)
+  IncludeScope-Add.cmake:[0-9]+ \(ExternalProject_Add\)
+  CMakeLists.txt:[0-9]+ \(include\)$

+ 12 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add.cmake

@@ -0,0 +1,12 @@
+function(IncludeScope_IncludeOnly)
+  include(ExternalProject)
+endfunction()
+
+IncludeScope_IncludeOnly()
+
+ExternalProject_Add(MyProj
+    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+)

+ 1 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add_Step-stderr.txt

@@ -0,0 +1,7 @@
+^CMake Error at .*/Modules/ExternalProject.cmake:[0-9]+ \(message\):
+  error: ExternalProject module must be explicitly included before using
+  ExternalProject_Add_Step function
+Call Stack \(most recent call first\):
+  .*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_parse_arguments\)
+  IncludeScope-Add_Step.cmake:[0-9]+ \(ExternalProject_Add_Step\)
+  CMakeLists.txt:[0-9]+ \(include\)$

+ 13 - 0
Tests/RunCMake/ExternalProject/IncludeScope-Add_Step.cmake

@@ -0,0 +1,13 @@
+function(IncludeScope_DefineProj)
+  include(ExternalProject)
+  ExternalProject_Add(MyProj
+    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND     ""
+    INSTALL_COMMAND   ""
+  )
+endfunction()
+
+IncludeScope_DefineProj()
+
+ExternalProject_Add_Step(MyProj extraStep COMMENT "Foo")

+ 2 - 0
Tests/RunCMake/ExternalProject/RunCMakeTest.cmake

@@ -1,5 +1,7 @@
 include(RunCMake)
 
+run_cmake(IncludeScope-Add)
+run_cmake(IncludeScope-Add_Step)
 run_cmake(NoOptions)
 run_cmake(SourceEmpty)
 run_cmake(SourceMissing)