usr/bin/c++ -O3 -DNDEBUG -o CMakeFiles/hello.dir/ -c /tmp/cmaketest/foo.cpp usr/bin/c++ -O3 -DNDEBUG -o CMakeFiles/hello.dir/ -c /tmp/cmaketest/main.cpp With the Release build type, the options passed to the compiler are these: Of course, change “Release” with “Debug” for debug builds. To fix this you simply need to specify a build type in the CMakeLists.txt file, in this way: set(CMAKE_BUILD_TYPE Release)Īt the end of your CMakeLists.txt file. The build type is a feature most IDE have, it allows you to compile your program in “debug” mode, for easily single-stepping through it with a debugger, or in “release” mode, with speed optimization enabled. That’s because no build type has been specified to CMake. Now, if you’ve read my previous blog post on GCC’s compiler flags, you might probably not like what you see, since no optimization flag has been passed to GCC and as a result, your program won’t run as fast as it should. usr/bin/c++ CMakeFiles/hello.dir/ CMakeFiles/hello.dir/ -o hello usr/bin/c++ -o CMakeFiles/hello.dir/ -c /tmp/cmaketest/foo.cpp Building CXX object CMakeFiles/hello.dir/ usr/bin/c++ -o CMakeFiles/hello.dir/ -c /tmp/cmaketest/main.cpp Here is the relevant part of the printout: But if the goal is to see the compiler flags used, it is always possible to override this behaviour with the VERBOSE=1 option. By default CMake hides the options passed to the compiler, and displays a higher level status indicator with the build completion percentage together with the name of the file currently being built (a much more elegant solution than autoconf). The interesting thing here is the VERBOSE=1 option. To do so, it is possible to use the commands: mkdir build & cd build But let’s see exactly what CMake does to compile these files. The first CMakeLists.txt looked like this: cmake_minimum_required(VERSION 2.6)Īs already explained, it successfully creates an executable called “hello” using the main.cpp and foo.cpp source files. Now it’s time to explore the CMake syntax further. It’s not the first time I talk about CMake in this blog, for the introduction read here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |