summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-02-24 20:09:06 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-02-24 22:43:22 (GMT)
commit7e3f9aa1b22fe44e7c077b9d8c56cc9eee375958 (patch)
treec33d1858b94a0745be9648a56cced9163f38b1ac
parent35ca2d524befc71b840808cce4e0a773ef722b71 (diff)
downloadCMake-7e3f9aa1b22fe44e7c077b9d8c56cc9eee375958.zip
CMake-7e3f9aa1b22fe44e7c077b9d8c56cc9eee375958.tar.gz
CMake-7e3f9aa1b22fe44e7c077b9d8c56cc9eee375958.tar.bz2
target_sources: give a hint when a file named `FILE_SET` is not found
`FILE_SET` is only supported within `target_sources()` and only directly after a visibility keyword or another `FILE_SET`. Give a hint as to what might be wrong if a file named `FILE_SET` cannot be found for any reason. Fixes: #24539
-rw-r--r--Source/cmSourceFile.cxx8
-rw-r--r--Tests/RunCMake/target_sources/FileSetDirect-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetDirect-stderr.txt12
-rw-r--r--Tests/RunCMake/target_sources/FileSetDirect.cmake3
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongSyntax-result.txt1
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongSyntax-stderr.txt12
-rw-r--r--Tests/RunCMake/target_sources/FileSetWrongSyntax.cmake4
-rw-r--r--Tests/RunCMake/target_sources/RunCMakeTest.cmake2
8 files changed, 43 insertions, 0 deletions
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index 3fa0051..6224d0e 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -4,6 +4,9 @@
#include <utility>
+#include <cm/string_view>
+#include <cmext/string_view>
+
#include "cmGlobalGenerator.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
@@ -221,6 +224,11 @@ bool cmSourceFile::FindFullPath(std::string* error,
case cmPolicies::NEW:
break;
}
+ if (lPath == "FILE_SET"_s) {
+ err += "\nHint: the FILE_SET keyword may only appear after a visibility "
+ "specifier or another FILE_SET within the target_sources() "
+ "command.";
+ }
if (error != nullptr) {
*error = std::move(err);
} else {
diff --git a/Tests/RunCMake/target_sources/FileSetDirect-result.txt b/Tests/RunCMake/target_sources/FileSetDirect-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDirect-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetDirect-stderr.txt b/Tests/RunCMake/target_sources/FileSetDirect-stderr.txt
new file mode 100644
index 0000000..c1f7635
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDirect-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at FileSetDirect.cmake:3 \(add_library\):
+ Cannot find source file:
+
+ FILE_SET
+
+ Tried extensions .c .C .c\+\+ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
+ .hh .h\+\+ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
+
+ Hint: the FILE_SET keyword may only appear after a visibility specifier or
+ another FILE_SET within the target_sources\(\) command.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_sources/FileSetDirect.cmake b/Tests/RunCMake/target_sources/FileSetDirect.cmake
new file mode 100644
index 0000000..9f412c8
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetDirect.cmake
@@ -0,0 +1,3 @@
+enable_language(C)
+
+add_library(lib1 STATIC empty.c FILE_SET h1.h TYPE HEADERS)
diff --git a/Tests/RunCMake/target_sources/FileSetWrongSyntax-result.txt b/Tests/RunCMake/target_sources/FileSetWrongSyntax-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongSyntax-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/target_sources/FileSetWrongSyntax-stderr.txt b/Tests/RunCMake/target_sources/FileSetWrongSyntax-stderr.txt
new file mode 100644
index 0000000..8722347
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongSyntax-stderr.txt
@@ -0,0 +1,12 @@
+CMake Error at FileSetWrongSyntax.cmake:3 \(add_library\):
+ Cannot find source file:
+
+ FILE_SET
+
+ Tried extensions .c .C .c\+\+ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
+ .hh .h\+\+ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
+
+ Hint: the FILE_SET keyword may only appear after a visibility specifier or
+ another FILE_SET within the target_sources\(\) command.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/target_sources/FileSetWrongSyntax.cmake b/Tests/RunCMake/target_sources/FileSetWrongSyntax.cmake
new file mode 100644
index 0000000..709fb23
--- /dev/null
+++ b/Tests/RunCMake/target_sources/FileSetWrongSyntax.cmake
@@ -0,0 +1,4 @@
+enable_language(C)
+
+add_library(lib1 STATIC)
+target_sources(lib1 PRIVATE empty.c FILE_SET h1.h TYPE HEADERS)
diff --git a/Tests/RunCMake/target_sources/RunCMakeTest.cmake b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
index 7c67c3f..c1314f7 100644
--- a/Tests/RunCMake/target_sources/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_sources/RunCMakeTest.cmake
@@ -43,6 +43,8 @@ run_cmake(FileSetNoExistInstall)
run_cmake(FileSetDirectories)
run_cmake(FileSetCustomTarget)
run_cmake(FileSetBadName)
+run_cmake(FileSetWrongSyntax)
+run_cmake(FileSetDirect)
if(APPLE)
run_cmake(FileSetFramework)
endif()