Skip to content
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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ywwry66
Copy link

@ywwry66 ywwry66 commented Mar 13, 2025

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.

@ywwry66 ywwry66 force-pushed the openmp_use_cmake branch 2 times, most recently from a6e2183 to b0746c7 Compare March 13, 2025 03:55
@ywwry66 ywwry66 marked this pull request as draft March 13, 2025 04:02
ywwry66 added 2 commits March 13, 2025 02:22
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`.
@ywwry66 ywwry66 marked this pull request as ready for review March 13, 2025 14:00
@ywwry66
Copy link
Author

ywwry66 commented Mar 13, 2025

Ok, this is ready. If appropriate, I can also remove all OpenMP related code in cmake/fc.cmake to let CMake detect OpenMP Fortran flags automatically, as was done for C in 6aac065.

@dimpase
Copy link

dimpase commented Mar 17, 2025

see #5169 for the needed setup

@dimpase
Copy link

dimpase commented Mar 18, 2025

A successful test on Linux x86_64, where libomp is installed system-wide in /usr/. I ran the following:

cmake -B build -DUSE_OPENMP=1 -DBUILD_SHARED_LIBS=1 -DBUILD_STATIC_LIBS=0 -DOpenMP_C_FLAGS="-fopenmp"  -DOpenMP_C_LIB_NAMES="omp" -DOpenMP_Fortran_FLAGS="-fopenmp" -DOpenMP_Fortran_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY="omp"
cd build/ && make -j8 && ctest

and the linkage is correct:

$ ldd lib/libopenblas.so
	linux-vdso.so.1 (0x00007f0cc7826000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f0cc6141000)
	libomp.so => /usr/lib64/libomp.so (0x00007f0cc5ff8000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f0cc5dfd000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f0cc7828000)

@dimpase
Copy link

dimpase commented Mar 19, 2025

Also works on M1 up to date system, with

cmake -B build -DUSE_OPENMP=1 -DBUILD_SHARED_LIBS=1 -DBUILD_STATIC_LIBS=0 -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp -I$(brew --prefix libomp)/include" -DOpenMP_C_LIB_NAMES="omp" -DOpenMP_Fortran_FLAGS="-fopenmp" -DOpenMP_Fortran_LIB_NAMES="omp" -DOpenMP_omp_LIBRARY=$(brew --prefix libomp)/lib/libomp.dylib

openblas.pc looks correct too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants