Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181197
  • 博文数量: 40
  • 博客积分: 2036
  • 博客等级: 大尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-12 22:39
文章分类

全部博文(40)

文章存档

2013年(3)

2012年(1)

2011年(18)

2010年(18)

分类: C/C++

2011-02-20 15:44:18

这是从别处转载的一篇文章,不过这篇文章还是很难找到的。现把原文转载至此,是英文的,等有空再翻过来。
Build with CMake in Eclipse

by John McGehee on January 17, 2011

can create a wide variety of build systems.  CMake can even create an Eclipse project, but that did not work for me.  In the , I use CMake to create ordinary , and build using those. Here’s how.

The conventional approach to is to create an external tool in Eclipse. However, a Make Target is simpler, and because it is stored in the Eclipse .project file, you can check it into your version control system and it will work in every one of your working copies, on every computer.

Create Eclipse Make Targets

Create a Make Target for each configuration that you want to build.  Here I assume that you have the usual Release and Debug configurations:

  • Display the Make Target window using the Window > Show View > Make Target menu command. It should appear on the right, with the Outline window.
  • Select the folder for the project for which you want to add CMake.  CMake will run with this folder as its working directory.
  • Right click on the folder and select New from the context menu.  The Create Make Target dialog will appear.
    • Type Target name CMake Release
    • In Make target, deselect Same as the target name, and make sure that the Make target field is empty
    • In Build Command, deselect Use builder settings and set the Build command to

      cmake -E chdir Release/ cmake -G "Unix Makefiles" ../

    • Click OK
  • Repeat, this time for Target name CMake Debug, and Build command,

    cmake -E chdir Debug/ cmake -DCMAKE_BUILD_TYPE:STRING=Debug -G "Unix Makefiles" ../

  • Create the Release/ and Debug/ directories

    mkdir Release Debug

Eclipse Make Targets Can Run Any Command

The Make Target feature of Eclipse CDT can be used to execute any command, not just build commands.  Take advantage of the CMake -E command to make your Make Targets portable across platforms.  The standard output from the command appears in the Eclipse Console window.

Note that the Build command field accommodates only a single command. That is, a semicolon separated list of multiple commands does not work.

Set Up the Eclipse CDT Builder

Next, set up the CDT builder to run the Makefiles that CMake builds.

  • Right click on a CDT project.  In the context menu, select Properties.
  • On the left, select C/C++ Build
    • Set Configuration to Release
      • Choose the Builder Settings tab
        • Deselect Use default build command
        • Specify the Build command:

          make -C ${ConfigName}

        • Deselect Generate Makefiles automatically
        • Make the Build directory field blank
        • The form should appear as shown below:

          Click to Enlarge

      • Choose the Behavior tab
        • Select Build (Incremental build) and specify the target name all
        • Select Clean and specify the target name clean
        • The form should appear as shown below:

          Click to Enlarge

    • Set Configuration to Debug
      • Choose the Builder Settings tab
        • Set all values exactly the same as the Release configuration
      • Choose the Behavior tab
        • Set all values exactly the same as the Release configuration
  • Click OK
Build the Project

Use CMake to create an out-of-source GNU Make build system:

  • In the Make Targets window, double click on CMake Release or CMake Debug to create the GNU Make build system in Release/ or Debug/, respectively
  • If necessary, edit your CMakeLists.txt control files
  • Delete the contents of the corresponding build directory. For example:

    rm -r Release/*

    and repeat.

    Actually, for minor edits to your CMakeLists.txt control files, you need not delete the build directory. However, I cannot tell you exactly where the threshold for “minor edits” is.

Now, build the project the usual way with Eclipse:

  • Select the configuration to build (Release of Debug) with the Project > Build Configurations > Set Active command
  • Build with the Project > Build Project command
  • Edit your source code files, and repeat
原文地址:

阅读(9581) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~