Skip to content

Profiling - CMake#17678

Closed
philippefoubert wants to merge 16 commits intoopencv:3.4from
philippefoubert:enable_profiling
Closed

Profiling - CMake#17678
philippefoubert wants to merge 16 commits intoopencv:3.4from
philippefoubert:enable_profiling

Conversation

@philippefoubert
Copy link
Copy Markdown
Contributor

resolves #17657

# - 'TEST_FILE <c1> <c2>' - test file
# - 'TURN_OFF_COMPILER_FLAG <d1> <d2>' - incompatible options that shall be turned off
# - 'TURN_OFF_LINKER_FLAG <e1> <e2>' - incompatible options that shall be turned off
# - 'LINKER_FLAG <f1> <f2>' - linker flag that shall be used with the compiler flag
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest rewriting help string in more traditional cmake format:

ocv_check_compiler_flag(<LANG> <FLAG> <RESULT> [UPDATED_COMPILER_FLAGS <var>] [UPDATED_LINKER_FLAGS <var>] [TEST_FILE <file>] [TURN_OFF_COMPILER_FLAG <flag> [<flag> ...]] [TURN_OFF_LINKER_FLAG <flag> [<flag> ...]] [LINKER_FLAG <flag> [<flag> ...]])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to mix variable update functionality to this macro. It adds unnecessary complexity and does not correlate with macro name: ocv_check_compiler_flag. "check" usually means that nothing will be changed and macro will just return some value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but i had to deal with its usage: this macro is not always used the same variable containing the compiler/linker flags. Would you find better to pass these variables in read only and modifying them, if necessary, outside of the macro?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add these options to add_extra_compiler_option macro? Or a new higher level macro/function which will be used in one or two places?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why haven't you make a patch that you proposed in the issue? It was much simpler.

@philippefoubert
Copy link
Copy Markdown
Contributor Author

Can the build be relaunch once more? The problem (usage of "list(join ...)" not supported if CMake is not up to date) should be solved.

@philippefoubert
Copy link
Copy Markdown
Contributor Author

My new version is much better but the builds fail because the LINK_OPTIONS option of try_compile() does not exist before CMake 3.14. Do you have any workaround to suggest?

@asmorkalov
Copy link
Copy Markdown
Contributor

@philippefoubert @mshabunin friendly reminder.

@philippefoubert
Copy link
Copy Markdown
Contributor Author

@philippefoubert @mshabunin friendly reminder.

I was off work for a few days... 😏
I think now the PR is ready but, since flags have changed, a manual validation is required.

@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin Friendly reminder.

@philippefoubert
Copy link
Copy Markdown
Contributor Author

@asmorkalov @mshabunin Did you have time to perform the code review?

@mshabunin
Copy link
Copy Markdown
Contributor

@philippefoubert , looks like compile options has changed:

  Actual (486): '-fvisibility-inlines-hidden -fdata-sections
  -ffunction-sections -fomit-frame-pointer -pthread -Wno-long-long
  -fdiagnostics-show-option -Wno-missing-field-initializers -Wno-comment
  -Wno-delete-non-virtual-dtor -Winit-self -Wuninitialized -Wsign-promo
  -Wshadow -Wpointer-arith -Winit-self -Wundef -Wmissing-declarations
  -Werror=format-security -Wformat -Wformat -Werror=sequence-point
  -Werror=address -Werror=non-virtual-dtor -Werror=return-type -Wall -W
  -fsigned-char -msse -msse2 -msse3'

  Expected (497): '-fsigned-char -W -Wall -Werror=return-type
  -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat
  -Werror=format-security -Wmissing-declarations -Wundef -Winit-self
  -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self
  -Wno-delete-non-virtual-dtor -Wno-comment -Wno-missing-field-initializers
  -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer
  -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden
  -fvisibility-inlines-hidden'

I can see duplicated -Wformat option and wrong order: -Wall -W - moved to the end.


I thought the issue with ENABLE_PROFILING have been fixed in #17744, haven't it?


# add_extra_compiler_option(<option> [...]
# [TURN_OFF_COMPILER_FLAG <flag> [<flag> ...]]
# [TURN_OFF_LINKER_FLAG <flag> [<flag> ...]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TURN_OFF

Perhaps naming is not accurate. Suggested variants:

  • REMOVE
  • or EXCLUDE

Also it would be nice to allow patterns here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made the renaming. Could explain what you think about when you are talking about patterns ?

Copy link
Copy Markdown
Member

@alalek alalek Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean to replace checks if(... STREQUAL ...) => if(... MATHES "${regex_pattern}")

In this case use string(REGEX REPLACE ...) instead of string(REPLACE ...) (but need to add argument boundary checks)

Mostly needed for handling of non-boolean options with "values", like -march= or -O2 / -O1 / -O0 / -O3 / Os.

add_extra_compiler_option("-Wformat")
add_extra_compiler_option("-Werror=format-security -Wformat")
add_extra_compiler_option("-Wmissing-declarations")
add_extra_compiler_option("-Wmissing-prototypes")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need such massive changes?

BTW, good PR should not break existed code and doesn't require massive changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only added the double quotes to ease the parsing in the macro and increase homogeneity: some of the calls to add_extra_compiler_option were done with double quotes and some were done without double quotes.

message(STATUS "Performing Test ${RESULT} - Success")
else(${RESULT})
message(STATUS "Performing Test ${RESULT} - Failed")
# message("${OUTPUT}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary debug code (it is already added to CMakeError.log)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshabunin > I thought the issue with ENABLE_PROFILING have been fixed in #17744, haven't it?

The #17744 is a quick fix to the ENABLE_PROFILING while the #17678 is more generic: the incompatibility between compiler options is not only related to profiling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep original message(STATUS "Performing Test ${RESULT} - Failed") messages.

set(_varname "HAVE_CPU_${OPT}_SUPPORT")
ocv_check_compiler_flag(CXX "${CPU_BASELINE_FLAGS}" "${_varname}" "${CPU_${OPT}_TEST_FILE}")
ocv_check_compiler_flag(CXX "${CPU_BASELINE_FLAGS}" "${_varname}"
LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENCV_EXTRA_EXE_LINKER_FLAGS

IMHO, this should be assumed in "ocv_" check function.

@philippefoubert
Copy link
Copy Markdown
Contributor Author

📌 (not directly related to this PR):
Following gcc: error: long: No such file or directory, i have to set OPENCV_ENABLE_ALLOCATOR_STATS=OFF to be able to compile using mingw32

@alalek
Copy link
Copy Markdown
Member

alalek commented Sep 3, 2020

@philippefoubert Related issue is here: #16990
You may want to provide automatic handling for MinGW in CMake scripts and replace "long long" with "int64_t", see modules/core/CMakeLists.txt. See #16990 (comment)

@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin @philippefoubert Friendly reminder. The PR still does not pass CI checks.

1 similar comment
@asmorkalov
Copy link
Copy Markdown
Contributor

@mshabunin @philippefoubert Friendly reminder. The PR still does not pass CI checks.

@asenyaev
Copy link
Copy Markdown
Contributor

asenyaev commented Apr 8, 2021

jenkins cn please retry a build

@mshabunin
Copy link
Copy Markdown
Contributor

This PR has been superseded by #17744.

@mshabunin mshabunin closed this Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants