Skip to content

Commit f70c3fe

Browse files
Some changes to make a possible compilation of LAPACKE independent from a Fortran compiler
1 parent 02ea2d3 commit f70c3fe

File tree

5 files changed

+117
-111
lines changed

5 files changed

+117
-111
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
message(STATUS "CBLAS enable")
1+
message(STATUS "CBLAS enabled")
22
enable_language(C)
33

44
set(LAPACK_INSTALL_EXPORT_NAME ${CBLASLIB}-targets)

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]" )

CMakeLists.txt

Lines changed: 24 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.6)
22

3-
project(LAPACK Fortran C)
3+
project(LAPACK)
44

55
set(LAPACK_MAJOR_VERSION 3)
66
set(LAPACK_MINOR_VERSION 11)
@@ -129,92 +129,6 @@ configure_file(
129129
include(PreventInSourceBuilds)
130130
include(PreventInBuildInstalls)
131131

132-
# Check if recursive flag exists
133-
include(CheckFortranCompilerFlag)
134-
if(CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
135-
check_fortran_compiler_flag("-Mrecursive" _MrecursiveFlag)
136-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
137-
check_fortran_compiler_flag("-frecursive" _frecursiveFlag)
138-
elseif(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
139-
check_fortran_compiler_flag("-recursive" _recursiveFlag)
140-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL XL)
141-
check_fortran_compiler_flag("-qrecur" _qrecurFlag)
142-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)
143-
check_fortran_compiler_flag("-recursive" _recursiveFlag)
144-
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NVHPC)
145-
check_fortran_compiler_flag("-Mrecursive" _MrecursiveFlag)
146-
else()
147-
message(WARNING "Fortran local arrays should be allocated on the stack."
148-
" Please use a compiler which guarantees that feature."
149-
" See https://github.com/Reference-LAPACK/lapack/pull/188 and references therein.")
150-
endif()
151-
152-
# Add recursive flag
153-
if(_MrecursiveFlag)
154-
string(REGEX MATCH "-Mrecursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
155-
if(NOT output_test)
156-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive"
157-
CACHE STRING "Recursive flag must be set" FORCE)
158-
endif()
159-
elseif(_frecursiveFlag)
160-
string(REGEX MATCH "-frecursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
161-
if(NOT output_test)
162-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -frecursive"
163-
CACHE STRING "Recursive flag must be set" FORCE)
164-
endif()
165-
elseif(_recursiveFlag)
166-
string(REGEX MATCH "-recursive" output_test <string> "${CMAKE_Fortran_FLAGS}")
167-
if(NOT output_test)
168-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
169-
CACHE STRING "Recursive flag must be set" FORCE)
170-
endif()
171-
elseif(_qrecurFlag)
172-
string(REGEX MATCH "-qrecur" output_test <string> "${CMAKE_Fortran_FLAGS}")
173-
if(NOT output_test)
174-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qrecur"
175-
CACHE STRING "Recursive flag must be set" FORCE)
176-
endif()
177-
endif()
178-
179-
if(UNIX)
180-
if(CMAKE_Fortran_COMPILER_ID MATCHES Intel)
181-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
182-
endif()
183-
if(CMAKE_Fortran_COMPILER_ID STREQUAL XL)
184-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave -qstrict")
185-
endif()
186-
# Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
187-
# This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
188-
string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
189-
endif()
190-
191-
if(CMAKE_Fortran_COMPILER_ID STREQUAL Compaq)
192-
if(WIN32)
193-
if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
194-
get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
195-
message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
196-
set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
197-
string(TOLOWER "${cmd}" cmdlc)
198-
if(cmdlc STREQUAL "df")
199-
message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
200-
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
201-
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
202-
#This is a workaround that is needed to avoid forward-slashes in the
203-
#filenames listed in response files from incorrectly being interpreted as
204-
#introducing compiler command options
205-
if(${BUILD_SHARED_LIBS})
206-
message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
207-
endif()
208-
set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
209-
set(str "${str} included with the CVF distribution fails to build Lapack because\n")
210-
set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
211-
message(STATUS ${str})
212-
set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
213-
endif()
214-
endif()
215-
endif()
216-
endif()
217-
218132
# Add option to enable flat namespace for symbol resolution on macOS
219133
if(APPLE)
220134
option(USE_FLAT_NAMESPACE "Use flat namespaces for symbol resolution during build and runtime." OFF)
@@ -272,26 +186,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/bin)
272186
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
273187
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LAPACK_BINARY_DIR}/lib)
274188

275-
# --------------------------------------------------
276-
# Check for any necessary platform specific compiler flags
277-
include(CheckLAPACKCompilerFlags)
278-
CheckLAPACKCompilerFlags()
279-
280-
# --------------------------------------------------
281-
# Check second function
282-
283-
include(CheckTimeFunction)
284-
set(TIME_FUNC NONE)
285-
CHECK_TIME_FUNCTION(NONE TIME_FUNC)
286-
CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
287-
CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
288-
CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
289-
CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
290-
message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
291-
292-
set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
293-
set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
294-
295189
# deprecated LAPACK and LAPACKE routines
296190
option(BUILD_DEPRECATED "Build deprecated routines" OFF)
297191
message(STATUS "Build deprecated routines: ${BUILD_DEPRECATED}")
@@ -403,6 +297,27 @@ endif()
403297
if(NOT LATESTLAPACK_FOUND)
404298
message(STATUS "Using supplied NETLIB LAPACK implementation")
405299
set(LAPACK_LIBRARIES ${LAPACKLIB})
300+
301+
enable_language(Fortran)
302+
303+
# Check for any necessary platform specific compiler flags
304+
include(CheckLAPACKCompilerFlags)
305+
CheckLAPACKCompilerFlags()
306+
307+
# Check second function
308+
include(CheckTimeFunction)
309+
set(TIME_FUNC NONE)
310+
CHECK_TIME_FUNCTION(NONE TIME_FUNC)
311+
CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
312+
CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
313+
CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
314+
CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
315+
316+
# Set second function
317+
message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
318+
set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
319+
set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
320+
406321
add_subdirectory(SRC)
407322
else()
408323
set(CMAKE_EXE_LINKER_FLAGS
@@ -438,6 +353,7 @@ if(BUILD_TESTING OR LAPACKE_WITH_TMG)
438353
if(LATESTLAPACK_FOUND AND LAPACKE_WITH_TMG)
439354
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
440355
# Check if dlatms (part of tmg) is found
356+
include(CheckFortranFunctionExists)
441357
CHECK_FORTRAN_FUNCTION_EXISTS("dlatms" LAPACK_WITH_TMGLIB_FOUND)
442358
unset(CMAKE_REQUIRED_LIBRARIES)
443359
if(NOT LAPACK_WITH_TMGLIB_FOUND)
@@ -452,9 +368,7 @@ endif()
452368
set(LAPACK_INSTALL_EXPORT_NAME ${LAPACK_INSTALL_EXPORT_NAME_CACHE})
453369
unset(LAPACK_INSTALL_EXPORT_NAME_CACHE)
454370

455-
if(LAPACKE)
456-
add_subdirectory(LAPACKE)
457-
endif()
371+
add_subdirectory(LAPACKE)
458372

459373

460374
#-------------------------------------

TESTING/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
if(MSVC_VERSION)
28
# string(REPLACE "/STACK:10000000" "/STACK:900000000000000000"
39
# CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")

0 commit comments

Comments
 (0)