summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2014-06-13 11:39:47 +0200
committerStephen Kelly <steveire@gmail.com>2014-07-02 19:37:04 +0200
commitb47c125ff7f088c87183e6ad60850aefdaf43757 (patch)
tree7ac75263740e5490a2feb408bded3440ac9bfb00
parent477b07213a806c825f95fdfacd444028e1783dc2 (diff)
downloadcmake-b47c125ff7f088c87183e6ad60850aefdaf43757.tar.gz
WCDH: Ensure that the prefix argument to the macro is valid.
The prefix must be a C-identifier because it is written as the prefix of preprocessor macros and possibly structs.
-rw-r--r--Modules/WriteCompilerDetectionHeader.cmake8
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt1
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt5
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake10
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake2
8 files changed, 42 insertions, 0 deletions
diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake
index 593176c91b..86137e2d68 100644
--- a/Modules/WriteCompilerDetectionHeader.cmake
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -235,6 +235,14 @@ function(write_compiler_detection_header
message(FATAL_ERROR "Unparsed arguments: ${_WCD_UNPARSED_ARGUMENTS}")
endif()
+ if (prefix_arg STREQUAL "")
+ message(FATAL_ERROR "A prefix must be specified")
+ endif()
+ string(MAKE_C_IDENTIFIER ${prefix_arg} cleaned_prefix)
+ if (NOT prefix_arg STREQUAL cleaned_prefix)
+ message(FATAL_ERROR "The prefix must be a valid C identifier.")
+ endif()
+
if(NOT _WCD_VERSION)
set(_WCD_VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
endif()
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt
new file mode 100644
index 0000000000..cf8578e265
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ A prefix must be specified
+Call Stack \(most recent call first\):
+ EmptyPrefix.cmake:[0-9]+ \(write_compiler_detection_header\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake
new file mode 100644
index 0000000000..eda6b185aa
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/EmptyPrefix.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX ""
+ VERSION 3.1
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt
new file mode 100644
index 0000000000..ea1bf6703e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix-stderr.txt
@@ -0,0 +1,5 @@
+CMake Error at .*/Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
+ The prefix must be a valid C identifier.
+Call Stack \(most recent call first\):
+ InvalidPrefix.cmake:[0-9]+ \(write_compiler_detection_header\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake
new file mode 100644
index 0000000000..6599f35a9e
--- /dev/null
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidPrefix.cmake
@@ -0,0 +1,10 @@
+
+include(WriteCompilerDetectionHeader)
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/somefile"
+ PREFIX "0compile"
+ VERSION 3.1
+ COMPILERS GNU
+ FEATURES cxx_final
+)
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake b/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake
index be79d417f4..6dded44a6b 100644
--- a/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/RunCMakeTest.cmake
@@ -10,3 +10,5 @@ run_cmake(OldVersion)
run_cmake(InvalidCompiler)
run_cmake(InvalidFeature)
run_cmake(InvalidCXXFeature)
+run_cmake(EmptyPrefix)
+run_cmake(InvalidPrefix)