diff options
author | tenzap <46226844+tenzap@users.noreply.github.com> | 2021-11-23 15:34:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 15:34:35 +0300 |
commit | d3b28f86515df73194d1102253b739b51b1909f5 (patch) | |
tree | 8a594f6e80c5b6be045aeed372b06582d05d0fe3 /CMakeLists.txt | |
parent | a3dc977e58470644f2acca77905285d44b22f2b8 (diff) |
use cmake's FindOpenMP (#7156)
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
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index dd149c287..d8d0393f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") |