Skip to content

Commit

Permalink
openmp: extend the list of supported compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 17, 2024
1 parent 8719eef commit c600d85
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions recipes/openmp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

Check warning on line 4 in recipes/openmp/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused Version imported from conan.tools.scm

required_conan_version = ">=1.52.0"

Expand Down Expand Up @@ -39,7 +40,7 @@ def package_id(self):
self.info.clear()

def validate(self):
if self.options.provider == "native" and self._openmp_flags() is None:
if self.options.provider == "native" and self._openmp_flags is None:
raise ConanInvalidConfiguration(
f"{self.settings.compiler} is not supported by this recipe. Contributions are welcome!"
)
Expand All @@ -52,20 +53,53 @@ def validate(self):
"Make sure you avoid accidental linking against the native implementation through external libraries."
)

@property
def _openmp_flags(self):
# Based on https://github.com/Kitware/CMake/blob/v3.28.1/Modules/FindOpenMP.cmake#L104-L135
if self.settings.compiler == "clang":
# Based on https://github.com/Kitware/CMake/blob/v3.30.0/Modules/FindOpenMP.cmake#L119-L154
if self.settings.compiler == "gcc":
return ["-fopenmp"]
elif self.settings.compiler == "clang":
return ["-fopenmp=libomp"]
elif self.settings.compiler == "apple-clang":
return ["-Xclang", "-fopenmp"]
elif self.settings.compiler == "gcc":
return ["-fopenmp"]
elif is_msvc(self):
return ["-openmp"]
elif self.settings.compiler == "intel-cc":
return ["-Qopenmp"]
if self.settings.os == "Windows":
return ["-Qopenmp"]
else:
return ["-qopenmp"]
elif self.settings.compiler == "sun-cc":
return ["-xopenmp"]
elif is_msvc(self):

# The following compilers are not currently covered by settings.yml,
# but are included for completeness.
elif self.settings.compiler == "hp":
return ["+Oopenmp"]
elif self.settings.compiler == "intel-llvm":
if self.settings.get_safe("compiler.frontend") == "msvc":
return ["-Qiopenmp"]
else:
return ["-fiopenmp"]
elif self.settings.compiler == "pathscale":
return ["-openmp"]
elif self.settings.compiler == "nag":
return ["-openmp"]
elif self.settings.compiler == "absoft":
return ["-openmp"]
elif self.settings.compiler == "nvhpc":
return ["-mp"]
elif self.settings.compiler == "pgi":
return ["-mp"]
elif self.settings.compiler == "xl":
return ["-qsmp=omp"]
elif self.settings.compiler == "cray":
return ["-h", "omp"]
elif self.settings.compiler == "fujitsu":
return ["-Kopenmp"]
elif self.settings.compiler == "fujitsu-clang":
return ["-fopenmp"]

return None

def package_info(self):
Expand All @@ -79,7 +113,7 @@ def package_info(self):
if self.options.provider == "native":
# Rely on CMake's FindOpenMP.cmake and an OpenMP implementation provided by the compiler.
# Export appropriate flags for the transitive use case.
openmp_flags = self._openmp_flags()
openmp_flags = self._openmp_flags
self.cpp_info.sharedlinkflags = openmp_flags
self.cpp_info.exelinkflags = openmp_flags
self.cpp_info.cflags = openmp_flags
Expand Down

0 comments on commit c600d85

Please sign in to comment.