Doctest Cmake

Aug 08, 2020 We declare two targets, one for doctest and one for range-v3. CMake downloads both libraries via their git repository. The parameter GITTAG specifies the commit in the dependencies history we use. The preferred method for generating the build tree is to do an out-of-source build, i.e. Create a directory somewhere outside of your source tree and execute cmake from there. Even creating a 'build' directory in the root of your project and executing cmake. Would provide a clean structure which won't interfere with your source tree. The unit tests use doctest unit testing framework, which I currently do not include in the project. How should my main CMakeLists.txt file and the unit test CMakeLists.txt files look like to: make clients use C17 (or later) language standard as the library uses std::optional and the like. Option (DOCTESTWITHMAININSTATICLIB 'Build a static lib (cmake target) with a default main entry point' ON) option (DOCTESTNOINSTALL 'Skip the installation process' OFF ) option (DOCTESTUSESTDHEADERS 'Use std headers' OFF ).


Cross-platform CMake can generate a wide variety of build systems. The CMake 2.8 project generator for Eclipse does not work, so you must create the project and configure it to build with GNU Make. Here’s how to do it on Linux.

Create an Eclipse Project

Create an Eclipse CDT (C/C++ Development Tooling) project using the File > New > C++ Project command for your C++ project, or File > New > C Project for a C project.

Do not create the project using the CMake Eclipse project generator.

Create Eclipse Make Targets

Tip: The Make Target feature of Eclipse CDT can be used to execute any command, not just build commands. The standard output from the command appears in the Eclipse Console window.

Doctest Cmake

Take advantage of the CMake -E command to create cross-platform Make Targets. Note that the Build command field accommodates only a single command–a semicolon separated list of multiple commands does not work.

The conventional approach to using CMake with Eclipse 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 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 nameCMake 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' ./ -DCMAKE_BUILD_TYPE:STRING=Release

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

    cmake -E chdir Debug/ cmake -G 'Unix Makefiles' ./ -DCMAKE_BUILD_TYPE:STRING=DebugSimple comic for mac.

  • Create the Release/ and Debug/ directories

    mkdir Release Debug

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:
      • 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 generate an out-of-source GNU Make build system:

  • In the Make Targets window, double click on CMake Release or CMake Debug to generate 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 what 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

This article was originally published by John McGehee, Voom, Inc. under the CC BY 3.0 license. Changes have been made.

Reference Documentation

  • CMake 3.20 Documentation (latest), QtHelp (latest)
  • CMake 3.19 Documentation, QtHelp
  • CMake 3.18 Documentation, QtHelp
  • CMake 3.17 Documentation, QtHelp
  • CMake 3.16 Documentation, QtHelp
  • CMake 3.15 Documentation, QtHelp
  • CMake 3.14 Documentation, QtHelp
  • CMake 3.13 Documentation, QtHelp
  • CMake 3.12 Documentation, QtHelp
  • CMake 3.11 Documentation, QtHelp
  • CMake 3.10 Documentation, QtHelp
  • CMake 3.9 Documentation, QtHelp
  • CMake 3.8 Documentation, QtHelp
  • CMake 3.7 Documentation, QtHelp
  • CMake 3.6 Documentation, QtHelp
  • CMake 3.5 Documentation, QtHelp
  • CMake 3.4 Documentation, QtHelp
  • CMake 3.3 Documentation, QtHelp
  • CMake 3.2 Documentation, QtHelp
  • CMake 3.1 Documentation, QtHelp
  • See older versions below.
  • See development versions: master, stage (master + staged MRs)

Doctest Cmake Error

Training Materials

  • Mastering CMake is a book published by Kitware.
  • CMake Training Courses are provided by Kitware.
  • See the cmake-buildsystem(7) and cmake-language(7) manual pages for an overview of CMake concepts and source tree organization.


  • The CMake Discourse Forum is a place to ask for help with CMake.

Kitware Source

The Kitware Source is a quarterly newsletter for developers designed to deliver detailed technical articles, information on recent releases and upcoming changes related to Kitware’s open source products. This includes information on CMake and Kitware’s Quality Software Process (see example articles below).

Subscribing to the Source is free. To be added to the Source mailing list, please contact the editor at [email protected], be sure to include your full name and postal mailing address in the email.

Doctest Cmake Link

Older Reference Documentation

The following pre-3.0 reference manuals are available online:

Doctest Cmake Install

  • cmake(1):2.8.12, 2.8.11, 2.8.10, 2.8.9, 2.8.8, 2.8.7, 2.8.6, 2.8.5, 2.8.4, 2.8.3, 2.8.2, 2.8.1, 2.8.0, 2.6
  • ctest(1):2.8.12, 2.8.11, 2.8.10, 2.8.9, 2.8.8, 2.8.7, 2.8.6, 2.8.5, 2.8.4, 2.8.3, 2.8.2, 2.8.1, 2.8.0, 2.6
  • cpack(1):2.8.12, 2.8.11, 2.8.10, 2.8.9, 2.8.8, 2.8.7, 2.8.6, 2.8.5, 2.8.4, 2.8.3, 2.8.2, 2.8.1, 2.8.0, 2.6