For a project that uses the OpenMP API, I'm using Clang 12.0.0 on Ubuntu 20.04. Also, the version of CMake is 3.16.3.
I have the following snippet. This is my CMakeLists.txt:
include(FindOpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
if(NOT OPENMP_FOUND)
message(FATAL ERROR "Unable to find OpenMP library.")
endif()
And, the output is:
[cmake] -- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
[cmake] -- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
[cmake] -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
[cmake] FATAL ERROR Unable to find OpenMP library.
Instead, if I use GCC (version 9.4.0), the output is:
[cmake] -- Found OpenMP_C: -fopenmp (found version "4.5")
[cmake] -- Found OpenMP_CXX: -fopenmp (found version "4.5")
[cmake] -- Found OpenMP: TRUE (found version "4.5")
I know that when using Clang with OpenMP you need to use -fopenmp=libomp. But, how can I set up CMake so that everything works? What am I missing?
Any help is appreciated!