Skip to content

Commit ed8bc17

Browse files
committed
CppCheck: print friendly message if C++ <filesystem> is not linkable
This is better UX and no need to warn users. For example, a GCC 13 Linux HPC user saw this.
1 parent e29877a commit ed8bc17

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

cmake/CppCheck.cmake

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@ endif()
1919
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
2020

2121
# some compilers claim to have filesystem, but their libstdc++ doesn't have it.
22-
check_source_compiles(CXX
23-
[=[
24-
#include <filesystem>
25-
22+
set(_src "#include <filesystem>
2623
int main () {
27-
std::filesystem::path tgt("a/b");
28-
29-
return !tgt.has_filename();
30-
}
31-
]=]
32-
HAVE_CXX_FILESYSTEM
33-
)
24+
std::filesystem::path tgt;
25+
return tgt.empty() ? 0 : 1;
26+
}")
27+
check_source_compiles(CXX "${_src}" HAVE_CXX_FILESYSTEM)
3428

3529
if(NOT HAVE_CXX_FILESYSTEM)
36-
message(WARNING "C++ stdlib filesystem is broken in libstdc++ ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}
37-
${HAVE_CXX_FILESYSTEM}")
30+
message(STATUS "${PROJECT_NAME}: CMake ${CMAKE_VERSION} ${CMAKE_GENERATOR} proceeding with C++${CMAKE_CXX_STANDARD} fallback to <filesystem>: libstdc++ ${ffilesystem_stdcpp_version} compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} linker: ${CMAKE_CXX_COMPILER_LINKER_ID} ${CMAKE_CXX_COMPILER_LINKER_VERSION}
31+
${HAVE_CXX_FILESYSTEM}
32+
see CMake log file ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeConfigureLog.yaml for details on variable HAVE_CXX_FILESYSTEM.")
3833
return()
3934
endif()
4035

0 commit comments

Comments
 (0)