[译]CMake构建管理器
By robot-v1.0
本文链接 https://www.kyfws.com/applications/the-cmake-build-manager-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1461 个词 阅读量 0[译]CMake构建管理器
原文地址:https://www.codeproject.com/Articles/4292/The-CMake-Build-Manager
原文作者:William A. Hoffman
译文由本站 robot-v1.0 翻译
前言
CMake is a cross-platform open-source build tool that generates Visual Studio 6, 7 and 7.1 IDE project files. It also generates makefiles for NMake, Borland, Mac OSX, Linux, and most UNIX systems.
CMake是一个跨平台的开源构建工具,可生成Visual Studio 6\7和7.1 IDE项目文件.它还为NMake,Borland,Mac OSX,Linux和大多数UNIX系统生成makefile.
- 下载Windows Installer-1.44 MB(Download widnows installer - 1.44 MB) 下载Unix二进制文件:(Download Unix binaries:) http://www.cmake.org/HTML/Download.html(http://www.cmake.org/HTML/Download.html)
介绍(Introduction)
CMake是跨平台构建经理.开发它是为了支持描述在所有平台上均可使用的构建过程的单个输入.但是,它无需接管构建过程,而只是为本机构建工具生成输入. CMake可以为UNIX和Windows生成Microsoft项目文件和各种Makefile格式.在Visual Studio 6\7和7.1都具有不同的项目格式的情况下,CMake可用于维护对项目中所有三个版本的支持.除了移植构建系统之外,CMake还可以用于测试编译器是否支持C ++功能. CMake支持完整的try/compile try/run系统,就像UNIX上的autoconf一样.这将使您的代码在可用时充分利用语言的受支持功能.(CMake is a cross platform build manager. It was developed to support a single input describing a build process that works on all platforms. However, instead of taking over the build process, it simply generates input for the native build tools. CMake can generate microsoft project files and various makefile formats for UNIX and Windows. With Visual Studio 6, 7, and 7.1 all having different project formats, CMake can be used to maintain support for all three versions in your project. In addition to porting the build system, CMake can be used to test the compiler for supported C++ features. CMake supports a full try/compile try/run system much like autoconf on UNIX. This will allow your code to take advantage of the supported features of the language as they become available.)
背景(Background)
CMake是一个开放源代码项目,该项目已经开发了三年.有关CMake的更多信息,请参见(CMake is an Open Source project that has been in develpment for the past three years. For more information about CMake, see) http://www.cmake.org/(http://www.cmake.org/) . CMake的完整源代码也可以从CMake主页下载.(. Full source code for CMake can be downloaded from the the CMake homepage as well.)
使用代码(Using the Code)
涉及三个目录.顶层目录有两个子目录,分别是./Demo和./Hello.在目录./Hello中,建立了一个库.在目录./Demo中,通过链接到库来构建可执行文件.总共创建了三个CMakeList.txt文件:每个目录一个.(There are three directories involved. The top level directory has two subdirectories called ./Demo and ./Hello. In the directory ./Hello, a library is built. In the directory ./Demo, an executable is built by linking to the library. A total of three CMakeList.txt files are created: one for each directory.)
第一个顶级目录包含以下CMakeLists.txt文件.(The first, top-level directory contains the following CMakeLists.txt file.)
# The name of our project is "HELLO". CMakeLists files in this project can
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
PROJECT(HELLO)
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually
# cause another cmake executable to run. The same process will walk through
# the project's entire directory structure.
SUBDIRS(Hello Demo)
# Create a library called "Hello" which includes the source file "hello.cxx".
# Any number of sources could be listed here.
ADD_LIBRARY(Hello hello.cxx)
# Make sure the compiler can find include files from our Hello library.
INCLUDE_DIRECTORIES(${HELLO_SOURCE_DIR}/Hello)
# Make sure the linker can find the Hello library once it is built.
LINK_DIRECTORIES(${HELLO_BINARY_DIR}/Hello)
# Add executable called "helloDemo" that is built from the source files
# "demo.cxx" and "demo_b.cxx".
ADD_EXECUTABLE(helloDemo demo.cxx demo_b.cxx)
# Link the executable to the Hello library.
TARGET_LINK_LIBRARIES(helloDemo Hello)
在顶层目录中执行CMake时,将处理CMakeLists.txt文件,然后进入列出的子目录.变量(包括路径,库路径等)被继承.根据系统的不同,将构建makefiles(Unix)或工作区/项目(MSVC).然后可以按通常的方式使用它们来构建代码.(CMake when executed in the top-level directory will process the CMakeLists.txt file and then descend into the listed subdirectories. Variables, include paths, library paths, etc. are inherited. Depending on the system, makefiles (Unix) or workspaces/projects (MSVC) will be built. These can then be used in the usual way to build the code.)
历史(History)
- 2003年11月1日-更新了下载(1 Nov 2003 - updated download)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 C++ VC6 WinXP Win2003 Windows Win2K Visual-Studio Dev 新闻 翻译