Skip to content

Commit

Permalink
Fixed up fortran build so that config.fh file is generated correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpalmer committed Sep 13, 2016
1 parent 749f065 commit 47920b3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 25 deletions.
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ else()
set(HAVE_BLAS 0)
endif()

message(status "BLAS_LIBRARIES: ${BLAS_LIBRARIES}")
message(status "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
message(STATUS "BLAS_LIBRARIES: ${BLAS_LIBRARIES}")
message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
if (HAVE_BLAS)
set(linalg_lib
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES})
endif()

# check for availability of functions by seeing if small programs compile
CHECK_C_SOURCE_COMPILES(
"
Expand Down Expand Up @@ -291,27 +291,31 @@ set (HAVE_ARMCI_INITIALIZED 1)
option (CHECK_COMPILATION_ONLY "Check compilation only" OFF)

if (ENABLE_FORTRAN)
if (Fortran_COMPILER_NAME MATCHES "gfortran.*")
message(STATUS "CMAKE_Fortran_COMPILER: ${CMAKE_Fortran_COMPILER}")
if (CMAKE_Fortran_COMPILER MATCHES "gfortran.*")
set (F90_MODULE )
set (F77_GETARG GETARG)
set (F77_GETARG_ARGS "i,s")
set (F77_GETARG_DECLS "intrinsic GETARG")
set (F77_IARGC IARGC)
set (F77_FLUSH flush)
set (HAVE_F77_FLUSH 1)
elseif (Fortran_COMPILER_NAME MATCHES "ifort.*")
elseif (CMAKE_Fortran_COMPILER MATCHES "ifort.*")
set (F90_MODULE )
set (F77_GETARG GETARG)
set (F77_GETARG_ARGS "i,s")
set (F77_GETARG_DECLS "GETARG")
set (F77_IARGC IARGC)
set (F77_FLUSH flush)
set (HAVE_F77_FLUSH 1)
elseif (Fortran_COMPILER_NAME MATCHES "pgf90.*")
elseif (CMAKE_Fortran_COMPILER MATCHES "pgf90.*")
set (F90_MODULE )
set (F77_GETARG GETARG)
set (F77_GETARG_ARGS "i,s")
set (F77_GETARG_DECLS "GETARG")
set (F77_IARGC IARGC)
set (F77_GETARG_DECLS "external GETARG")
set (F77_IARGC IARGC)
set (F77_FLUSH flush)
set (HAVE_F77_FLUSH 1)
endif()
else()
# need to set these variable even if only compiling C/C++
Expand Down Expand Up @@ -355,13 +359,16 @@ CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/cmake/matypes.h.in
${CMAKE_SOURCE_DIR}/ma/matypes.h )

if (ENABLE_FORTRAN)
message(STATUS "CMAKE_COMMAND:${CMAKE_COMMAND}")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/config.fh
COMMAND ${CMAKE_COMMAND} -D INPUT:PATH="${CMAKE_CURRENT_SOURCE_DIR}/config.h" -D OUTPUT:PATH="${CMAKE_CURRENT_SOURCE_DIR}/config.fh" -P ${PROJECT_SOURCE_DIR}/tools/config_fh_from_h.cmake
DEPENDS config.h
COMMAND ${CMAKE_COMMAND} -D INPUT:PATH="${CMAKE_CURRENT_SOURCE_DIR}/config.h" -D OUTPUT:PATH="${CMAKE_CURRENT_SOURCE_DIR}/config.fh" -P ${PROJECT_SOURCE_DIR}/tools/config_fh_from_h.cmake DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.h
)
add_custom_target(
GenerateConfigFH ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/config.fh
)
set (GA_CONFIG_FH
${CMAKE_CURRENT_SOURCE_DIR}/config.fh)
endif()

# -------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
#define F77_FUNC_(name,NAME) name ## _
*/

#define FXX_MODULE ${F90_MODULE}
#define F77_GETARG ${F77_GETARG}
#define F77_GETARG_ARGS ${F77_GETARG_ARGS}
#define F77_GETARG_DECL ${F77_GETARG_DECLS}
#define F77_IARGC ${F77_IARGC}
#define F77_FLUSH ${F77_FLUSH}
#cmakedefine01 HAVE_F77_FLUSH

#define SIZEOF_INT ${CM_SIZEOF_INT}
#define SIZEOF_DOUBLE ${CM_SIZEOF_DOUBLE}
#define SIZEOF_F77_DOUBLE_PRECISION ${CM_SIZEOF_F77_DOUBLE}
Expand Down
4 changes: 4 additions & 0 deletions gaf2c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ add_library(gaf2c OBJECT
drand.c
${FORTRAN_FILES}
)

if (ENABLE_FORTRAN)
ADD_DEPENDENCIES(ga_src GenerateConfigFH)
endif()
4 changes: 4 additions & 0 deletions global/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ add_library(ga_src OBJECT
${GA_FILES}
)

if(ENABLE_FORTRAN)
ADD_DEPENDENCIES(ga_src GenerateConfigFH)
endif()

# -------------------------------------------------------------
# Global Arrays header installation
# -------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions ma/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ add_library(ma OBJECT
table.c
${FORTRAN_FILES}
)

if (ENABLE_FORTRAN)
ADD_DEPENDENCIES(ga_src GenerateConfigFH)
endif()
21 changes: 8 additions & 13 deletions tools/config_fh_from_h.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
if (INPUT)
if (OUTPUT)
message(STATUS "Reading ${INPUT} ...")
file(READ "${INPUT}" in0)
string(REGEX REPLACE "\r?\n" ";" lines "${in0}")
# replace carriage returns with a semi-colon
string (REGEX REPLACE "\n" ";" in0 "${in0}")
set(out "")
foreach (l ${lines})
# remove comments
string(REGEX REPLACE "/\\*..*\\*/" "" l "${l}")
# ignore lines with leading whitespace
string(REGEX MATCH "^ *" found "${l}")
if (found)
set(l "")
endif ()
if (l)
foreach (l in ${in0})
# Only retain lines that start with "#"
set(found "")
string(REGEX MATCH "^#" found "${l}")
if (found)
set(out "${out}${l}\n")
endif (l)
endif ()
endforeach ()
message(STATUS "Writing ${OUTPUT} ...")
file(WRITE "${OUTPUT}" "${out}")
else (OUTPUT)
message(ERROR "OUTPUT variable must be set")
Expand Down

0 comments on commit 47920b3

Please sign in to comment.