cmake config_error ai_generated true

CMake Error: Could not determine the platform name for CMAKE_SYSTEM_NAME = "Generic"

ID: cmake/generic-platform-name-unknown

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
cmake 3.26.0 active
cmake 3.27.0 active
cmake 3.28.0 active

Root Cause

CMake cannot find a valid platform file for the given system name; often occurs when using a custom toolchain file without specifying CMAKE_SYSTEM_NAME correctly.

generic

中文

CMake 无法为给定的系统名称找到有效的平台文件;通常发生在使用自定义工具链文件而未正确指定 CMAKE_SYSTEM_NAME 时。

Official Documentation

https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-with-toolchain-files

Workarounds

  1. 90% success Create a custom platform file named 'Platform/Generic.cmake' in your project's cmake module path with minimal settings: # cmake/Platform/Generic.cmake set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_C_COMPILER_WORKS TRUE) set(CMAKE_CXX_COMPILER_WORKS TRUE) Then set CMAKE_MODULE_PATH to include that directory.
    Create a custom platform file named 'Platform/Generic.cmake' in your project's cmake module path with minimal settings:
    
    # cmake/Platform/Generic.cmake
    set(CMAKE_SYSTEM_NAME Generic)
    set(CMAKE_C_COMPILER_WORKS TRUE)
    set(CMAKE_CXX_COMPILER_WORKS TRUE)
    
    Then set CMAKE_MODULE_PATH to include that directory.
  2. 80% success Use the existing 'Generic' platform by setting the toolchain file properly: cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake -DCMAKE_SYSTEM_NAME=Generic /path/to/source Ensure toolchain.cmake sets CMAKE_SYSTEM_NAME to Generic.
    Use the existing 'Generic' platform by setting the toolchain file properly:
    
    cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake -DCMAKE_SYSTEM_NAME=Generic /path/to/source
    
    Ensure toolchain.cmake sets CMAKE_SYSTEM_NAME to Generic.

中文步骤

  1. 在项目的 cmake 模块路径中创建名为 'Platform/Generic.cmake' 的自定义平台文件,包含最小设置:
    
    # cmake/Platform/Generic.cmake
    set(CMAKE_SYSTEM_NAME Generic)
    set(CMAKE_C_COMPILER_WORKS TRUE)
    set(CMAKE_CXX_COMPILER_WORKS TRUE)
    
    然后设置 CMAKE_MODULE_PATH 指向该目录。
  2. 通过正确设置工具链文件来使用现有的 'Generic' 平台:
    
    cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake -DCMAKE_SYSTEM_NAME=Generic /path/to/source
    
    确保 toolchain.cmake 设置了 CMAKE_SYSTEM_NAME 为 Generic。

Dead Ends

Common approaches that don't work:

  1. Set CMAKE_SYSTEM_NAME to "Linux" or "Windows" arbitrarily 70% fail

    Forces a platform file that may not match the target environment, causing linker or compiler errors.

  2. Remove CMAKE_SYSTEM_NAME entirely 85% fail

    CMake will auto-detect the host system, which defeats cross-compilation and may produce wrong binaries.