Skip to content

Commit f279210

Browse files
Some changes to make a possible compilation of LAPACKE independent from a Fortran compiler
1 parent 1fafb88 commit f279210

File tree

5 files changed

+111
-106
lines changed

5 files changed

+111
-106
lines changed

BLAS/CMakeLists.txt

+6
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

+1-1
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

+75
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,26 @@ if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
4848
if( "${CMAKE_Fortran_FLAGS}" MATCHES "-ffpe-trap=[izoupd]")
4949
set( FPE_EXIT TRUE )
5050
endif()
51+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-frecursive") )
52+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -frecursive"
53+
CACHE STRING "Recursive flag must be set" FORCE)
54+
endif()
5155

5256
# Intel Fortran
5357
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
5458
if( "${CMAKE_Fortran_FLAGS}" MATCHES "[-/]fpe(-all=|)0" )
5559
set( FPE_EXIT TRUE )
5660
endif()
5761

62+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-recursive") )
63+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
64+
CACHE STRING "Recursive flag must be set" FORCE)
65+
endif()
66+
67+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-fp-model[ \t]strict") )
68+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fp-model strict")
69+
endif()
70+
5871
# SunPro F95
5972
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
6073
if( ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=") AND
@@ -66,13 +79,33 @@ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
6679
CACHE STRING "Flags for Fortran compiler." FORCE )
6780
endif()
6881

82+
if(UNIX)
83+
# Delete libmtsk in linking sequence for Sun/Oracle Fortran Compiler.
84+
# This library is not present in the Sun package SolarisStudio12.3-linux-x86-bin
85+
string(REPLACE \;mtsk\; \; CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}")
86+
endif()
87+
6988
# IBM XL Fortran
7089
elseif( (CMAKE_Fortran_COMPILER_ID STREQUAL "VisualAge" ) OR # CMake 2.6
7190
(CMAKE_Fortran_COMPILER_ID STREQUAL "XL" ) ) # CMake 2.8
7291
if( "${CMAKE_Fortran_FLAGS}" MATCHES "-qflttrap=[a-zA-Z:]:enable" )
7392
set( FPE_EXIT TRUE )
7493
endif()
7594

95+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qrecur") )
96+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qrecur"
97+
CACHE STRING "Recursive flag must be set" FORCE)
98+
endif()
99+
100+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qnosave") )
101+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qnosave")
102+
endif()
103+
104+
105+
if( UNIX AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qstrict") )
106+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qstrict")
107+
endif()
108+
76109
# HP Fortran
77110
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "HP" )
78111
if( "${CMAKE_Fortran_FLAGS}" MATCHES "\\+fp_exception" )
@@ -130,13 +163,55 @@ elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
130163
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -w=unused")
131164
endif()
132165

166+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-recursive") )
167+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -recursive"
168+
CACHE STRING "Recursive flag must be set" FORCE)
169+
endif()
170+
133171
# Suppress compiler banner and summary
134172
check_fortran_compiler_flag("-quiet" _quiet)
135173
if( _quiet AND NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "[-/]quiet") )
136174
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -quiet")
137175
endif()
138176

177+
# Flang Fortran
178+
elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Flang" )
179+
if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-Mrecursive") )
180+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Mrecursive"
181+
CACHE STRING "Recursive flag must be set" FORCE)
182+
endif()
183+
184+
# Compaq Fortran
185+
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Compaq")
186+
if(WIN32)
187+
if(CMAKE_GENERATOR STREQUAL "NMake Makefiles")
188+
get_filename_component(CMAKE_Fortran_COMPILER_CMDNAM ${CMAKE_Fortran_COMPILER} NAME_WE)
189+
message(STATUS "Using Compaq Fortran compiler with command name ${CMAKE_Fortran_COMPILER_CMDNAM}")
190+
set(cmd ${CMAKE_Fortran_COMPILER_CMDNAM})
191+
string(TOLOWER "${cmd}" cmdlc)
192+
if(cmdlc STREQUAL "df")
193+
message(STATUS "Assume the Compaq Visual Fortran Compiler is being used")
194+
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 1)
195+
set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_INCLUDES 1)
196+
#This is a workaround that is needed to avoid forward-slashes in the
197+
#filenames listed in response files from incorrectly being interpreted as
198+
#introducing compiler command options
199+
if(${BUILD_SHARED_LIBS})
200+
message(FATAL_ERROR "Making of shared libraries with CVF has not been tested.")
201+
endif()
202+
set(str "NMake version 9 or later should be used. NMake version 6.0 which is\n")
203+
set(str "${str} included with the CVF distribution fails to build Lapack because\n")
204+
set(str "${str} the number of source files exceeds the limit for NMake v6.0\n")
205+
message(STATUS ${str})
206+
set(CMAKE_Fortran_LINK_EXECUTABLE "LINK /out:<TARGET> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS>")
207+
endif()
208+
endif()
209+
endif()
210+
139211
else()
212+
message(WARNING "Fortran local arrays should be allocated on the stack."
213+
" Please use a compiler which guarantees that feature."
214+
" See https://github.com/Reference-LAPACK/lapack/pull/188 and references therein.")
140215
endif()
141216

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

CMakeLists.txt

+23-105
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.2)
22

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

55
set(LAPACK_MAJOR_VERSION 3)
66
set(LAPACK_MINOR_VERSION 11)
@@ -123,90 +123,6 @@ configure_file(
123123
include(PreventInSourceBuilds)
124124
include(PreventInBuildInstalls)
125125

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

267-
# --------------------------------------------------
268-
# Check for any necessary platform specific compiler flags
269-
include(CheckLAPACKCompilerFlags)
270-
CheckLAPACKCompilerFlags()
271-
272-
# --------------------------------------------------
273-
# Check second function
274-
275-
include(CheckTimeFunction)
276-
set(TIME_FUNC NONE)
277-
CHECK_TIME_FUNCTION(NONE TIME_FUNC)
278-
CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
279-
CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
280-
CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
281-
CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
282-
message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
283-
284-
set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
285-
set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
286-
287183
# deprecated LAPACK and LAPACKE routines
288184
option(BUILD_DEPRECATED "Build deprecated routines" OFF)
289185
message(STATUS "Build deprecated routines: ${BUILD_DEPRECATED}")
@@ -395,6 +291,27 @@ endif()
395291
if(NOT LATESTLAPACK_FOUND)
396292
message(STATUS "Using supplied NETLIB LAPACK implementation")
397293
set(LAPACK_LIBRARIES ${LAPACKLIB})
294+
295+
enable_language(Fortran)
296+
297+
# Check for any necessary platform specific compiler flags
298+
include(CheckLAPACKCompilerFlags)
299+
CheckLAPACKCompilerFlags()
300+
301+
# Check second function
302+
include(CheckTimeFunction)
303+
set(TIME_FUNC NONE)
304+
CHECK_TIME_FUNCTION(NONE TIME_FUNC)
305+
CHECK_TIME_FUNCTION(INT_CPU_TIME TIME_FUNC)
306+
CHECK_TIME_FUNCTION(EXT_ETIME TIME_FUNC)
307+
CHECK_TIME_FUNCTION(EXT_ETIME_ TIME_FUNC)
308+
CHECK_TIME_FUNCTION(INT_ETIME TIME_FUNC)
309+
310+
# Set second function
311+
message(STATUS "--> Will use second_${TIME_FUNC}.f and dsecnd_${TIME_FUNC}.f as timing function.")
312+
set(SECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/second_${TIME_FUNC}.f)
313+
set(DSECOND_SRC ${LAPACK_SOURCE_DIR}/INSTALL/dsecnd_${TIME_FUNC}.f)
314+
398315
add_subdirectory(SRC)
399316
else()
400317
set(CMAKE_EXE_LINKER_FLAGS
@@ -430,6 +347,7 @@ if(BUILD_TESTING OR LAPACKE_WITH_TMG)
430347
if(LATESTLAPACK_FOUND AND LAPACKE_WITH_TMG)
431348
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
432349
# Check if dlatms (part of tmg) is found
350+
include(CheckFortranFunctionExists)
433351
CHECK_FORTRAN_FUNCTION_EXISTS("dlatms" LAPACK_WITH_TMGLIB_FOUND)
434352
unset(CMAKE_REQUIRED_LIBRARIES)
435353
if(NOT LAPACK_WITH_TMGLIB_FOUND)

TESTING/CMakeLists.txt

+6
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)