2009-09-28 19:46:51 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2009 Kitware, Inc.
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
|
|
|
|
2014-05-13 13:02:19 +04:00
|
|
|
cmake_minimum_required(VERSION ${CMAKE_VERSION})
|
2009-08-05 21:40:29 +04:00
|
|
|
project(FortranCInterface C Fortran)
|
|
|
|
include(${FortranCInterface_BINARY_DIR}/Input.cmake OPTIONAL)
|
|
|
|
|
|
|
|
# Check if the C compiler supports '$' in identifiers.
|
|
|
|
include(CheckCSourceCompiles)
|
|
|
|
check_c_source_compiles("
|
|
|
|
extern int dollar$(void);
|
|
|
|
int main() { return 0; }
|
|
|
|
" C_SUPPORTS_DOLLAR)
|
|
|
|
|
|
|
|
# List manglings of global symbol names to try.
|
|
|
|
set(global_symbols
|
|
|
|
my_sub # VisualAge
|
2009-08-06 15:53:32 +04:00
|
|
|
my_sub_ # GNU, Intel, HP, SunPro, MIPSpro
|
2009-08-06 15:53:41 +04:00
|
|
|
my_sub__ # GNU g77
|
2009-10-06 00:30:58 +04:00
|
|
|
MY_SUB # Intel on Windows
|
2009-08-05 21:40:29 +04:00
|
|
|
mysub # VisualAge
|
2009-08-06 15:53:32 +04:00
|
|
|
mysub_ # GNU, Intel, HP, SunPro, MIPSpro
|
2009-10-06 00:30:58 +04:00
|
|
|
MYSUB # Intel on Windows
|
2009-08-05 21:40:29 +04:00
|
|
|
${FortranCInterface_GLOBAL_SYMBOLS}
|
|
|
|
)
|
|
|
|
list(REMOVE_DUPLICATES global_symbols)
|
|
|
|
|
|
|
|
# List manglings of module symbol names to try.
|
|
|
|
set(module_symbols
|
2009-08-06 00:55:57 +04:00
|
|
|
__my_module_MOD_my_sub # GNU 4.3
|
2009-08-05 21:40:29 +04:00
|
|
|
__my_module_NMOD_my_sub # VisualAge
|
2009-08-06 01:07:36 +04:00
|
|
|
__my_module__my_sub # GNU 4.2
|
|
|
|
__mymodule_MOD_mysub # GNU 4.3
|
2009-08-05 21:40:29 +04:00
|
|
|
__mymodule_NMOD_mysub # VisualAge
|
2009-08-06 01:07:36 +04:00
|
|
|
__mymodule__mysub # GNU 4.2
|
2009-08-05 21:40:29 +04:00
|
|
|
my_module$my_sub # HP
|
|
|
|
my_module_mp_my_sub_ # Intel
|
2009-10-06 00:30:58 +04:00
|
|
|
MY_MODULE_mp_MY_SUB # Intel on Windows
|
2009-08-06 01:07:36 +04:00
|
|
|
my_module_my_sub_ # PGI
|
2010-12-10 01:15:48 +03:00
|
|
|
my_module_MP_my_sub # NAG
|
2009-08-05 21:40:29 +04:00
|
|
|
mymodule$mysub # HP
|
|
|
|
mymodule_mp_mysub_ # Intel
|
2009-10-06 00:30:58 +04:00
|
|
|
MYMODULE_mp_MYSUB # Intel on Windows
|
2009-08-06 01:07:36 +04:00
|
|
|
mymodule_mysub_ # PGI
|
2010-12-10 01:15:48 +03:00
|
|
|
mymodule_MP_mysub # NAG
|
2009-08-05 21:40:29 +04:00
|
|
|
${FortranCInterface_MODULE_SYMBOLS}
|
|
|
|
)
|
|
|
|
list(REMOVE_DUPLICATES module_symbols)
|
|
|
|
|
|
|
|
# Note that some compiler manglings cannot be invoked from C:
|
|
|
|
# MIPSpro uses "MY_SUB.in.MY_MODULE"
|
|
|
|
# SunPro uses "my_module.my_sub_"
|
2010-01-22 22:15:47 +03:00
|
|
|
# PathScale uses "MY_SUB.in.MY_MODULE"
|
2009-08-05 21:40:29 +04:00
|
|
|
|
|
|
|
# Add module symbols only with Fortran90.
|
|
|
|
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
|
|
|
|
set(myfort_modules mymodule.f90 my_module.f90)
|
|
|
|
set(call_mod call_mod.f90)
|
|
|
|
set_property(SOURCE main.F PROPERTY COMPILE_DEFINITIONS CALL_MOD)
|
|
|
|
else()
|
|
|
|
set(module_symbols)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Generate C symbol sources.
|
2011-03-24 23:06:58 +03:00
|
|
|
set(symbol_sources)
|
2014-10-14 18:25:32 +04:00
|
|
|
if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(PathScale|Cray)$")
|
2011-03-24 23:06:58 +03:00
|
|
|
# Provide mymodule_ and my_module_ init symbols because:
|
|
|
|
# - PGI Fortran uses module init symbols
|
|
|
|
# but not for:
|
|
|
|
# - PathScale Fortran uses module init symbols but module symbols
|
|
|
|
# use '.in.' so we cannot provide them anyway.
|
|
|
|
# - Cray Fortran >= 7.3.2 uses module init symbols but module symbols
|
|
|
|
# use 'mysub$mymodule_' so we cannot provide them anyway.
|
|
|
|
list(APPEND symbol_sources mymodule_.c my_module_.c)
|
|
|
|
endif()
|
2009-08-05 21:40:29 +04:00
|
|
|
foreach(symbol IN LISTS global_symbols module_symbols)
|
|
|
|
# Skip symbols with '$' if C cannot handle them.
|
|
|
|
if(C_SUPPORTS_DOLLAR OR NOT "${symbol}" MATCHES "\\$")
|
|
|
|
if("${symbol}" MATCHES "SUB")
|
|
|
|
set(upper "-UPPER")
|
|
|
|
else()
|
|
|
|
set(upper)
|
|
|
|
endif()
|
|
|
|
string(REPLACE "$" "S" name "${symbol}")
|
|
|
|
set(source ${CMAKE_CURRENT_BINARY_DIR}/symbols/${name}${upper}.c)
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbol.c.in ${source} @ONLY)
|
|
|
|
list(APPEND symbol_sources ${source})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Provide symbols through Fortran.
|
|
|
|
add_library(myfort STATIC mysub.f my_sub.f ${myfort_modules})
|
|
|
|
|
|
|
|
# Provide symbols through C but fall back to Fortran.
|
2011-03-24 23:06:58 +03:00
|
|
|
add_library(symbols STATIC ${symbol_sources})
|
2009-08-05 21:40:29 +04:00
|
|
|
target_link_libraries(symbols myfort)
|
|
|
|
|
|
|
|
# Require symbols through Fortran.
|
|
|
|
add_executable(FortranCInterface main.F call_sub.f ${call_mod})
|
|
|
|
target_link_libraries(FortranCInterface symbols)
|