Repository: conan-io/conan

Issue:
[feature] Improve detect API to support Intel oneAPI compiler
### What is your suggestion?

Hi there,
Is there anything that we can do in order to better support the Intel oneAPI compiler in the [detect API](https://github.com/conan-io/conan/blob/37573eeb176b9d382d999d5b3c45d220727f8702/conan/internal/api/detect_api.py#L205)?
Any suggestion is welcome, I will be happy to contribute.
Thanks.

### Have you read the CONTRIBUTING guide?

- [X] I've read the CONTRIBUTING guide


Discussion:
Hi @jakeheke75 

Thanks for your suggestion.

Yes, it would be possible to add detection for Intel OneAPI. The place to do it would be the ``def detect_compiler():`` method in ``detect.py`` file. Some points to take into account:

- The default precedence (msvc in Windows, gcc in Linux, etc) cannot be changed, it could be considered too breaking.
- If the CC/CXX env-vars are defined to point to it, then it would be the easier approach, and then the detection for it can be implemented there
- You can have a look how gcc and others detect the version
- After compiler + version are detected correctly (this can be tested with ``conan profile detect -f``), then it would be necessary to complete the other defaults: cppstd, libcxx (if it used, like Linux) or runtime (for Windows)

The way to do it would be a PR to improve that. As testing of this is quite challenging for this feature, no tests are initially added, and we should trust your manual testing mostly.

Please let me know if this is enough to start
Hello @memsharded 

Thank you for all the information. It's enough to start, I will submit a draft PR as soon as I have something working. If I have any doubt during the development process I will write it here; in this way we can keep track of all the open points.

Thanks!


Well, I haven't got so far without asking the first question :smile: 
Where can I update the strings of the Intel compiler versions in `settings.yml`? I mean, now for testing purposes I can update them manually, but in the future we probably want to have them stored and retrieved automatically right?
![image](https://github.com/conan-io/conan/assets/113254017/52efca58-156c-415d-b52e-54f08f032187)
Thank you in advance for your help.


Hi @jakeheke75 

Don't worry, you can ask as many questions as you need 🙂 

You can add whatever is necessary/expected in https://github.com/conan-io/conan/blob/bde2eaa061e1d202dff06ece20427bd5f27cfaa4/conans/client/conf/__init__.py#L3

To test temporarily go to your cache (``conan config home``) and modify the ``settings.yml`` there.


Side hint: When posting things to Github, it is better to copy and paste as text rather than images, that allow us to copy and search, etc. Formatting can be done with triple backticks. Many thanks!

Resolving patch:
diff --git a/conan/internal/api/detect_api.py b/conan/internal/api/detect_api.py
--- a/conan/internal/api/detect_api.py
+++ b/conan/internal/api/detect_api.py
@@ -185,6 +185,8 @@ def _detect_gcc_libcxx(version_, executable):
         return "libCstd"
     elif compiler == "mcst-lcc":
         return "libstdc++"
+    elif compiler == "intel-cc":
+        return "libstdc++11"    
 
 
 def default_msvc_runtime(compiler):
@@ -225,9 +227,16 @@ def _visual_cppstd_default(version):
     def _mcst_lcc_cppstd_default(version):
         return "gnu14" if version >= "1.24" else "gnu98"
 
+    def _intel_cppstd_default(version):
+        tokens = version.main
+        major = tokens[0]
+        # https://www.intel.com/content/www/us/en/developer/articles/troubleshooting/icx-changes-default-cpp-std-to-cpp17-with-2023.html
+        return "17" if major >= "2023" else "14"
+
     default = {"gcc": _gcc_cppstd_default(compiler_version),
                "clang": _clang_cppstd_default(compiler_version),
                "apple-clang": "gnu98",
+               "intel-cc": _intel_cppstd_default(compiler_version),
                "msvc": _visual_cppstd_default(compiler_version),
                "mcst-lcc": _mcst_lcc_cppstd_default(compiler_version)}.get(str(compiler), None)
     return default
@@ -268,6 +277,9 @@ def detect_compiler():
                 output.error("%s detected as a frontend using apple-clang. "
                              "Compiler not supported" % command)
             return gcc, gcc_version
+        if "icpx" in command or "icx" in command:
+            intel, intel_version = _intel_compiler(command)
+            return intel, intel_version        
         if platform.system() == "SunOS" and command.lower() == "cc":
             return _sun_cc_compiler(command)
         if (platform.system() == "Windows" and command.rstrip('"').endswith(("cl", "cl.exe"))
@@ -342,6 +354,18 @@ def _gcc_compiler(compiler_exe="gcc"):
     except (Exception,):  # to disable broad-except
         return None, None
 
+def _intel_compiler(compiler_exe="icx"):
+    try:
+        ret, out = detect_runner("%s --version" % compiler_exe)
+        if ret != 0:
+            return None, None
+        compiler = "intel-cc"
+        installed_version = re.search(r"(202[0-9]+(\.[0-9])?)", out).group()
+        if installed_version:
+            ConanOutput(scope="detect_api").info("Found %s %s" % (compiler, installed_version))
+            return compiler, Version(installed_version)
+    except (Exception,):  # to disable broad-except
+        return None, None
 
 def _sun_cc_compiler(compiler_exe="cc"):
     try:
@@ -423,4 +447,6 @@ def default_compiler_version(compiler, version):
         return major
     elif compiler == "msvc":
         return major
+    elif compiler == "intel-cc":
+        return major
     return version
diff --git a/conans/client/conf/__init__.py b/conans/client/conf/__init__.py
--- a/conans/client/conf/__init__.py
+++ b/conans/client/conf/__init__.py
@@ -121,7 +121,8 @@
         libcxx: [libstdc++, libc++]
         cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]
     intel-cc:
-        version: ["2021.1", "2021.2", "2021.3"]
+        version: ["2021.1", "2021.2", "2021.3", "2021.4", "2022.1", "2022.2",
+                  "2022.3", "2023.0", "2023.1", "2023.2", "2024.0",]
         update: [null, ANY]
         mode: ["icx", "classic", "dpcpp"]
         libcxx: [null, libstdc++, libstdc++11, libc++]


Test patch: