-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake: Pass OpenMP
compiler and linker flags through CMake targets
#5180
base: develop
Are you sure you want to change the base?
Conversation
a6e2183
to
b0746c7
Compare
bf2f49f
to
18ccac9
Compare
Ok, this is ready. If appropriate, I can also remove all OpenMP related code in |
see #5169 for the needed setup |
A successful test on Linux x86_64, where libomp is installed system-wide in /usr/. I ran the following:
and the linkage is correct:
|
Also works on M1 up to date system, with
openblas.pc looks correct too. |
Using `OpenMP::OpenMP_LANG` targets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by setting `OpenMP_LANG_FLAGS`, `OpenMP_LANG_LIB_NAMES`, and `OpenMP_omp_LIBRARY`.
18ccac9
to
251c3f8
Compare
get_target_property(OMP_C_LIB OpenMP::OpenMP_C INTERFACE_LINK_LIBRARIES) | ||
get_target_property(OMP_Fortran_LIB OpenMP::OpenMP_Fortran INTERFACE_LINK_LIBRARIES) | ||
if (NOT OMP_C_LIB STREQUAL OMP_Fortran_LIB) | ||
message(FATAL_ERROR "Multiple OpenMP runtime libraries detected. Mixed OpenMP runtime linkage is dangerous. You may pass -DOpenMP_LANG_LIB_NAMES and -DOpenMP_omp_LIBRARY to manually choose the OpenMP library.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous failure in the GitHub workflow was caused by this check due to mixed linkage to both libomp and libgomp. I have updated the workflow in the latest commit and it should pass the check now.
Using
OpenMP::OpenMP_LANG
targets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by settingOpenMP_LANG_FLAGS
,OpenMP_LANG_LIB_NAMES
, andOpenMP_omp_LIBRARY
.