Repository: conan-io/conan-center-index

Issue:
[package] openblas/0.3.17: continues to build when build_lapack is defined but no fortran compiler is found
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **openblas/0.3.17**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
Configuration for profile default:

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=clang
compiler.version=12
compiler.libcxx=libstdc++11
build_type=Release
[options]
[conf]
[build_requires]
[env]
CC=/usr/bin/clang
CXX=/usr/bin/clang++
```


### Steps to reproduce (Include if Applicable)
1. Ensure no fortran compiler is installed or discoverable.
2. Install openblas with option `build_lapack=True` set.


### Description

When building openblas with `build_lapack=True` but no fortran compiler is discoverable/exists, it will throw an error indicating as such, but then continue on to compile with BLAS only:

```
openblas/0.3.17@user/experimental: Calling build()
openblas/0.3.17@user/experimental: WARN: Building with lapack support requires a Fortran compiler.
... <snip>
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - NOTFOUND
-- No Fortran compiler found, can build only BLAS but not LAPACK
```

The expected/desired behaviour in this situation would be to throw an error and not compile. This causes an issue in downstream packages where it's expected that this either causes failure or succeeds, such as is the case with armadillo #6754. In this specific case, the library compiles but when it's used, the user will experience unresolved symbol errors, which is difficult to track down because the compilation appears to have succeeded, unless one reads back through the (very long) compilation log.



Discussion:

Resolving patch:
diff --git a/recipes/openblas/all/conanfile.py b/recipes/openblas/all/conanfile.py
--- a/recipes/openblas/all/conanfile.py
+++ b/recipes/openblas/all/conanfile.py
@@ -9,11 +9,7 @@ class OpenblasConan(ConanFile):
     url = "https://github.com/conan-io/conan-center-index"
     homepage = "https://www.openblas.net"
     description = "An optimized BLAS library based on GotoBLAS2 1.13 BSD version"
-    topics = (
-        "openblas",
-        "blas",
-        "lapack"
-    )
+    topics = ("openblas", "blas", "lapack")
     settings = "os", "compiler", "build_type", "arch"
     options = {
         "shared": [True, False],
@@ -27,7 +23,7 @@ class OpenblasConan(ConanFile):
         "fPIC": True,
         "build_lapack": False,
         "use_thread": True,
-        "dynamic_arch": False
+        "dynamic_arch": False,
     }
     exports_sources = ["CMakeLists.txt"]
     generators = "cmake"
@@ -45,17 +41,21 @@ def configure(self):
             del self.options.fPIC
 
     def validate(self):
-        if hasattr(self, 'settings_build') and tools.cross_building(self, skip_x64_x86=True):
+        if hasattr(self, "settings_build") and tools.cross_building(self, skip_x64_x86=True):
             raise ConanInvalidConfiguration("Cross-building not implemented")
 
     def source(self):
-        tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
+        tools.get(
+            **self.conan_data["sources"][self.version],
+            strip_root=True,
+            destination=self._source_subfolder
+        )
 
     def _configure_cmake(self):
         if self._cmake:
             return self._cmake
         self._cmake = CMake(self)
-        
+
         if self.options.build_lapack:
             self.output.warn("Building with lapack support requires a Fortran compiler.")
         self._cmake.definitions["NOFORTRAN"] = not self.options.build_lapack
@@ -66,7 +66,9 @@ def _configure_cmake(self):
         # Required for safe concurrent calls to OpenBLAS routines
         self._cmake.definitions["USE_LOCKING"] = not self.options.use_thread
 
-        self._cmake.definitions["MSVC_STATIC_CRT"] = False # don't, may lie to consumer, /MD or /MT is managed by conan
+        self._cmake.definitions[
+            "MSVC_STATIC_CRT"
+        ] = False  # don't, may lie to consumer, /MD or /MT is managed by conan
 
         # This is a workaround to add the libm dependency on linux,
         # which is required to successfully compile on older gcc versions.
@@ -76,6 +78,28 @@ def _configure_cmake(self):
         return self._cmake
 
     def build(self):
+        if tools.Version(self.version) >= "0.3.12":
+            search = """message(STATUS "No Fortran compiler found, can build only BLAS but not LAPACK")"""
+            replace = (
+                """message(FATAL_ERROR "No Fortran compiler found. Cannot build with LAPACK.")"""
+            )
+        else:
+            search = "enable_language(Fortran)"
+            replace = """include(CheckLanguage)
+check_language(Fortran)
+if(CMAKE_Fortran_COMPILER)
+  enable_language(Fortran)
+else()
+  message(FATAL_ERROR "No Fortran compiler found. Cannot build with LAPACK.")
+  set (NOFORTRAN 1)
+  set (NO_LAPACK 1)
+endif()"""
+
+        tools.replace_in_file(
+            os.path.join(self._source_subfolder, "cmake", "f_check.cmake"),
+            search,
+            replace,
+        )
         cmake = self._configure_cmake()
         cmake.build()
 
@@ -95,10 +119,16 @@ def package_info(self):
         self.cpp_info.names["cmake_find_package_multi"] = "OpenBLAS"
         self.cpp_info.names["pkg_config"] = "openblas"
         cmake_component_name = "pthread" if self.options.use_thread else "serial"
-        self.cpp_info.components["openblas_component"].names["cmake_find_package"] = cmake_component_name
-        self.cpp_info.components["openblas_component"].names["cmake_find_package_multi"] = cmake_component_name
+        self.cpp_info.components["openblas_component"].names[
+            "cmake_find_package"
+        ] = cmake_component_name
+        self.cpp_info.components["openblas_component"].names[
+            "cmake_find_package_multi"
+        ] = cmake_component_name
         self.cpp_info.components["openblas_component"].names["pkg_config"] = "openblas"
-        self.cpp_info.components["openblas_component"].includedirs.append(os.path.join("include", "openblas"))
+        self.cpp_info.components["openblas_component"].includedirs.append(
+            os.path.join("include", "openblas")
+        )
         self.cpp_info.components["openblas_component"].libs = tools.collect_libs(self)
         if self.settings.os == "Linux":
             if self.options.use_thread:
@@ -106,5 +136,7 @@ def package_info(self):
             if self.options.build_lapack:
                 self.cpp_info.components["openblas_component"].system_libs.append("gfortran")
 
-        self.output.info("Setting OpenBLAS_HOME environment variable: {}".format(self.package_folder))
+        self.output.info(
+            "Setting OpenBLAS_HOME environment variable: {}".format(self.package_folder)
+        )
         self.env_info.OpenBLAS_HOME = self.package_folder


Test patch: