Learning CMake: A Beginner's Guide Cmake Beginner S
User Manual: Pdf
Open the PDF directly: View PDF .
Page Count: 7
Download | |
Open PDF In Browser | View PDF |
cmake学习资料汇总 https://cgold.readthedocs.io/en/latest/overview.html Table of Contents 1. Introduction 2. Tutorial 1: Let's start with CMake 3. Build system 4. Compilation and properties 5. Commands and variables 6. Tutorial 2: Creating a simple project - SimpleCal 7. Modules and packages 8. Tutorial 3: Creating a project with CMake, Qt5 and OpenCV 9. Cross Compiling 10. Tutorial 4: Compiling a project with CMake in VS 2012 11. ctest 12. Tutorial 5: Testing with CMake and Google Testing Framework 13. cpack 14. Tutorial 6: Packaging SimpleCal 15. CMake's development 16. Tutorial 7: Create a simple plugin for CMake 17. Tutorial 8: Using CMake with Eclipse 18. Conclusion Introduction Recently, I've created a simple library in C++. I want to use CMake as the building system so it’s the time to learn a new tool. Summary Introduction Tutorial 1: Let's start with CMake Build system Compilation and properties Commands and variables Tutorial 2: Creating a simple project - SimpleCal Modules and packages Tutorial 3: Creating a project with CMake, Qt5 and OpenCV Cross Compiling Tutorial 4: Compiling a project with CMake in VS 2012 ctest Tutorial 5: Testing with CMake and Google Testing Framework cpack Tutorial 6: Packaging SimpleCal CMake's development Tutorial 7: Create a simple plugin for CMake Tutorial 8: Using CMake with Eclipse Conclusion Chapter 1: Let's start with CMake 1. What is CMake? From the CMake’s website: CMake is an extensible, open-source system that manages the build process in an operating system and in a compiler-independent manner. Unlike many cross-platform systems, CMake is designed to be used in conjunction with the native build environment. Simple configuration files placed in each source directory (called CMakeLists.txt files) are used to generate standard build files (e.g., makefiles on Unix and projects/workspaces in Windows MSVC) which are used in the usual way. CMake can generate a native build environment that will compile source code, create libraries, generate wrappers and build executables in arbitrary combinations. CMake supports in-place and out-of-place builds, and can therefore support multiple builds from a single source tree. CMake also supports static and dynamic library builds. Another nice feature of CMake is that it generates a cache file that is designed to be used with a graphical editor. For example, when CMake runs, it locates include files, libraries, and executables, and may encounter optional build directives. This information is gathered into the cache, which may be changed by the user prior to the generation of the native build files. In a short conclusion, CMake help you to manage and build your source codes effectively. If you have some troubles with gcc and Makefile, just move out to CMake. 2. Installation To install CMake in Linux, just simply do on your terminal # For Ubuntu $ sudo apt-get install cmake # For Redhat $ yum install cmake # For Mac OS X with Macports $ sudo port install cmake 3. Quick start So I assume that you know C++ and what the Makefile is. CMake will do the job of Makefile from now. Let start with a simple C++ program. // test.cpp #includeusing namespace std; int main(void) { cout << "Hello World" << endl; return(0); } And you saved it as , then to compile it in CMake you should create a txt file named test.cpp CMakeLists.txt # Specify the minimum version for CMake cmake_minimum_required(VERSION 2.8) # Project's name project(hello) # Set the output folder where your program will be created set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) # The following folder will be included include_directories("${PROJECT_SOURCE_DIR}") There is a list of CMake’s global varibales. You should know them. CMAKE_BINARY_DIR if you are building in-source, this is the same as 这个难道在 整个编译的 流程中永远 保持不变吗 CMAKE_SOURCE_DIR , otherwise this is the top level directory of your build tree CMAKE_SOURCE_DIR this is the directory, from which cmake was started, i.e. the top level source directory EXECUTABLE_OUTPUT_PATH set this variable to specify a common place where CMake should put all executable files (instead of CMAKE_CURRENT_BINARY_DIR ) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) LIBRARY_OUTPUT_PATH set this variable to specify a common place where CMake should put all libraries (instead of CMAKE_CURRENT_BINARY_DIR ) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) PROJECT_NAME the name of the project set by 包含了 PROJECT命令 的 CMakeLists.t xt文件所在的 目录是什 么。。。。。 ? 所以应该是 PROJECT_SOUR CE_DIR 目录 PROJECT_SOURCE_DIR PROJECT() command. 所以PROJECT目录的作用应该就是确定 PROJECT_SOURCE_DIR 目录 contains the full path to the root of your project source directory, i.e. to the nearest directory where the PROJECT() command Now, you have to compile the line into your CMakeLists.txt test.cpp CMakeLists.txt . The way to do this task is too simple. Add the following : add_executable(hello ${PROJECT_SOURCE_DIR}/test.cpp) Now, let build the source code with CMake. At this point, you will have the folder with the following files: $ ls test.cpp CMakeLists.txt contains To build your project hello , just do $ cmake -H. -Bbuild $ cmake --build build -- -j3 The first command will creates CMake configuration files inside folder program hello in bin build and the second one will generate the output folder. You should test your output: $ ./bin/hello Hello World Too simple, right? The source code of this sample project canbe found at CMakeLists.txt and test.cpp Chapter 2: CMake's build system
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Author : tuannguyen68 Create Date : 2014:12:18 09:40:23+00:00 Producer : calibre 2.12.0 [http://calibre-ebook.com] Modify Date : 2017:11:26 12:10:14+08:00 Description : This book is a collection of tutorials and posts about using the CMake tool. Title : Learning CMake: A beginner's guide Subject : Publisher : GitBook Creator : tuannguyen68 Language : en Metadata Date : 2014:12:18 09:40:23.206517+00:00 Timestamp : 2014:12:18 09:40:20.160323+00:00 Page Count : 7 Has XFA : NoEXIF Metadata provided by EXIF.tools