The ENABLE_PROFILE option is not properly managed: the "-pg" option is always seen as not available.
System information (version)
- OpenCV => 4.4.0
- Operating System / Platform => Windows 64 Bit
- Compiler => mingw32
Detailed description
Extract of OpenCVCompilerOptions.cmake:
[...]
if(ENABLE_PROFILING)
add_extra_compiler_option("-pg -g")
# turn off incompatible options
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS
CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG
OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
endforeach()
[...]
Description of the problem:
For a successful check of the flag support (ocv_check_flag_support) in add_extra_compiler_option, two corrections are required:
- The test of the option "-pg -g" should be done after having turning off incompatible options
- The "-pg" should be placed both in the linker and in the compiler settings
The following code should be written a more properly way but it shows what should be done to enable the profiling:
[...]
if(ENABLE_PROFILING)
# turn off incompatible options
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS
CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE
CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG
OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
string(REPLACE "-fdata-sections" "" ${flags} "${${flags}}")
endforeach()
# -pg should be placed both in the linker and in the compiler settings
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
add_extra_compiler_option("-pg -g")
[...]
The ENABLE_PROFILE option is not properly managed: the "-pg" option is always seen as not available.
System information (version)
Detailed description
Extract of OpenCVCompilerOptions.cmake:
Description of the problem:
For a successful check of the flag support (
ocv_check_flag_support) inadd_extra_compiler_option, two corrections are required:The following code should be written a more properly way but it shows what should be done to enable the profiling: