Skip to content

Commit 33b3a45

Browse files
authored
Merge pull request #834 from weslleyspereira/makes-cmake-independent-from-Fortran
Compilation of LAPACKE possibly independent from Fortran
2 parents 1638202 + bf50aff commit 33b3a45

File tree

8 files changed

+205
-147
lines changed

8 files changed

+205
-147
lines changed

.github/workflows/cmake.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,34 @@ jobs:
151151
echo "Coverage"
152152
cmake --build build --target coverage
153153
bash <(curl -s https://codecov.io/bash) -X gcov
154+
155+
test-install-cblas-lapacke-without-fortran-compiler:
156+
runs-on: ubuntu-latest
157+
steps:
158+
- name: Checkout LAPACK
159+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
160+
161+
- name: Install ninja-build tool
162+
uses: seanmiddleditch/gha-setup-ninja@16b940825621068d98711680b6c3ff92201f8fc0 # v3
163+
164+
- name: Install basics
165+
run: |
166+
sudo apt update
167+
sudo apt install -y cmake liblapack-dev libblas-dev
168+
sudo apt purge gfortran
169+
170+
- name: Configure CMake
171+
run: >
172+
cmake -B build -G Ninja
173+
-D CMAKE_BUILD_TYPE=Release
174+
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/lapack_install
175+
-D CBLAS:BOOL=ON
176+
-D LAPACKE:BOOL=ON
177+
-D USE_OPTIMIZED_BLAS:BOOL=ON
178+
-D USE_OPTIMIZED_LAPACK:BOOL=ON
179+
-D BUILD_TESTING:BOOL=OFF
180+
-D LAPACKE_WITH_TMG:BOOL=OFF
181+
-D BUILD_SHARED_LIBS:BOOL=ON
182+
183+
- name: Install
184+
run: cmake --build build --target install -j2

BLAS/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
enable_language(Fortran)
2+
3+
# Check for any necessary platform specific compiler flags
4+
include(CheckLAPACKCompilerFlags)
5+
CheckLAPACKCompilerFlags()
6+
17
add_subdirectory(SRC)
28
if(BUILD_TESTING)
39
add_subdirectory(TESTING)

CBLAS/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
message(STATUS "CBLAS enable")
1+
message(STATUS "CBLAS enabled")
22
enable_language(C)
33

44
set(LAPACK_INSTALL_EXPORT_NAME ${CBLASLIB}-targets)
55

66
# Create a header file cblas.h for the routines called in my C programs
7-
include(FortranCInterface)
8-
## Ensure that the fortran compiler and c compiler specified are compatible
9-
FortranCInterface_VERIFY()
10-
FortranCInterface_HEADER(${LAPACK_BINARY_DIR}/include/cblas_mangling.h
11-
MACRO_NAMESPACE "F77_"
12-
SYMBOL_NAMESPACE "F77_")
7+
include(CheckLanguage)
8+
check_language(Fortran)
9+
if(CMAKE_Fortran_COMPILER)
10+
enable_language(Fortran)
11+
include(FortranCInterface)
12+
## Ensure that the fortran compiler and c compiler specified are compatible
13+
FortranCInterface_VERIFY()
14+
FortranCInterface_HEADER(${LAPACK_BINARY_DIR}/include/cblas_mangling.h
15+
MACRO_NAMESPACE "F77_"
16+
SYMBOL_NAMESPACE "F77_")
17+
endif()
1318
if(NOT FortranCInterface_GLOBAL_FOUND OR NOT FortranCInterface_MODULE_FOUND)
1419
message(WARNING "Reverting to pre-defined include/cblas_mangling.h")
1520
configure_file(include/cblas_mangling_with_flags.h.in

CMAKE/CheckLAPACKCompilerFlags.cmake

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,26 @@ if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
5656
if( "${CMAKE_Fortran_FLAGS}" MATCHES "-ffpe-trap=[izoupd]")
5757
set( FPE_EXIT TRUE )
5858
endif()
59+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-frecursive") )
60+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -frecursive"
61+
CACHE STRING "Recursive flag must be set" FORCE)
62+
endif()
5963

6064
# Intel Fortran
6165
elseif( CMAKE_Fortran_COMPILER_ID MATCHES "Intel" )
6266
if( "${CMAKE_Fortran_FLAGS}" MATCHES "[-/]fpe(-all=|)0" )
6367
set( FPE_EXIT TRUE )
6468
endif()
6569

70+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-recursive") )
71+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
72+
CACHE STRING "Recursive flag must be set" FORCE)
73+
endif()
74+
75+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-fp-model[ \t]strict") )
76+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
77+
endif()
78+
6679
# SunPro F95
6780
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
6881
if( ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=") AND
@@ -74,13 +87,33 @@ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
7487
CACHE STRING "Flags for Fortran compiler." FORCE )
7588
endif()
7689

90+
if(UNIX)
91+
# Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
92+
# This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
93+
string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
94+
endif()
95+
7796
# IBM XL Fortran
7897
elseif( (CMAKE_Fortran_COMPILER_ID STREQUAL "VisualAge" ) OR # CMake 2.6
7998
(CMAKE_Fortran_COMPILER_ID STREQUAL "XL" ) ) # CMake 2.8
8099
if( "${CMAKE_Fortran_FLAGS}" MATCHES "-qflttrap=[a-zA-Z:]:enable" )
81100
set( FPE_EXIT TRUE )
82101
endif()
83102

103+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qrecur") )
104+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qrecur"
105+
CACHE STRING "Recursive flag must be set" FORCE)
106+
endif()
107+
108+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qnosave") )
109+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave")
110+
endif()
111+
112+
113+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qstrict") )
114+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qstrict")
115+
endif()
116+
84117
# HP Fortran
85118
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "HP" )
86119
if( "${CMAKE_Fortran_FLAGS}" MATCHES "\\+fp_exception" )
@@ -138,6 +171,11 @@ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
138171
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w=unused")
139172
endif()
140173

174+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-recursive") )
175+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
176+
CACHE STRING "Recursive flag must be set" FORCE)
177+
endif()
178+
141179
# Suppress compiler banner and summary
142180
check_fortran_compiler_flag("-quiet" _quiet)
143181
if( _quiet AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "[-/]quiet") )
@@ -155,7 +193,49 @@ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" )
155193
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Kieee")
156194
endif()
157195

196+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-Mrecursive") )
197+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive"
198+
CACHE STRING "Recursive flag must be set" FORCE)
199+
endif()
200+
201+
# Flang Fortran
202+
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Flang" )
203+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-Mrecursive") )
204+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive"
205+
CACHE STRING "Recursive flag must be set" FORCE)
206+
endif()
207+
208+
# Compaq Fortran
209+
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq")
210+
if(WIN32)
211+
if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
212+
get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
213+
message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
214+
set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
215+
string(TOLOWER "${cmd}" cmdlc)
216+
if(cmdlc STREQUAL "df")
217+
message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
218+
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
219+
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
220+
#This is a workaround that is needed to avoid forward-slashes in the
221+
#filenames listed in response files from incorrectly being interpreted as
222+
#introducing compiler command options
223+
if(${BUILD_SHARED_LIBS})
224+
message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
225+
endif()
226+
set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
227+
set(str "${str} included with the CVF distribution fails to build Lapack because\n")
228+
set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
229+
message(STATUS ${str})
230+
set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
231+
endif()
232+
endif()
233+
endif()
234+
158235
else()
236+
message(WARNING "Fortran local arrays should be allocated on the stack."
237+
" Please use a compiler which guarantees that feature."
238+
" See https://github.com/Reference-LAPACK/lapack/pull/188 and references therein.")
159239
endif()
160240

161241
if( "${CMAKE_Fortran_FLAGS_RELEASE}" MATCHES "O[3-9]" )

0 commit comments

Comments
 (0)