MantisBT - Community
View Issue Details
0027417Community[OCCT] OCCT:Configurationpublic2016-04-22 13:052016-12-09 16:37
BenjaminBihler 
bugmaster 
normaltweak 
closedfixed 
MinGW-w64Windows
 
[OCCT] 7.1.0[OCCT] 7.1.0 
0027417: Choose a Better Default Release Optimization Parameter for MinGW-w64
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.
Not necessary
No tags attached.
related to 0027319assigned ibs Open CASCADE Configuration, Cmake - cmake's c/cxx corresponding flags are not updated in cmake gui after changes in cmake script 
Issue History
2016-04-22 13:05BenjaminBihlerNew Issue
2016-04-22 13:05BenjaminBihlerAssigned To => BenjaminBihler
2016-04-22 13:09gitNote Added: 0053499
2016-04-22 13:11BenjaminBihlerAssigned ToBenjaminBihler => bugmaster
2016-04-22 13:11BenjaminBihlerStatusnew => resolved
2016-04-22 13:11BenjaminBihlerSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13538#r13538
2016-04-22 13:16abvAssigned Tobugmaster => ibs
2016-04-25 11:14ibsNote Added: 0053534
2016-04-25 11:14ibsAssigned Toibs => BenjaminBihler
2016-04-25 11:14ibsStatusresolved => feedback
2016-04-25 11:14ibsRelationship addedrelated to 0027319
2016-04-25 11:46BenjaminBihlerNote Added: 0053537
2016-04-25 11:56ibsNote Added: 0053542
2016-04-25 12:04gitNote Added: 0053544
2016-04-25 12:05BenjaminBihlerNote Added: 0053545
2016-04-25 12:09ibsNote Added: 0053546
2016-04-25 12:09ibsNote Added: 0053547
2016-04-25 12:09ibsAssigned ToBenjaminBihler => bugmaster
2016-04-25 12:09ibsStatusfeedback => reviewed
2016-04-29 16:10bugmasterChangeset attached => occt master a139a353
2016-04-29 16:10bugmasterStatusreviewed => verified
2016-04-29 16:10bugmasterResolutionopen => fixed
2016-05-20 12:22gitNote Added: 0054204
2016-12-09 16:31aivStatusverified => closed
2016-12-09 16:37aivFixed in Version => 7.1.0

Notes
(0053499)
git   
2016-04-22 13:09   
Branch CR27417 has been created by BenjaminBihler.

SHA-1: 1524979ab2d2dcb093bbe2765c09fab0a3d1e5f5


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.
(0053534)
ibs   
2016-04-25 11:14   
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.
(0053537)
BenjaminBihler   
2016-04-25 11:46   
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
(0053542)
ibs   
2016-04-25 11:56   
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?
(0053544)
git   
2016-04-25 12:04   
Branch CR27417 has been updated by BenjaminBihler.

SHA-1: 06d29f0f8160766bccb9c5977ca0aa6b87f782c1


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

(0053545)
BenjaminBihler   
2016-04-25 12:05   
Now it works! My editor here displays absolutely no difference between O and zero. ;-)
(0053546)
ibs   
2016-04-25 12:09   
Great! :) grateful to you for the participation :)
(0053547)
ibs   
2016-04-25 12:09   
dear bugmaster, please integrate the fix
(0054204)
git   
2016-05-20 12:22   
Branch CR27417 has been deleted by inv.

SHA-1: 06d29f0f8160766bccb9c5977ca0aa6b87f782c1