Activate Fortran interface on demand

Not only if we need to compile Fortran code, but also if we need to call
some functions from a Fortran library from C code.
This commit is contained in:
Roland Kaufmann
2013-02-22 21:42:31 +01:00
parent 7871a48551
commit dc3d94e985
2 changed files with 35 additions and 6 deletions

View File

@@ -203,12 +203,11 @@ configure_vars (
WRITE ${${project}_CONFIG_VARS}
)
### --- begin AGMG specific --- ###
include (UseFortranWrappers)
define_fc_func (
APPEND ${CONFIG_H}
IF HAVE_AGMG # HAVE_BLAS HAVE_LAPACK
)
### --- end AGMG specific --- ###
# compile main library; pull in all required includes and libraries
include (OpmCompile)

View File

@@ -1,7 +1,7 @@
# - Provide C wrappers for Fortran code
#
# Synopsis:
# define_fc_func (APPEND config.h)
# define_fc_func (APPEND config.h IF HAVE_BLAS)
function (define_fc_func verb file)
# check that we are being called correctly
@@ -13,10 +13,40 @@ function (define_fc_func verb file)
endif (NOT (("${verb}" STREQUAL "APPEND") OR
("${verb}" STREQUAL "WRITE")))
# check under which conditions we should do our work
if (NOT "${ARGN}" STREQUAL "")
set (args ${ARGN})
list (GET args 0 keyword)
if (NOT "${keyword}" STREQUAL "IF")
message (FATAL_ERROR
"Unknown conditional \"${keyword}\" passed as third argument."
)
endif (NOT "${keyword}" STREQUAL "IF")
list (REMOVE_AT args 0)
set (needed FALSE)
foreach (condition IN LISTS args)
if (${${condition}})
set (needed TRUE)
break ()
endif (${${condition}})
endforeach (condition)
else (NOT "${ARGN}" STREQUAL "")
# if called unconditionally, then always include the wrapper
set (needed TRUE)
endif (NOT "${ARGN}" STREQUAL "")
# only do something if we actually have some components which requires
# the interaction -- don't load the Fortran compiler just to write
# this macro (which apparently nobody uses then)
if (CMAKE_C_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_LOADED)
if (needed)
# enable languages needed
if (NOT CMAKE_C_COMPILER_LOADED)
enable_language (C)
endif (NOT CMAKE_C_COMPILER_LOADED)
if (NOT CMAKE_Fortran_COMPILER_LOADED)
enable_language (Fortran)
endif (NOT CMAKE_Fortran_COMPILER_LOADED)
# get a temporary file
set (_tmp_hdr ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/config_f.h)
@@ -42,7 +72,7 @@ function (define_fc_func verb file)
${_str}
"\n"
)
else (CMAKE_C_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_LOADED)
else (needed)
message (STATUS "Fortran/C interface not activated")
endif (CMAKE_C_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_LOADED)
endif (needed)
endfunction (define_fc_func)