A very strange cmake.

Source: Internet
Author: User

CMake is a cross-platform installation (compilation) tool that can be used to describe the installation of all platforms (the compilation process) with simple statements. He is able to output a variety of Makefile or project files that can test the C + + features supported by the compiler, similar to the Automake under UNIX. Only the CMake configuration file is named CmakeLists.txt. Cmake does not directly construct the final software, but rather produces standard constructs such as Unix's Makefile or Windows Visual C + + projects/workspaces, which are then used in a general constructive fashion. This makes it possible for developers familiar with an integrated development environment (IDE) to build their software in a standard way, and the ability to use the native building systems of each platform is the difference between CMake and scons and other similar systems.

CMake can compile the source code, make the library, generate the adapter (wrapper), and can construct the execution file in any order. CMake supports In-place construction (binary files and source code in the same directory tree) and out-of-place constructs (binary files in other directories), so it is easy to construct multiple binaries from the same source directory tree. CMake also supports the construction of static and dynamic libraries. The name "CMake" is the abbreviation for "Cross platform make". Although the name contains "make", the common "make" system on CMake and UNIX is separate and more advanced. HistoryCMake is to address the Insight Segmentation and Registration Toolkit (ITK) under the Visible Human Project project funded by the National Medical Library of the United States The need for cross-platform construction of software was created, and its design was influenced by the Pcmaker developed by Ken Martin. Pcmaker originally was to support Visualization toolkit This open source three-dimensional graphics and visual system only appeared, today VTK also adopted cmake. At the time of design CMake, Kitware's bill Hoffman used some of Pcmaker's most important ideas, plus more of his own ideas, to integrate some of the GNU construction system's functions. CMake's initial practice was made in 2000, with rapid progress in the early 2001, and many of the improvements came from other developers integrating CMake into their systems, for example, the VXL community, which uses cmake as a building environment, has contributed many important functions, Brad King has added several features to support cable and Gcc-xml's automated packaging tools, while the Research and Development division of the singular company is used in the internal testing system dart, and there are features to enable VTK to transition to CMake and support ("Los Alamos National Laboratory" & "Los Alamos National Laboratory") Advanced Computing Lab's parallel vision system ParaView and added. Configuration filesA configuration file is a cmake script written in a special programming language dedicated to building software. built-in C language, C + +, Fortran, Java automatic dependency analysis function. support Swig, Qt, FLTK through the CMake scripting language. built-in to Microsoft Visual Studio. NET and past versions of Visual Studio can produce documents with the suffix. DSP,. sln, and. vcproj. use traditional time tags to detect changes in file contents. Support Parallel construction (simultaneous construction on multiple computers)Cross-platform compilation on many operating systems, including Linux, POSIX compliant systems (AIX, *BSD, HP-UX, IRIX, Mingw/msys, Solaris Systems), Mac OS x, and Microsoft Windows 95/98/nt/2000 /xp and so on. generates a global dependency graph that can be used for Graphviz. has been integrated with software testing and release tools such as Dart, CTest and Cpack.

CMake How to useSoftware InstallationDownload CMake Windows version InstallationRun EXE directly installation of Linux version:Install cmakecmake-*.*.*tar.gz for downloaded source package tar xvf cmake-*.*.*.tar.gzcd cmake-*.*.*./bootstrapmakemake Install if CMake is already installed, To install a new version: CD cmake-*.*.*cmake. Makemake install how to use

All of the CMake statements are written in a file called: CMakeLists.txt. When the CMakeLists.txt file is determined, the associated variable value can be configured with the Ccmake command. This command must point to the directory where the CMakeLists.txt is located. after the configuration is complete, apply the CMake command to generate the appropriate makefile (under the UNIX like system) or the project file (specified with the appropriate programming tools under window).

Its basic operating procedures are:

    1. $> Ccmake Directory
    2. $> CMake Directory
    3. $> make

Where directory is the directory where CMakeList.txt resides;

    • The first statement is used to configure the compilation options, such as the Vtk_dir directory, the general step does not need to configure, directly execute the second statement, but when there is an error, it is necessary to consider the configuration, this step is really useful;
    • The second command is used to generate makefile files based on CMakeLists.txt ;
    • The third command is used to execute the makefile file, compile the program, and generate the executable file ;
The writing of CMakeLists.txt

CMake implementation is so simple, the difficulty lies in how to write CMakeLists.txt files, the following example of a simple introduction to CMakeLists.txt writing, see the following CMakeLists.txt

#project nameproject (test_math) #head file pathinclude_directories (include) #source Directoryaux_source_ DIRECTORY (src dir_srcs) #set  environment Variableset (Test_math${dir_srcs}) #set  extern  Librariesset (librarieslibm.so) #add executable fileadd_executable (.. /bin/bin ${test_math}) #add link librarytarget_link_libraries (.. /bin/bin ${libraries})

or use the following CMakeLists.txt

  1. #project Name
  2. PROJECT(Test_math)
  3. #head file path
  4. Include_directories(
  5. Include
  6. )
  7. #source Directory
  8. Aux_source_directory(src dir_srcs)
  9. #set environment variable
  10. SET(Test_math
  11. ${Dir_srcs}
  12. )
  13. #add executable file
  14. Add_executable(.. /bin/bin ${test_math})
  15. #add link Library
  16. Target_link_libraries(.. /bin/bin m)

This is the CMakeLists.txt of a program that tests mathematical functions, followed by "#" as the contents of a comment, and CMake commands are all uppercase

Line 2nd specifies that the generated project is named Test_math

Line 4th specifies that the header file directory is include

Line 8th specifies that the source file directory is SRC and assigns it to the environment variable Dir_srcs

Line 10th sets the value of the environment variable Test_math to the value of the environment variable DIR_SRCS, which is used here to show how environment variables are assigned to an environment variable

The 14th line is to assign the math library to the environment variable libraries, which, of course, can be used without this environment variable, and directly using the library name later

Line 18th is used to specify the build file to compile all the files in the environment variable Test_math directory. Executable file bin in the/bin directory

Line 20th specifies: /bin/bin the link library at execution time is the value of the environment variable libraries-libm.so

The source file is given below
/SRC/MAIN.C:

  1. #include <stdio.h>
  2. #include ". /include/a.h "
  3. int main()
  4. {
  5. double b=25.0;
  6. double a=0.0;
  7. A=get_sqrt(b);
  8. printf ("A is%LF, B is%lf\ n", A, A, a, a);
  9. return 0;
  10. }

/src/a.c

    1. #include ". /include/a.h "
    2. Double get_sqrt(double var1)
    3. {
    4. return sqrt(var1);
    5. }

/include/a.h

#ifndef a_file_header_inc

    1. #define A_file_header_inc
    2. #include <math.h>
    3. Double get_sqrt(double var1);
    4. #endif

Place the CMakeLists.txt in the current directory and execute the CMakeLists.txt

    1. $> CMake.
    2. $> make

You can build the executable file, the bin file under directory/bin, and run to see if it works the way you want it to.

Application software Bullet Physics Enginekde (starting with version 4) the Visualization Toolkit ( VTK) Insight Segmentation and Registration Toolkit (ITK) Paraviewdevil-open Image Libraryopenscenegraphscribusdrishtipvpgnchickenparadiseo Quantum GIS OPENCVPclfast Light Toolkit (FLTK) after MySql 5.58 version clion

Reference

Baidu Encyclopedia CMake.

Hands-free think that year ([email protected]), CMake profile

A very strange cmake.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.