Skip to content

Commit 4327756

Browse files
authored
Merge pull request Reference-LAPACK#1181 from ACSimon33/fortran_strlen_type
Change FORTRAN_STRLEN type in installed headers.
2 parents 8856fad + eeed198 commit 4327756

File tree

8 files changed

+93
-41
lines changed

8 files changed

+93
-41
lines changed

CBLAS/CMakeLists.txt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
11
message(STATUS "CBLAS enabled")
22
enable_language(C)
33

4-
set(LAPACK_INSTALL_EXPORT_NAME ${CBLASLIB}-targets)
5-
6-
# Create a header file cblas.h for the routines called in my C programs
74
include(CheckLanguage)
85
check_language(Fortran)
96
if(CMAKE_Fortran_COMPILER)
107
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_")
178

189
# Check for any necessary platform specific compiler flags
1910
include(CheckLAPACKCompilerFlags)
2011
CheckLAPACKCompilerFlags()
2112
endif()
22-
if(NOT FortranCInterface_GLOBAL_FOUND OR NOT FortranCInterface_MODULE_FOUND)
23-
message(WARNING "Reverting to pre-defined include/cblas_mangling.h")
24-
configure_file(include/cblas_mangling_with_flags.h.in
25-
${LAPACK_BINARY_DIR}/include/cblas_mangling.h)
26-
endif()
13+
14+
set(LAPACK_INSTALL_EXPORT_NAME ${CBLASLIB}-targets)
2715

2816
include(CheckCSourceCompiles)
2917
check_c_source_compiles("int __attribute__((weak)) main() {};"
3018
HAS_ATTRIBUTE_WEAK_SUPPORT)
3119

3220
include_directories(include ${LAPACK_BINARY_DIR}/include)
33-
add_subdirectory(include)
3421
add_subdirectory(src)
3522

3623
macro(append_subdir_files variable dirname)
@@ -40,12 +27,6 @@ foreach(depfile ${holder})
4027
endforeach()
4128
endmacro()
4229

43-
append_subdir_files(CBLAS_INCLUDE "include")
44-
install(FILES ${CBLAS_INCLUDE} ${LAPACK_BINARY_DIR}/include/cblas_mangling.h
45-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
46-
COMPONENT Development
47-
)
48-
4930
if(BUILD_TESTING)
5031
add_subdirectory(testing)
5132
add_subdirectory(examples)

CBLAS/include/CMakeLists.txt

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
1-
set(CBLAS_INCLUDE cblas.h cblas_f77.h cblas_64.h)
1+
# Replace FORTRAN_STRLEN definition in cblas_f77.h if needed
2+
file(READ cblas_f77.h cblas_f77_h_content)
3+
if(FORTRAN_STRLEN_TYPE)
4+
string(REPLACE
5+
"#define FORTRAN_STRLEN size_t" "#define FORTRAN_STRLEN ${FORTRAN_STRLEN_TYPE}"
6+
cblas_f77_h_content "${cblas_f77_h_content}")
7+
endif()
8+
file(WRITE ${LAPACK_BINARY_DIR}/include/cblas_f77.h "${cblas_f77_h_content}")
9+
install(
10+
FILES ${LAPACK_BINARY_DIR}/include/cblas_f77.h
11+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
12+
COMPONENT Development)
213

3-
file(COPY ${CBLAS_INCLUDE} DESTINATION ${LAPACK_BINARY_DIR}/include)
14+
if(CBLAS)
15+
set(CBLAS_INCLUDE cblas.h cblas_64.h)
16+
file(COPY ${CBLAS_INCLUDE} DESTINATION ${LAPACK_BINARY_DIR}/include)
17+
install(FILES ${CBLAS_INCLUDE}
18+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
19+
COMPONENT Development)
420

5-
file(COPY cblas_test.h DESTINATION ${LAPACK_BINARY_DIR}/test_include)
21+
file(COPY cblas_test.h DESTINATION ${LAPACK_BINARY_DIR}/test_include)
22+
endif()
23+
24+
# Create a header file for CBLAS routine mangling (cblas_mangling.h)
25+
include(CheckLanguage)
26+
check_language(Fortran)
27+
check_language(C)
28+
if(CMAKE_Fortran_COMPILER AND CMAKE_C_COMPILER)
29+
enable_language(Fortran)
30+
enable_language(C)
31+
include(FortranCInterface)
32+
## Ensure that the fortran compiler and c compiler specified are compatible
33+
FortranCInterface_VERIFY()
34+
FortranCInterface_HEADER(${LAPACK_BINARY_DIR}/include/cblas_mangling.h
35+
MACRO_NAMESPACE "F77_"
36+
SYMBOL_NAMESPACE "F77_")
37+
38+
# Check for any necessary platform specific compiler flags
39+
include(CheckLAPACKCompilerFlags)
40+
CheckLAPACKCompilerFlags()
41+
endif()
42+
if(NOT FortranCInterface_GLOBAL_FOUND OR NOT FortranCInterface_MODULE_FOUND)
43+
message(WARNING "Reverting to pre-defined include/cblas_mangling.h")
44+
configure_file(
45+
cblas_mangling_with_flags.h.in
46+
${LAPACK_BINARY_DIR}/include/cblas_mangling.h)
47+
endif()
48+
49+
install(FILES ${LAPACK_BINARY_DIR}/include/cblas_mangling.h
50+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
51+
COMPONENT Development)

CBLAS/include/cblas.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ typedef enum CBLAS_SIDE {CblasLeft=141, CblasRight=142} CBLAS_SIDE;
4444

4545
#define CBLAS_ORDER CBLAS_LAYOUT /* this for backward compatibility with CBLAS_ORDER */
4646

47-
#include "cblas_mangling.h"
48-
4947
/*
5048
* Integer specific API
5149
*/

CBLAS/include/cblas_f77.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef CBLAS_F77_H
1010
#define CBLAS_F77_H
1111

12+
#include "cblas_mangling.h"
13+
1214
#include <stdarg.h>
1315
#include <stdint.h>
1416

@@ -1007,7 +1009,7 @@ void F77_sgemm_base(FCHAR, FCHAR, FINT, FINT, FINT, const float *, const float *
10071009
);
10081010
void F77_sgemmtr_base(FCHAR, FCHAR, FCHAR, FINT, FINT, const float *, const float *, FINT, const float *, FINT, const float *, float *, FINT
10091011
#ifdef BLAS_FORTRAN_STRLEN_END
1010-
, size_t, size_t, size_t
1012+
, FORTRAN_STRLEN, FORTRAN_STRLEN, FORTRAN_STRLEN
10111013
#endif
10121014
);
10131015

@@ -1046,7 +1048,7 @@ void F77_dgemm_base(FCHAR, FCHAR, FINT, FINT, FINT, const double *, const double
10461048
);
10471049
void F77_dgemmtr_base(FCHAR, FCHAR, FCHAR, FINT, FINT, const double *, const double *, FINT, const double *, FINT, const double *, double *, FINT
10481050
#ifdef BLAS_FORTRAN_STRLEN_END
1049-
, size_t, size_t, size_t
1051+
, FORTRAN_STRLEN, FORTRAN_STRLEN, FORTRAN_STRLEN
10501052
#endif
10511053
);
10521054

CMAKE/CheckLAPACKCompilerFlags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ macro(CheckLAPACKCompilerFlags)
5757

5858
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "8")
5959
add_compile_definitions("$<$<COMPILE_LANGUAGE:C>:FORTRAN_STRLEN=int>")
60+
set(FORTRAN_STRLEN_TYPE "int" CACHE INTERNAL "" FORCE)
6061
endif()
6162

6263
# Disabling loop vectorization for GNU Fortran versions affected by
@@ -137,12 +138,14 @@ macro(CheckLAPACKCompilerFlags)
137138
if(UNIX)
138139
if(APPLE)
139140
add_compile_definitions("$<$<COMPILE_LANGUAGE:C>:FORTRAN_STRLEN=int>")
141+
set(FORTRAN_STRLEN_TYPE "int" CACHE INTERNAL "" FORCE)
140142
else()
141143
# Get all flags added via `add_compile_options(...)`
142144
get_directory_property(COMP_OPTIONS COMPILE_OPTIONS)
143145

144146
if(NOT("${CMAKE_Fortran_FLAGS};${COMP_OPTIONS}" MATCHES "-abi=64c"))
145147
add_compile_definitions("$<$<COMPILE_LANGUAGE:C>:FORTRAN_STRLEN=int>")
148+
set(FORTRAN_STRLEN_TYPE "int" CACHE INTERNAL "" FORCE)
146149
endif()
147150
endif()
148151
endif()

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ endif()
258258
# CBLAS
259259
option(CBLAS "Build CBLAS" OFF)
260260

261+
# Include cblas_f77.h and cblas_mangling.h even if CBLAS is not built
262+
if(CBLAS OR NOT BLAS_FOUND)
263+
add_subdirectory(CBLAS/include)
264+
endif()
265+
261266
if(CBLAS)
262267
add_subdirectory(CBLAS)
263268
endif()
@@ -285,7 +290,7 @@ if(LAPACK_LIBRARIES)
285290
check_language(Fortran)
286291
if(CMAKE_Fortran_COMPILER)
287292
enable_language(Fortran)
288-
include(CheckFortranFunctionExists)
293+
incldude(CheckFortranFunctionExists)
289294
set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES})
290295
# Check if new routine of 3.4.0 is in LAPACK_LIBRARIES
291296
CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND)

LAPACKE/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ message(STATUS "Build LAPACKE double precision real: ${LAPACKE_BUILD_DOUBLE}")
3333
message(STATUS "Build LAPACKE single precision complex: ${LAPACKE_BUILD_COMPLEX}")
3434
message(STATUS "Build LAPACKE double precision complex: ${LAPACKE_BUILD_COMPLEX16}")
3535

36-
append_subdir_files(LAPACKE_INCLUDE "include")
3736
append_subdir_files(SOURCES "src")
3837
if (LAPACKE_BUILD_SINGLE)
3938
append_subdir_files(SOURCES_SINGLE "src")
@@ -112,11 +111,6 @@ endif()
112111
target_link_libraries(${LAPACKELIB} PRIVATE ${LAPACK_LIBRARIES})
113112

114113
lapack_install_library(${LAPACKELIB})
115-
install(
116-
FILES ${LAPACKE_INCLUDE} ${LAPACK_BINARY_DIR}/include/lapacke_mangling.h
117-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
118-
COMPONENT Development
119-
)
120114

121115
if(BUILD_TESTING)
122116
add_subdirectory(example)

LAPACKE/include/CMakeLists.txt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
set(LAPACKE_INCLUDE lapack.h)
2-
IF(LAPACKE)
3-
list(APPEND LAPACKE_INCLUDE lapacke.h lapacke_config.h lapacke_utils.h)
1+
# Replace FORTRAN_STRLEN definition in lapack.h if needed
2+
file(READ lapack.h lapack_h_content)
3+
if(FORTRAN_STRLEN_TYPE)
4+
string(REPLACE
5+
"#define FORTRAN_STRLEN size_t" "#define FORTRAN_STRLEN ${FORTRAN_STRLEN_TYPE}"
6+
lapack_h_content "${lapack_h_content}")
47
endif()
8+
file(WRITE ${LAPACK_BINARY_DIR}/include/lapack.h "${lapack_h_content}")
9+
install(
10+
FILES ${LAPACK_BINARY_DIR}/include/lapack.h
11+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
12+
COMPONENT Development
13+
)
514

6-
file(COPY ${LAPACKE_INCLUDE} DESTINATION ${LAPACK_BINARY_DIR}/include)
15+
if(LAPACKE)
16+
list(APPEND LAPACKE_INCLUDE lapacke.h lapacke_64.h lapacke_config.h lapacke_utils.h)
17+
file(COPY ${LAPACKE_INCLUDE} DESTINATION ${LAPACK_BINARY_DIR}/include)
18+
install(
19+
FILES ${LAPACKE_INCLUDE}
20+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
21+
COMPONENT Development
22+
)
23+
endif()
724

8-
# Create a header file lapacke_mangling.h for the routines called in my C programs
25+
# Create a header file for LAPACK routine mangling (lapacke_mangling.h)
926
include(CheckLanguage)
1027
check_language(Fortran)
1128
check_language(C)
@@ -23,4 +40,10 @@ if(NOT FortranCInterface_GLOBAL_FOUND OR NOT FortranCInterface_MODULE_FOUND)
2340
message(WARNING "Reverting to pre-defined include/lapacke_mangling.h")
2441
configure_file(lapacke_mangling_with_flags.h.in
2542
${LAPACK_BINARY_DIR}/include/lapacke_mangling.h)
26-
endif()
43+
endif()
44+
45+
install(
46+
FILES ${LAPACK_BINARY_DIR}/include/lapacke_mangling.h
47+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
48+
COMPONENT Development
49+
)

0 commit comments

Comments
 (0)