Skip to content

Commit

Permalink
use cmake's FindOpenMP (#7156)
Browse files Browse the repository at this point in the history
check_add_gcc_compiler_flag("-fopenmp")
is not robust enough. On some systems and with some compilers
(eg. AppleClang 7) it may say the compiler flag is valid, but later build
fails with:

ld: library not found for -lgomp

Actually, AppleClang doesn't support OpenMP

Replace this check with cmake's FindOpenMP [1] which gives better results.

Output example in case of not found
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)

Output example in case of found
-- Found OpenMP_C: -fopenmp=libomp (found version "3.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "3.1")
-- Found OpenMP: TRUE (found version "3.1")

[1] https://cmake.org/cmake/help/v3.3/module/FindOpenMP.html?highlight=openmp#variables
  • Loading branch information
tenzap authored Nov 23, 2021
1 parent a3dc977 commit d3b28f8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ if(WITH_APP_BUNDLE)
endif()

add_gcc_compiler_flags("-fno-common")
check_add_gcc_compiler_flag("-fopenmp")
find_package(OpenMP)
if(OpenMP_FOUND)
add_gcc_compiler_cflags(${OpenMP_C_FLAGS})
add_gcc_compiler_cxxflags(${OpenMP_CXX_FLAGS})
endif()
add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long")
add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute")
add_gcc_compiler_flags("-fvisibility=hidden")
Expand Down

0 comments on commit d3b28f8

Please sign in to comment.