首页 > 解决方案 > 没有 C 编译器的主机上的非 C 项目的 CMake

问题描述

我想使用 CMake 为非 C 项目生成 makefile。我不需要 C 编译器来构建我的项目。事实上,我没有在主机上安装 C 编译器。

我的CMakeLists.txt样子:

cmake_minimum_required (VERSION 2.6)
project (the_thing.html)

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/cmake-pandocology")
INCLUDE(pandocology)

add_document(
    TARGET the_thing
    OUTPUT_FILE the_thing.html
    SOURCES the_thing.md
)

当我在我的 Windows 机器上运行 cmake 时:

$ mkdir dict && cd dist
$ cmake .. -G"Unix Makefiles"
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also ".../dist/CMakeFiles/CMakeOutput.log".
See also ".../dist/CMakeFiles/CMakeError.log".

这两个日志文件没有提供额外的线索。如何修复该项目以使其忽略缺少 C(和 C++)编译器?

标签: cmake

解决方案


你需要明确地说没有语言。

project("the_thing.html"
    LANGUAGES
        NONE
)

那来自我的一个项目,但它使用现代 CMake(您的最低版本是 2.6)。以上可能对您有用,但如果不是,应该这样做:

project("the_thing.html" NONE)

推荐阅读