问题
1. cmake is a command from CMake software: preparation for build automation system; make and make install are commands from Make software: build automation system.
2. From reading this post, what I understand is that:
a. This "cmake and make" stuffs actually use g++ / gcc in its implementation. cmake and make stuffs are basically just tools in using g++ / gcc. Is that correct?
b. gcc / g++ are the compiler that do the actual work.
c. So I can just use gcc / g++ directly without using the make and CMake things?
3. According to this stackoverflow answer: CMake takes a CMakeList.txt file, and outputs it to a platform-specific build format, e.g., a Makefile, Visual Studio, etc.
However when I came across this openCV installation :
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
It executes cmake command in a directory where there is no CMakeLists.txt file. Can you explain and elaborate on this?
4. The usual steps that I've seen are: cmake, make, sudo make install.
I read this stackoverflow post, what I understand:
(i) make is for building the project.
(ii) make install is to copy the binary / executables to the installed directories.
a. So when we make, where are the result / binary files / executables stored at?
b. If we only run make without make install, does it mean that the files are not generated?
c. I came across this openCV tutorial on using openCV with GCC and CMake. It uses:
cd <DisplayImage_directory>
cmake .
make
Why doesn't it do make install as well?
5. In summary:
CMake takes CMakeList.txt file (which is cross platform) to generate a Makefile (which is specific to a platform).
I can just write Makefile manually and skip the CMake step. but it is better to do with the CMake step because it is cross platform, otherwise I have to rewrite the Makefile again if I change platform.
Make takes Makefile (which is generated by CMake or written manually) as a guide to compile and build. Make basically uses gcc / g++ or other compiler in its work. Make itself is just a tool for the compiler.
Make install put the result / executables into the install path
回答1:
CMake generates files for other build systems. These can be Makefiles, Ninja files or projects file for IDEs like Visual studio or Eclipse. The build files contains calls to compilers like GCC, Clang or cl.exe. If you have several compilers installed, you can choose one.
All three parts are independent. The compiler, the build system and CMake.
It is easier to understand, when you have the history. People used their compiler. Over the time the added so many flags, that it was cumbersome to type them every time. So the put the calls in a script. From that the build systems (Make, Ninja) evolved.
The people wanted to support multiple platforms, compilers, scenarios and so on and the build system files became hard to maintain and their use was error-prone. That's the reason people invented meta build system that create the files for the actual build system. Examples are Autotools or CMake.
- Yes
- CMake does not use your compiler, make does not implement it, but it calls (uses) the compiler.
- The CMakeLists.txt file should be in the parent directory of
release. The last argument of the CMake call indicates the path were the CMakeLists.txt file is located. - Right, make generates the file in the build directory. In your example from 3.
releaseis the build directory. You can find all the generated files and use them. Installing is optional, especially if you want to develop the software, you are not installing it. - Try writing Makefiles for a large project and you will see how much work it is. But yes, everything in 5 is right.
来源:https://stackoverflow.com/questions/39761924/understanding-roles-of-cmake-make-and-gcc