Skip to content

Commit

Permalink
Reduce number of macros in fortran compilation line for BLAS_64
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrainiuk committed Jun 28, 2023
1 parent e2428ec commit 80b492d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
21 changes: 14 additions & 7 deletions BLAS/SRC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,20 @@ endif()
list(REMOVE_DUPLICATES SOURCES)

add_library(${BLASLIB}_obj OBJECT ${SOURCES})
target_compile_options(${BLASLIB}_obj PRIVATE -fPIC)
set_target_properties(${BLASLIB}_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(BUILD_INDEX64_EXT_API)
set(SOURCES_64_F)
# Copy files so we can set source property specific to /${BLASLIB}_64_obj target
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLASLIB}_64_obj)
file(COPY ${SOURCES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${BLASLIB}_64_obj)
file(GLOB SOURCES_64_F ${CMAKE_CURRENT_BINARY_DIR}/${BLASLIB}_64_obj/*.f*)
add_library(${BLASLIB}_64_obj OBJECT ${SOURCES_64_F})
target_compile_options(${BLASLIB}_64_obj PRIVATE ${FOPT_ILP64})
set_target_properties(${BLASLIB}_64_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)
#Add _64 suffix to all Fortran functions via macros
set(COPT_64_F)
list(APPEND COPT_64_F -cpp)
foreach(F IN LISTS SOURCES)
foreach(F IN LISTS SOURCES_64_F)
set(COPT_64_F -cpp)
file(STRINGS ${F} ${F}.lst)
list(FILTER ${F}.lst INCLUDE REGEX "subroutine|SUBROUTINE|external|EXTERNAL|function|FUNCTION")
list(FILTER ${F}.lst EXCLUDE REGEX "^!.*")
Expand All @@ -128,10 +135,9 @@ if(BUILD_INDEX64_EXT_API)
string(STRIP ${FUNC} FUNC)
list(APPEND COPT_64_F "-D${FUNC}=${FUNC}_64")
endforeach()
list(REMOVE_DUPLICATES COPT_64_F)
set_source_files_properties(${F} PROPERTIES COMPILE_OPTIONS "${COPT_64_F}")
endforeach()
list(REMOVE_DUPLICATES COPT_64_F)
add_library(${BLASLIB}_64_obj OBJECT ${SOURCES})
target_compile_options(${BLASLIB}_64_obj PRIVATE -fPIC ${FOPT_ILP64} ${COPT_64_F})
endif()

add_library(${BLASLIB}
Expand All @@ -142,6 +148,7 @@ set_target_properties(
${BLASLIB} PROPERTIES
VERSION ${LAPACK_VERSION}
SOVERSION ${LAPACK_MAJOR_VERSION}
POSITION_INDEPENDENT_CODE ON
)
lapack_install_library(${BLASLIB})

Expand Down
29 changes: 18 additions & 11 deletions CBLAS/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,38 @@ set_target_properties(${CBLASLIB}_obj PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(BUILD_INDEX64_EXT_API)
# 64bit Integer Interface
# Define list of C files
set(SOURCES_64_C)
set(SOURCES_64_F)
list(APPEND SOURCES_64_C ${SOURCES})
list(APPEND SOURCES_64_F ${SOURCES})
list(FILTER SOURCES_64_C EXCLUDE REGEX "\.f$")
list(FILTER SOURCES_64_F INCLUDE REGEX "\.f$")
list(REMOVE_ITEM SOURCES_64_C cblas_globals.c)
# Define list of Fortran files
set(SOURCES_64_F)
list(APPEND SOURCES_64_F ${SOURCES})
list(FILTER SOURCES_64_F INCLUDE REGEX "\.f$")
# Copy files so we can set source property specific to /${CBLASLIB}_64_obj target
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CBLASLIB}_64_fobj)
file(COPY ${SOURCES_64_F} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CBLASLIB}_64_fobj)
file(GLOB SOURCES_64_F ${CMAKE_CURRENT_BINARY_DIR}/${CBLASLIB}_64_fobj/*)
add_library(${CBLASLIB}_64_cobj OBJECT ${SOURCES_64_C})
add_library(${CBLASLIB}_64_fobj OBJECT ${SOURCES_64_F})
set_target_properties(${CBLASLIB}_64_cobj ${CBLASLIB}_64_fobj PROPERTIES
POSITION_INDEPENDENT_CODE ON
Fortran_PREPROCESS ON)
target_compile_options(${CBLASLIB}_64_cobj PRIVATE -DWeirdNEC -DCBLAS_API64)
target_compile_options(${CBLASLIB}_64_fobj PRIVATE ${FOPT_ILP64})
#Add suffix to all Fortran functions via macros
set(COPT_64_F)
foreach(F IN LISTS SOURCES_64_F)
set(COPT_64_F)
file(STRINGS ${F} ${F}.lst)
list(FILTER ${F}.lst INCLUDE REGEX "subroutine|external")
foreach(FUNC IN LISTS ${F}.lst)
string(REGEX REPLACE "[ ]*(subroutine|external)[ ]*" "" FUNC ${FUNC})
string(REGEX REPLACE "[(][a-zA-Z0-9, ]*[)]" "" FUNC ${FUNC})
list(APPEND COPT_64_F "-D${FUNC}=${FUNC}_64")
endforeach()
set_source_files_properties(${F} PROPERTIES COMPILE_OPTIONS "${COPT_64_F}")
endforeach()
add_library(${CBLASLIB}_64_cobj OBJECT ${SOURCES_64_C})
add_library(${CBLASLIB}_64_fobj OBJECT ${SOURCES_64_F})
set_target_properties(${CBLASLIB}_64_cobj ${CBLASLIB}_64_fobj PROPERTIES
POSITION_INDEPENDENT_CODE ON
Fortran_PREPROCESS ON)
target_compile_options(${CBLASLIB}_64_cobj PRIVATE -DWeirdNEC -DCBLAS_API64)
target_compile_options(${CBLASLIB}_64_fobj PRIVATE ${FOPT_ILP64} ${COPT_64_F})
endif()

add_library(${CBLASLIB}
Expand Down

0 comments on commit 80b492d

Please sign in to comment.