cmake

 CMake是个好东西
相比起繁杂难记的autotools,CMake真是简单。
网址:
http://www.cmake.org
文档:
http://www.cmake.org/HTML/Documentation.html

假定项目为ProjectTest。项目结构如下:
src   放置源文件(*.h *.cpp),具体为
src/dira
src/dirb
src/dirc
bin   放置编译后的可执行程序
A.so B.a   第三方库

CMakelists.txt(放根目录下)可以这样写:

#项目名称
PROJECT (ProjectTest)

#头文件路径
INCLUDE_DIRECTORIES(
    src/dira
    src/dirb
    src/dirc
    )

#表示cpp文件列表的变量,如${DIRA_SRCS}代表src/dira目录下的所有源文件
AUX_SOURCE_DIRECTORY(src/dira DIRA_SRCS)
AUX_SOURCE_DIRECTORY(src/dirb DIRB_SRCS)
AUX_SOURCE_DIRECTORY(src/dirc DIRC_SRCS)

#设置变量${TEST_SRCS}
SET(TEST_SRCS
    ${DIRA_SRCS}
    ${DIRB_SRCS}
    ${DIRC_SRCS}
    )

#需要链接的第三方库
SET(LIBRARYS
    A.so
    B.a
    )

#添加可执行文件生成任务
ADD_EXECUTABLE(bin/test ${TEST_SRCS}})

#添加链接库
TARGET_LINK_LIBRARIES(bin/test ${LIBRARYS})


运行cmake CMakelists.txt,生成一份pp的Makefile文件--非常愉快的使用体验。




cmake version 2.4-patch 6
------------------------------------------------------------------------------
Name

  cmake - Cross-Platform Makefile Generator.

------------------------------------------------------------------------------
Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>

The "cmake" executable is the CMake command-line interface.  It may be used
to configure projects in scripts.  Project configuration settings may be
specified on the command line with the -D option.  The -i option will cause
cmake to interactively prompt for such settings.

CMake is a cross-platform build system generator.  Projects specify their
build process with platform-independent CMake listfiles included in each
directory of a source tree with the name CMakeLists.txt.  Users build a
project by using CMake to generate a build system for a native tool on their
platform.

------------------------------------------------------------------------------
Command-Line Options

  -C <initial-cache>
       Pre-load a script to populate the cache.

       When cmake is first run in an empty build tree, it creates a
       CMakeCache.txt file and populates it with customizable settings for
       the project.  This option may be used to specify a file from which to
       load cache entries before the first pass through the project's cmake
       listfiles.  The loaded entries take priority over the project's
       default values.  The given file should be a CMake script containing
       SET commands that use the CACHE option, not a cache-format file.

  -D <var>:<type>=<value>
       Create a cmake cache entry.

       When cmake is first run in an empty build tree, it creates a
       CMakeCache.txt file and populates it with customizable settings for
       the project.  This option may be used to specify a setting that takes
       priority over the project's default value.  The option may be repeated
       for as many cache entries as desired.

  -G <generator-name>
       Specify a makefile generator.

       CMake may support multiple native build systems on certain platforms.
       A makefile generator is responsible for generating a particular build
       system.  Possible generator names are specified in the Generators
       section.

  -E
       CMake command mode.

       For true platform independence, CMake provides a list of commands that
       can be used on all systems.  Run with -E help for the usage
       information.

  -i
       Run in wizard mode.

       Wizard mode runs cmake interactively without a GUI.  The user is
       prompted to answer questions about the project configuration.  The
       answers are used to set cmake cache values.

  -L[A][H]
       List non-advanced cached variables.

       List cache variables will run CMake and list all the variables from
       the CMake cache that are not marked as INTERNAL or ADVANCED.  This
       will effectively display current CMake settings, which can be then
       changed with -D option.  Changing some of the variable may result in
       more variables being created.  If A is specified, then it will display
       also advanced variables.  If H is specified, it will also display help
       for each variable.

  -N
       View mode only.

       Only load the cache.  Do not actually run configure and generate
       steps.

  -P <file>
       Process script mode.

       Process the given cmake file as a script written in the CMake
       language.  No configure or generate step is performed and the cache is
       not modified.

  --graphviz=[file]
       Generate graphviz of dependencies.

       Generate a graphviz input file that will contain all the library and
       executable dependencies in the project.

  --debug-trycompile
       Do not delete the try compile directories..

       Do not delete the files and directories created for try_compile calls.
       This is useful in debugging failed try_compiles.

  --debug-output
       Put cmake in a debug mode.

       Print extra stuff during the cmake run like stack traces with
       message(send_error ) calls.

  --help-command cmd [file]
       Print help for a single command and exit.

       Full documentation specific to the given command is displayed.

  --help-command-list [file]
       List available listfile commands and exit.

       The list contains all commands for which help may be obtained by using
       the --help-command argument followed by a command name.  If a file is
       specified, the help is written into it.

  --help-module module [file]
       Print help for a single module and exit.

       Full documentation specific to the given module is displayed.

  --help-module-list [file]
       List available modules and exit.

       The list contains all modules for which help may be obtained by using
       the --help-module argument followed by a module name.  If a file is
       specified, the help is written into it.

  --copyright [file]
       Print the CMake copyright and exit.

       If a file is specified, the copyright is written into it.

  --help
       Print usage information and exit.

       Usage describes the basic command line interface and its options.

  --help-full [file]
       Print full help and exit.

       Full help displays most of the documentation provided by the UNIX man
       page.  It is provided for use on non-UNIX platforms, but is also
       convenient if the man page is not installed.  If a file is specified,
       the help is written into it.

  --help-html [file]
       Print full help in HTML format.

       This option is used by CMake authors to help produce web pages.  If a
       file is specified, the help is written into it.

  --help-man [file]
       Print a UNIX man page and exit.

       This option is used by the cmake build to generate the UNIX man page.
       If a file is specified, the help is written into it.

  --version [file]
       Show program name/version banner and exit.

       If a file is specified, the version is written into it.

------------------------------------------------------------------------------
Generators

The following generators are available on this platform:

  Borland Makefiles
       Generates Borland makefiles.


  MSYS Makefiles
       Generates MSYS makefiles.

       The makefiles use /bin/sh as the shell.  They require msys to be
       installed on the machine.

  MinGW Makefiles
       Generates a make file for use with mingw32-make.

       The makefiles generated use cmd.exe as the shell.  They do not require
       msys or a unix shell.

  NMake Makefiles
       Generates NMake makefiles.


  Unix Makefiles
       Generates standard UNIX makefiles.

       A hierarchy of UNIX makefiles is generated into the build tree.  Any
       standard UNIX-style make program can build the project through the
       default make target.  A "make install" target is also provided.

  Visual Studio 6
       Generates Visual Studio 6 project files.


  Visual Studio 7
       Generates Visual Studio .NET 2002 project files.


  Visual Studio 7 .NET 2003
       Generates Visual Studio .NET 2003 project files.


  Visual Studio 8 2005
       Generates Visual Studio .NET 2005 project files.


  Visual Studio 8 2005 Win64
       Generates Visual Studio .NET 2005 Win64 project files.


  Watcom WMake
       Generates Watcom WMake makefiles.


------------------------------------------------------------------------------
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值