0

I was working with CMake. I have seen many CMake files and found there is a different release flag value set.

In one file I found: set(CMAKE_CXX_FLAGS_RELEASE "-O3")

In another: set(CMAKE_CXX_FLAGS_RELEASE "-O2")

and in other I found: set(CMAKE_CXX_FLAGS_RELEASE "-O1")

Please let me know what is the exact difference between these flags values? Can I use any one?

sachinsaini
  • 53
  • 1
  • 10
  • 2
    Those flags are not CMake-specific, but compiler-specific. See GCC manual for details (Clang uses the same flags, but lacks a good manual). TL;DR: O3 is the most optimized (aka the fastest, supposedly). – HolyBlackCat Feb 26 '22 at 16:24
  • There are many questions on Stack Overflow about difference between `O` flags. You could google them e.g. with https://www.google.com/search?q=gcc+difference+o+flags+site:stackoverflow.com. This search will find the [duplicate question](https://stackoverflow.com/questions/6454415/whats-the-difference-between-o3-and-o2-flags-that-man-gcc-says-o3-adds-to) too. – Tsyvarev Feb 26 '22 at 19:00

1 Answers1

1

You can read about those flags here

And shortly -O0, -O1, -O2, -O3 differ with the optimization level at the compile time. -O3 includes optimizations which are specified by -O2. And -O2 includes optimizations which are specified by -O1.

In your projects you can use any of those. You can even use no one of those flags (by default compiler uses -O0 flag). But in the university I was taught to use -O2 or -O3.

  • As **HolyBlackCat** said, gcc and clang use the same -O flags. And you can acquire detailed description with a gcc documentation. I couldn't get any description with a clang documentation – Kirill Rudnev Feb 26 '22 at 16:52