summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/GetPrerequisites.cmake9
-rw-r--r--Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt3
-rw-r--r--Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake19
-rw-r--r--Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake1
-rwxr-xr-xTests/RunCMake/GetPrerequisites/script3
-rwxr-xr-xTests/RunCMake/GetPrerequisites/script.bat3
-rwxr-xr-xTests/RunCMake/GetPrerequisites/script.sh3
7 files changed, 41 insertions, 0 deletions
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake
index d3b773c..fa6d75a 100644
--- a/Modules/GetPrerequisites.cmake
+++ b/Modules/GetPrerequisites.cmake
@@ -660,6 +660,15 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
return()
endif()
+ # Check for a script by extension (.bat,.sh,...) or if the file starts with "#!" (shebang)
+ file(READ ${target} file_contents LIMIT 5)
+ if(target MATCHES "\\.(bat|c?sh|bash|ksh|cmd)$" OR file_contents MATCHES "^#!")
+ message(STATUS "GetPrequisites(${target}) : ignoring script file")
+ # Clear var
+ set(${prerequisites_var} "" PARENT_SCOPE)
+ return()
+ endif()
+
set(gp_cmd_paths ${gp_cmd_paths}
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0;InstallDir]/../../VC/bin"
"$ENV{VS140COMNTOOLS}/../../VC/bin"
diff --git a/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt b/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt
new file mode 100644
index 0000000..5a353d8
--- /dev/null
+++ b/Tests/RunCMake/GetPrerequisites/ExecutableScripts-stdout.txt
@@ -0,0 +1,3 @@
+-- GetPrequisites\(.*script.sh\) : ignoring script file
+-- GetPrequisites\(.*script.bat\) : ignoring script file
+-- GetPrequisites\(.*script\) : ignoring script file
diff --git a/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake b/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake
new file mode 100644
index 0000000..d1bc9b1
--- /dev/null
+++ b/Tests/RunCMake/GetPrerequisites/ExecutableScripts.cmake
@@ -0,0 +1,19 @@
+include(GetPrerequisites)
+
+function(check_script script)
+ set(prereqs "")
+ get_prerequisites(${script} prereqs 1 1 "" "")
+ if(NOT "${prereqs}" STREQUAL "")
+ message(FATAL_ERROR "Prerequisites for ${script} not empty")
+ endif()
+endfunction()
+
+# Should not throw any errors
+# Regular executable
+get_prerequisites(${CMAKE_COMMAND} cmake_prereqs 1 1 "" "")
+# Shell script
+check_script(${CMAKE_CURRENT_LIST_DIR}/script.sh)
+# Batch script
+check_script(${CMAKE_CURRENT_LIST_DIR}/script.bat)
+# Shell script without extension
+check_script(${CMAKE_CURRENT_LIST_DIR}/script)
diff --git a/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake
index 3856c54..a635e38 100644
--- a/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GetPrerequisites/RunCMakeTest.cmake
@@ -1,3 +1,4 @@
include(RunCMake)
run_cmake_command(TargetMissing ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/TargetMissing.cmake)
+run_cmake_command(ExecutableScripts ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/ExecutableScripts.cmake)
diff --git a/Tests/RunCMake/GetPrerequisites/script b/Tests/RunCMake/GetPrerequisites/script
new file mode 100755
index 0000000..23bf47c
--- /dev/null
+++ b/Tests/RunCMake/GetPrerequisites/script
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "Hello World"
diff --git a/Tests/RunCMake/GetPrerequisites/script.bat b/Tests/RunCMake/GetPrerequisites/script.bat
new file mode 100755
index 0000000..dbb0ec2
--- /dev/null
+++ b/Tests/RunCMake/GetPrerequisites/script.bat
@@ -0,0 +1,3 @@
+@echo off
+
+echo "Hello world"
diff --git a/Tests/RunCMake/GetPrerequisites/script.sh b/Tests/RunCMake/GetPrerequisites/script.sh
new file mode 100755
index 0000000..23bf47c
--- /dev/null
+++ b/Tests/RunCMake/GetPrerequisites/script.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "Hello World"