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:
- $> Ccmake Directory
- $> CMake Directory
- $> 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
- #project Name
- PROJECT(Test_math)
- #head file path
- Include_directories(
- Include
- )
- #source Directory
- Aux_source_directory(src dir_srcs)
- #set environment variable
- SET(Test_math
- ${Dir_srcs}
- )
- #add executable file
- Add_executable(.. /bin/bin ${test_math})
- #add link Library
- 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:
- #include <stdio.h>
- #include ". /include/a.h "
- int main()
- {
- double b=25.0;
- double a=0.0;
- A=get_sqrt(b);
- printf ("A is%LF, B is%lf\ n", A, A, a, a);
- return 0;
- }
/src/a.c
- #include ". /include/a.h "
- Double get_sqrt(double var1)
- {
- return sqrt(var1);
- }
/include/a.h
#ifndef a_file_header_inc
- #define A_file_header_inc
- #include <math.h>
- Double get_sqrt(double var1);
- #endif
Place the CMakeLists.txt in the current directory and execute the CMakeLists.txt
- $> CMake.
- $> 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.