~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Modules/FortranCInterface/CMakeLists.txt

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#=============================================================================
 
2
# Copyright 2009 Kitware, Inc.
 
3
#
 
4
# Distributed under the OSI-approved BSD License (the "License");
 
5
# see accompanying file Copyright.txt for details.
 
6
#
 
7
# This software is distributed WITHOUT ANY WARRANTY; without even the
 
8
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
9
# See the License for more information.
 
10
#=============================================================================
 
11
 
 
12
cmake_minimum_required(VERSION 2.6.3)
 
13
project(FortranCInterface C Fortran)
 
14
include(${FortranCInterface_BINARY_DIR}/Input.cmake OPTIONAL)
 
15
 
 
16
# Check if the C compiler supports '$' in identifiers.
 
17
include(CheckCSourceCompiles)
 
18
check_c_source_compiles("
 
19
extern int dollar$(void);
 
20
int main() { return 0; }
 
21
" C_SUPPORTS_DOLLAR)
 
22
 
 
23
# List manglings of global symbol names to try.
 
24
set(global_symbols
 
25
  my_sub    # VisualAge
 
26
  my_sub_   # GNU, Intel, HP, SunPro, MIPSpro
 
27
  my_sub__  # GNU g77
 
28
  MY_SUB    # Intel on Windows
 
29
  mysub     # VisualAge
 
30
  mysub_    # GNU, Intel, HP, SunPro, MIPSpro
 
31
  MYSUB     # Intel on Windows
 
32
  ${FortranCInterface_GLOBAL_SYMBOLS}
 
33
  )
 
34
list(REMOVE_DUPLICATES global_symbols)
 
35
 
 
36
# List manglings of module symbol names to try.
 
37
set(module_symbols
 
38
  __my_module_MOD_my_sub  # GNU 4.3
 
39
  __my_module_NMOD_my_sub # VisualAge
 
40
  __my_module__my_sub     # GNU 4.2
 
41
  __mymodule_MOD_mysub    # GNU 4.3
 
42
  __mymodule_NMOD_mysub   # VisualAge
 
43
  __mymodule__mysub       # GNU 4.2
 
44
  my_module$my_sub        # HP
 
45
  my_module_mp_my_sub_    # Intel
 
46
  MY_MODULE_mp_MY_SUB     # Intel on Windows
 
47
  my_module_my_sub_       # PGI
 
48
  mymodule$mysub          # HP
 
49
  mymodule_mp_mysub_      # Intel
 
50
  MYMODULE_mp_MYSUB       # Intel on Windows
 
51
  mymodule_mysub_         # PGI
 
52
  ${FortranCInterface_MODULE_SYMBOLS}
 
53
  )
 
54
list(REMOVE_DUPLICATES module_symbols)
 
55
 
 
56
# Note that some compiler manglings cannot be invoked from C:
 
57
#   MIPSpro uses "MY_SUB.in.MY_MODULE"
 
58
#   SunPro uses "my_module.my_sub_"
 
59
 
 
60
# Add module symbols only with Fortran90.
 
61
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
 
62
  set(myfort_modules mymodule.f90 my_module.f90)
 
63
  set(call_mod call_mod.f90)
 
64
  set_property(SOURCE main.F PROPERTY COMPILE_DEFINITIONS CALL_MOD)
 
65
else()
 
66
  set(module_symbols)
 
67
endif()
 
68
 
 
69
# Generate C symbol sources.
 
70
foreach(symbol IN LISTS global_symbols module_symbols)
 
71
  # Skip symbols with '$' if C cannot handle them.
 
72
  if(C_SUPPORTS_DOLLAR OR NOT "${symbol}" MATCHES "\\$")
 
73
    if("${symbol}" MATCHES "SUB")
 
74
      set(upper "-UPPER")
 
75
    else()
 
76
      set(upper)
 
77
    endif()
 
78
    string(REPLACE "$" "S" name "${symbol}")
 
79
    set(source ${CMAKE_CURRENT_BINARY_DIR}/symbols/${name}${upper}.c)
 
80
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbol.c.in ${source} @ONLY)
 
81
    list(APPEND symbol_sources ${source})
 
82
  endif()
 
83
endforeach()
 
84
 
 
85
# Provide symbols through Fortran.
 
86
add_library(myfort STATIC mysub.f my_sub.f ${myfort_modules})
 
87
 
 
88
# Provide symbols through C but fall back to Fortran.
 
89
add_library(symbols STATIC mymodule_.c my_module_.c ${symbol_sources})
 
90
target_link_libraries(symbols myfort)
 
91
 
 
92
# Require symbols through Fortran.
 
93
add_executable(FortranCInterface main.F call_sub.f ${call_mod})
 
94
target_link_libraries(FortranCInterface symbols)