Merge topic 'module-case-mismatch'

dadbb71492 include/find_package: Warn on case-mismatched module names

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12094
This commit is contained in:
Brad King
2026-05-29 13:31:24 +00:00
committed by Kitware Robot
13 changed files with 111 additions and 2 deletions

View File

@@ -3511,6 +3511,27 @@ std::string cmMakefile::GetModulesFile(cm::string_view filename, bool& system,
result = moduleInCMakeRoot;
}
#if defined(_WIN32) || defined(__APPLE__)
if (!result.empty()) {
std::string const requestedName =
cmSystemTools::GetFilenameName(std::string{ filename });
std::string actualName;
cmsys::Status const status =
cmSystemTools::ReadNameOnDisk(result, actualName);
if (status && actualName != requestedName) {
this->IssueDiagnostic(
cmDiagnostics::CMD_AUTHOR,
cmStrCat("The module name\n ", requestedName, '\n',
"does not match the case of the module file name on disk\n"
" ",
cmSystemTools::GetFilenamePath(result), '/', actualName, '\n',
"This may fail on case-sensitive file systems. "
"Use the module name\n ",
actualName, "\ninstead."));
}
}
#endif
return result;
}

View File

@@ -367,6 +367,14 @@ RealSystem RealOS;
} // namespace
#if defined(_WIN32) || defined(__APPLE__)
cmsys::Status cmSystemTools::ReadNameOnDisk(std::string const& path,
std::string& name)
{
return ::ReadNameOnDisk(path, name);
}
#endif
#if !defined(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
// For GetEnvironmentVariables
# if defined(_WIN32)

View File

@@ -672,6 +672,12 @@ public:
/** Return subview of the full filename (i.e. file name without path) */
static cm::string_view GetFilenameNameView(cm::string_view filename);
#if defined(_WIN32) || defined(__APPLE__)
/** Read the on-disk spelling of the full filename's last component. */
static cmsys::Status ReadNameOnDisk(std::string const& path,
std::string& name);
#endif
/**
* Return subview of file extension of a full filename (dot included).
* Warning: this is the shortest extension (for example: .gz of .tar.gz)

View File

@@ -264,6 +264,22 @@ if(BUILD_TESTING)
unset(_sysctl_stdout)
endif()
if(NOT DEFINED CMake_TEST_FILESYSTEM_CASE)
if(CMAKE_HOST_WIN32)
set(CMake_TEST_FILESYSTEM_CASE 1)
elseif(CMAKE_HOST_APPLE)
execute_process(
COMMAND sw_vers -productVersion
OUTPUT_VARIABLE sw_vers_productVersion
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE _sw_vers_result
)
if(sw_vers_productVersion VERSION_GREATER_EQUAL 10.11)
set(CMake_TEST_FILESYSTEM_CASE 1)
endif()
endif()
endif()
if(CMake_TEST_CUDA AND NOT CMake_TEST_CUDA MATCHES "^(NVIDIA|Clang)$")
message(FATAL_ERROR "CMake_TEST_CUDA should be \"NVIDIA\" or \"Clang\", got \"${CMake_TEST_CUDA}\"")
endif()

View File

@@ -777,7 +777,8 @@ add_RunCMake_test(file-RPATH
add_RunCMake_test(file-STRINGS)
add_RunCMake_test(find_file -DMINGW=${MINGW})
add_RunCMake_test(find_library -DMINGW=${MINGW} -DCYGWIN=${CYGWIN} -DMSYS=${MSYS} -DMSVC=${MSVC})
add_RunCMake_test(find_package -DMINGW=${MINGW} -DMSYS=${MSYS})
add_RunCMake_test(find_package -DMINGW=${MINGW} -DMSYS=${MSYS}
-DCMake_TEST_FILESYSTEM_CASE=${CMake_TEST_FILESYSTEM_CASE})
add_RunCMake_test(find_package-CPS)
add_RunCMake_test(find_path -DMINGW=${MINGW})
add_RunCMake_test(find_program -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
@@ -792,7 +793,7 @@ endif()
add_RunCMake_test(INSTALL_OBJECT_NAME_STRATEGY)
add_RunCMake_test(INSTALL_OBJECT_ONLY_USE_DESTINATION)
add_RunCMake_test(if -DMSYS=${MSYS})
add_RunCMake_test(include)
add_RunCMake_test(include -DCMake_TEST_FILESYSTEM_CASE=${CMake_TEST_FILESYSTEM_CASE})
add_RunCMake_test(include_directories)
add_RunCMake_test(include_guard)
add_RunCMake_test(list)

View File

@@ -0,0 +1,18 @@
^CMake Warning \(author\) at ModuleNameCaseMismatch\.cmake:[0-9]+ \(find_package\):
The module name
Findcasemodule\.cmake
does not match the case of the module file name on disk
[^
]*/ModuleNameCaseMismatch/FindCaseModule\.cmake
This may fail on case-sensitive file systems\. Use the module name
FindCaseModule\.cmake
instead\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author to suppress it\.$

View File

@@ -0,0 +1,7 @@
list(PREPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_LIST_DIR}/ModuleNameCaseMismatch")
find_package(casemodule MODULE)
if(NOT casemodule_FOUND)
message(FATAL_ERROR "FindCaseModule.cmake not included")
endif()

View File

@@ -0,0 +1 @@
set(casemodule_FOUND TRUE)

View File

@@ -35,6 +35,9 @@ run_cmake(MissingConfigOneName)
run_cmake(MissingConfigRequired)
run_cmake(MissingConfigVersion)
run_cmake(MixedModeOptions)
if(CMake_TEST_FILESYSTEM_CASE)
run_cmake(ModuleNameCaseMismatch)
endif()
run_cmake_with_options(ModuleModeDebugPkg --debug-find-pkg=Foo,Zot)
run_cmake(NestedConfig)
run_cmake(PackageRoot)

View File

@@ -0,0 +1,18 @@
^CMake Warning \(author\) at CaseMismatch\.cmake:[0-9]+ \(include\):
The module name
casemodule\.cmake
does not match the case of the module file name on disk
[^
]*/CaseMismatch/CaseModule\.cmake
This may fail on case-sensitive file systems\. Use the module name
CaseModule\.cmake
instead\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author to suppress it\.$

View File

@@ -0,0 +1,6 @@
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CaseMismatch")
include(casemodule)
if(NOT case_module_included)
message(FATAL_ERROR "CaseModule.cmake not included")
endif()

View File

@@ -0,0 +1 @@
set(case_module_included TRUE)

View File

@@ -6,6 +6,9 @@ run_cmake(CMP0024-NEW)
run_cmake(ExportExportInclude)
run_cmake(IncludeIsDirectory)
run_cmake(IncludeMalformed)
if(CMake_TEST_FILESYSTEM_CASE)
run_cmake(CaseMismatch)
endif()
run_cmake(ParentVariableRoot)
run_cmake(ParentVariableSubDir)
run_cmake_script(ParentVariableScript)