如何正确启动 CMake

How can I launch CMake correctly

为了上学,我必须下载 CMake。 现在我在 mash-project 上找到了一个快速入门指南,但我不明白。

  1. 有人知道我在哪里可以选择 Xcode 作为生成器吗?
  2. CMAKE_BUILD_TYPECMAKE_OSX_ARCHITECTURES...
  3. 的含义是什么
  4. 我在应用程序文件夹中找不到 CMake,为什么?
  5. 我究竟需要 CMake 做什么?

谢谢千次的帮助!

  1. 获取 CMake 的图形界面,您将看到在多个构建环境中进行选择的选项。其中之一应该是 Xcode。阅读我对第 3 点的回答,了解如何获取 GUI。

  2. 第一个变量 CMAKE_BUILD_TYPE 包含一个表示构建 "flavor" 的值。用 Visual Studio 的说法,想想 Debug 和 Release。其工作方式非常简单:CMake 为每种构建类型定义了一组变量,用于控制构建过程的多个方面。例如,当 CMAKE_BUILD_TYPE 的值为 Debug 时,变量 CMAKE_CXX_FLAGS_DEBUG 包含要传递给 C++ 编译器的标志序列。类似地,CMAKE_CXX_FLAGS_RELEASE 可以解决 Release 的问题。 CMake 带有四种默认构建类型:Debug、Release、MinSizeRel 和 RelWithDebInfo。可以看看here官方文档

    我从来没有搞砸过 CMAKE_OSX_ARCHITECTURES,但也许 this 有帮助。

  3. 与许多其他程序一样,CMake 带有 "terminal interface",即可以使用终端进行交互。我不知道有关您的 CMake 安装的具体细节,但也许您没有获得任何图形界面,在这种情况下,不要指望在 Applications 文件夹中找到任何东西。 This answer 可能会有所帮助。简答:运行

    sudo port install cmake +gui
    

    也就是说,您可以通过将 CMake 所在的目录附加到您的 PATH 环境变量来使用终端界面。

  4. CMake 是一个非常漂亮的软件。在 C++ 世界中,有无数的编译器和环境,每个都有自己的配置设置。假设你写了一个很酷的软件,你想与世界分享。现在好吧,作为一个开源的人,你决定在自由许可下分发源代码,这样我们就可以自己构建它。此时,您究竟分发什么?

    一堆源文件?对构建中型项目没有帮助。我不知道您的项目结构,也不知道您可能依赖的任何预处理器宏。

    如果您的开发环境是 Visual Studio,您可以分发 .sln 文件,每个 Visual Studio 用户都可以使用完全相同的设置加载项目您假设在构建时会在场。这就带来了一个问题:我们这些不使用 Visual Studio 的人呢?您是否会仅仅因为他们选择 Linux 或 Mac OS X 而失去一群潜在用户?

    输入CMake。该程序允许您定义项目的结构(即要构建哪些库、哪些可执行文件、哪些测试),列出您可能拥有的任何依赖项(例如 Boost、Qt、Ogre3D),设置任何预处理器宏(呃! ) 你可能需要。您可以使用 CMake 定义的语言执行此操作,它可以在任何平台上理解该语言。处理此配置时,CMake 会为其 运行 所在的特定平台生成构建环境。你看,CMake 不会构建你的项目。它不是编译器。 CMake 仅 告诉您的编译器如何构建您的项目。它适用于任何平台

    作者是这样说的:

    CMake is an extensible, open-source system that manages the build process in an operating system and in a compiler-independent manner. Unlike many cross-platform systems, CMake is designed to be used in conjunction with the native build environment. Simple configuration files placed in each source directory (called CMakeLists.txt files) are used to generate standard build files (e.g., makefiles on Unix and projects/workspaces in Windows MSVC) which are used in the usual way. CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree. CMake also supports static and dynamic library builds. Another nice feature of CMake is that it generates a cache file that is designed to be used with a graphical editor. For example, when CMake runs, it locates files, libraries, and executables, and may encounter optional build directives. This information is gathered into the cache, which may be changed by the user prior to the generation of the native build files.