Archived issue #0027417
Choose a Better Default Release Optimization Parameter for MinGW-w64
Description
In my opinion CMake is doing a bad job by proposing "-O3" as the default release optimization parameter for MinGW-w64. In my tests, the binaries become larger, but the speed is almost the same. (I have not done comparisons on Linux, there "-O3" might indeed be better than "-O2".) Also other build tools like qmake set the default optimization parameter to "-O2".
I would therefore propose to set the default release optimization parameter to "-O2", if the compiler is MinGW. Actually this parameter can easily be overwritten by the user, but this would mean proposing the optimization parameter that has been proven to be best at least in some cases.
I would therefore propose to set the default release optimization parameter to "-O2", if the compiler is MinGW. Actually this parameter can easily be overwritten by the user, but this would mean proposing the optimization parameter that has been proven to be best at least in some cases.
Steps to reproduce
Not necessary
Public activity
9 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Fri Apr 22 12:07:52 2016 +0200
0027417: Coose a Better Default Release Optimization Parameter for MinGW-w64
Forcing CMAKE_CXX_FLAGS_RELEASE to -O2 -DNDEBUG, if the compiler is MinGW-w64.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Fri Apr 22 12:07:52 2016 +0200
0027417: Coose a Better Default Release Optimization Parameter for MinGW-w64
Forcing CMAKE_CXX_FLAGS_RELEASE to -O2 -DNDEBUG, if the compiler is MinGW-w64.
Dear Benjamin,
It will be great if you replace "-O3" with "-O2" in such way, for example:
string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}")
if (IS_O3_CXX)
string (REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
else()
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
2. "FORCE" is not necessary for only one flag due to #0027319 issue will cover this omission.
It will be great if you replace "-O3" with "-O2" in such way, for example:
string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}")
if (IS_O3_CXX)
string (REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
else()
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
2. "FORCE" is not necessary for only one flag due to #0027319 issue will cover this omission.
Dear ibs,
thank you for the hint. Your solution looks nicer, I have done it the other way, since the variabled seemed not to be updated.
Still your code does not work here. I have added debug output, which leads to the following lines:
# Set default release optimization option to O2 instead of O3, since in
# some OCCT related examples, this gives significantly smaller binaries
# at comparable performace with MinGW-w64.
message ("Old CMAKE_CXX_FLAGS_RELEASE variable: ${CMAKE_CXX_FLAGS_RELEASE}")
string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}")
message ("IS_O3_CXX: ${IS_O3_CXX}")
if (IS_O3_CXX)
message("Found -O3 string")
string (REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
message ("New variable: ${CMAKE_CXX_FLAGS_RELEASE}")
else()
message ("Did not find -O3 string")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
The output is
Old CMAKE_CXX_FLAGS_RELEASE variable: -O3 -DNDEBUG
IS_O3_CXX:
Did not find -O3 string
which shows that something did not work correctly, but I could not figure out what it is. Can you?
Thanks,
Benjamin
thank you for the hint. Your solution looks nicer, I have done it the other way, since the variabled seemed not to be updated.
Still your code does not work here. I have added debug output, which leads to the following lines:
# Set default release optimization option to O2 instead of O3, since in
# some OCCT related examples, this gives significantly smaller binaries
# at comparable performace with MinGW-w64.
message ("Old CMAKE_CXX_FLAGS_RELEASE variable: ${CMAKE_CXX_FLAGS_RELEASE}")
string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}")
message ("IS_O3_CXX: ${IS_O3_CXX}")
if (IS_O3_CXX)
message("Found -O3 string")
string (REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
message ("New variable: ${CMAKE_CXX_FLAGS_RELEASE}")
else()
message ("Did not find -O3 string")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
endif()
The output is
Old CMAKE_CXX_FLAGS_RELEASE variable: -O3 -DNDEBUG
IS_O3_CXX:
Did not find -O3 string
which shows that something did not work correctly, but I could not figure out what it is. Can you?
Thanks,
Benjamin
Benjamin,
there is a doubt that ' string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}") ' contains "zero" but "O" letter. It's my fault due to the previous my example was a speculative. Could you replace "-03" with "-O3" and check again?
there is a doubt that ' string (REGEX MATCH "-03" IS_O3_CXX "${CMAKE_CXX_FLAGS_RELEASE}") ' contains "zero" but "O" letter. It's my fault due to the previous my example was a speculative. Could you replace "-03" with "-O3" and check again?
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Mon Apr 25 11:04:13 2016 +0200
0027417: Choose a Better Default Release Optimization Parameter for MinGW-w64
Switched to replacing optimization parameter instead of overwriting
CMAKE_CXX_FLAGS_RELEASE string
[revision removed]
Detailed log of new commits:
Author: Benjamin Bihler
Date: Mon Apr 25 11:04:13 2016 +0200
0027417: Choose a Better Default Release Optimization Parameter for MinGW-w64
Switched to replacing optimization parameter instead of overwriting
CMAKE_CXX_FLAGS_RELEASE string
Now it works! My editor here displays absolutely no difference between O and zero. ;-)
Great! :) grateful to you for the participation :)
dear Commenter 1, please integrate the fix
Branch [archived branch] has been deleted by Participant.
[revision removed]
[revision removed]
Related records