Visual Studio), the configuration type must be specified with the -C flag. Rebuild the application and then cd to the binary directory and run the ctest executable: ctest -N and ctest -VV. # configure a header file to pass some of the CMake settingsĬonfigure_file(TutorialConfig.h.in TutorialConfig.h) Option(USE_MYMATH "Use tutorial provided math implementation" ON) With CPack.The contens of CMakeLists.txt: cmake_minimum_required(VERSION 3.10) To create platform specific installers as described in Chapter Packaging That support binary installations and package management features asįound in cygwin, debian, RPMs etc. In this example we will be building installation packages The install we did previously in section Installing and Testing (Stepģ), where we were installing the binaries that we had built from the We want to provide both binary and sourceĭistributions on a variety of platforms. Next suppose that we want to distribute our project to other people so Install ( FILES MathFunctions.h DESTINATION include) Building an Installer (Step 6) Install ( TARGETS MathFunctions DESTINATION bin) #define a macro to simplify adding tests, then use it macro (do_test arg result)Īdd_test (TutorialComp $/Table.h) If you wanted to addĪ lot of tests to test different input values you might consider When an incorrect number of arguments are provided. Square root is what it should be and that the usage message is printed PASS_REGULAR_EXPRESSION test property to verify that the output of the Not segfault or otherwise crash, and has a zero return value. The first test simply verifies that the application runs, does Set_tests_properties (TutorialUsage PROPERTIES PASS_REGULAR_EXPRESSION "Usage.*number")Īfter building one may run the "ctest" command line tool to run the # does the usage message work? add_test (TutorialUsage Tutorial) Set_tests_properties (TutorialSmall PROPERTIES PASS_REGULAR_EXPRESSION "0.0001 is 0.01") # does it handle small numbers add_test (TutorialSmall Tutorial 0.0001) Set_tests_properties (TutorialNegative PROPERTIES PASS_REGULAR_EXPRESSION "-25 is 0") # does it handle negative numbers add_test (TutorialNegative Tutorial -25) Set_tests_properties (TutorialComp25 PROPERTIES PASS_REGULAR_EXPRESSION "25 is 5") # does it sqrt of 25 add_test (TutorialComp25 Tutorial 25) # does the application run add_test (TutorialRuns Tutorial 25) ![]() Library into a subdirectory called MathFunctions. TheĮxecutable can then use this library instead of the standard square rootįunction provided by the compiler. Own implementation for computing the square root of a number. Now we will add a library to our project. The main changes are the inclusion of the TutorialConfig.h header fileĪnd printing out a version number as part of the usage message. Std::cout << "The square root of " << inputValue << " is " << outputValue << std::endl Std::cout << "Usage: " << argv << " number " << std::endl Ĭonst double outputValue = sqrt(inputValue) " << Tutorial_VERSION_MAJOR << std::endl Std::cout << argv << " Version " << Tutorial_VERSION_MAJOR << ". # include "TutorialConfig.h " int main ( int argc, char *argv) A simple program that computes the square root of a number Source code for tutorial.cxx will compute the square root of a numberĪnd the first version of it is very simple, as follows: Upper, lower, and mixed case commands are supported by CMake. Note that this example uses lower case commands in the CMakeLists.txtįile. This will be the starting point for our tutorial. The most basic project is an executable built from source code files.įor simple projects a two line CMakeLists.txt file is all that is Manual pages for an overview of CMake concepts and source tree See also the introductory sections of the Subdirectory containing a complete copy of the tutorial for that step. ![]() This tutorial can be found in theĭirectory of the CMake source code tree. Separate issues but seeing how they all work together in an example Many of these topics have been introduced Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | Step 6 | Step 7īelow is a step-by-step tutorial covering common build system use cases Personnaly I found original tutoria outdated and uncomplete, after completing it before downloading original sources, with mediocrete results, I have decided to update it and consolidate in my repository.
0 Comments
Leave a Reply. |