The CMakeLists.txt file for this project in Listing 3 is only slightly different than that in Listing 2 above: Listing 3: The Multi-directory Project CMakeLists.txt file I have also created a build directory (which is currently empty) that is used to contain the final binary executable and any temporary files that are required for the build. h) are placed in the include directory and that the source files (. You can see in this example that any header files (. The tree utility program displays below the structure of the example project (note: this student test project is available in the GitHub repository that is described tree In this example, a project with a typical directory structure is used. These Makefiles are then individually invoked by the Makefile in the parent directory.ĬMake can be very useful in this situation. Makefiles become more verbose when there are sub-directories present - in fact, it is usual practice to place an individual Makefile in each sub-directory. We can now examine more complex CMake examples.Īs your project grows, it is likely that you will organize it into sub-directories. It is important though, because it explains the basic operation of CMake. It works! However, this process is a somewhat excessive way to just build the HelloWorld.cpp program. Building CXX object CMakeFiles/hello.dir/ Once the Makefile has been created, the make command can be used to build the make # The shell in which to execute make rules. # Generated by "Unix Makefiles" Generator, CMake Version 2.8 rw-r-r- 1 molloyd molloyd 4811 Apr 1 01:52 more Makefile Do not make edits to this Makefile, as any edits will be overwritten the next time that the cmake utility is lsĬMakeCache.txt CMakeFiles CMakeLists.txt Makefile cmake_install.cmake ls -l Makefile Build files have been written to: /home/molloyd/exploringBB/extras/cmake/helloworldĬMake identified the environment settings for the Linux device and created the Makefile for this project, which can be viewed. Check for working CXX compiler: /usr/bin/c++ - works Check for working CXX compiler: /usr/bin/c++ Check for working C compiler: /usr/bin/gcc - works Check for working C compiler: /usr/bin/gcc The CXX compiler identification is GNU 4.6.3 The C compiler identification is GNU 4.6.3 Now you are ready to build the Hello World project using CMake - execute the cmake command and pass it the directory that contains the source code and the CMakeLists.txt file - in this case “. The project code is in the GitHub repository directory, where you will see only the two files described in Listings 1 and 2 cd ls For example, under sudo apt-get install cmake -version To build the project, first test that you have CMake installed, and if not, install it using the package manager that is used by your flavor of Linux. The first argument to the add_executable() function is the name of the executable to be built, and the second argument is the source file from which to build the executable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |