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
This commit is contained in:
Ben Boeckel 2023-02-24 15:09:06 -05:00
parent 35ca2d524b
commit 7e3f9aa1b2
8 changed files with 43 additions and 0 deletions

View File

@ -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 {

View File

@ -0,0 +1 @@
1

View File

@ -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\)

View File

@ -0,0 +1,3 @@
enable_language(C)
add_library(lib1 STATIC empty.c FILE_SET h1.h TYPE HEADERS)

View File

@ -0,0 +1 @@
1

View File

@ -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\)

View File

@ -0,0 +1,4 @@
enable_language(C)
add_library(lib1 STATIC)
target_sources(lib1 PRIVATE empty.c FILE_SET h1.h TYPE HEADERS)

View File

@ -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()