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

« back to all changes in this revision

Viewing changes to Tests/Fortran/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
1
cmake_minimum_required (VERSION 2.6)
2
 
project(testf Fortran C)
 
2
project(testf C CXX Fortran)
3
3
message("CTEST_FULL_OUTPUT ")
4
4
set(CMAKE_VERBOSE_MAKEFILE 1)
5
5
message("ENV_FLAGS = $ENV{FFLAGS}")
7
7
message("CMAKE_Fortran_COMPILER_FULLPATH = ${CMAKE_Fortran_COMPILER_FULLPATH}")
8
8
message("CMAKE_Fortran_COMPILER = ${CMAKE_Fortran_COMPILER}")
9
9
message("CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}")
10
 
add_executable(testf hello.f)
11
 
 
 
10
 
 
11
set(_SHARED SHARED)
 
12
if("${CMAKE_Fortran_COMPILER_ID}" MATCHES "^(XL|VisualAge)$")
 
13
  # We do not implement SHARED Fortran libs on AIX yet!
 
14
  # Workaround: Set LINKER_LANGUAGE to C, which uses 'xlc' and Fortran implicits.
 
15
  set(_SHARED STATIC)
 
16
elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
 
17
  # g77 2.96 does not support shared libs on Itanium because g2c is not -fPIC
 
18
  execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --version
 
19
                  OUTPUT_VARIABLE output ERROR_VARIABLE output)
 
20
  if("${output}" MATCHES "Red Hat .* 2\\.96")
 
21
    set(_SHARED STATIC)
 
22
  endif()
 
23
endif()
 
24
 
 
25
add_library(hello STATIC hello.f)
 
26
add_library(world ${_SHARED} world.f world.def)
 
27
add_executable(testf testf.f)
 
28
target_link_libraries(testf hello world)
12
29
 
13
30
function(test_fortran_c_interface_module)
14
31
  message(STATUS "Testing FortranCInterface module")
15
32
  # test the C to Fortran interface module
16
33
  include(FortranCInterface)
 
34
  FortranCInterface_VERIFY()
 
35
  FortranCInterface_VERIFY(CXX)
17
36
  if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
18
 
    if(FORTRAN_C_MODULE_MANGLING_FOUND)
 
37
    if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro")
 
38
      set(module_expected 1)
 
39
    endif()
 
40
    if(FortranCInterface_MODULE_FOUND OR module_expected)
19
41
      set(srcs foo.f)
20
42
      set(FORTRAN_FUNCTIONS test_mod:sub)
21
 
    else(FORTRAN_C_MODULE_MANGLING_FOUND)
22
 
      if(CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro")
23
 
        message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
24
 
          " linking Fortran module procedures from C")
25
 
      else()
26
 
        message("This will fail, but let the user see the error")
27
 
        set(srcs foo.f)
28
 
        set(FORTRAN_FUNCTIONS test_mod:sub)
29
 
      endif()
30
 
    endif(FORTRAN_C_MODULE_MANGLING_FOUND)
 
43
      set(MYC_DEFS TEST_MOD)
 
44
    else()
 
45
      message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
 
46
        " linking Fortran module procedures from C")
 
47
    endif()
31
48
  endif()
32
 
  set(FORTRAN_FUNCTIONS ${FORTRAN_FUNCTIONS} my_sub mysub )
33
 
  set(srcs ${srcs} mysub.f foo.c)
34
 
  create_fortran_c_interface("F_" FORTRAN_FUNCTIONS 
35
 
    "${testf_BINARY_DIR}/foo.h")
 
49
  list(APPEND FORTRAN_FUNCTIONS my_sub mysub)
 
50
  FortranCInterface_HEADER(foo.h
 
51
    MACRO_NAMESPACE "FC_"
 
52
    SYMBOL_NAMESPACE "F_"
 
53
    SYMBOLS ${FORTRAN_FUNCTIONS}
 
54
    )
36
55
  include_directories("${testf_BINARY_DIR}")
37
 
  
 
56
 
38
57
  # if the name mangling is not found for a F90 compiler
39
58
  # print out some diagnostic stuff for the dashboard
40
 
  if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
41
 
    if(NOT FORTRAN_C_MODULE_MANGLING_FOUND)
42
 
      file(GLOB_RECURSE O_OBJFILES
43
 
        "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckFortranLink/*.o"
44
 
        "*.o" )
45
 
      file(GLOB_RECURSE OBJ_OBJFILES 
46
 
        "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckFortranLink/*.obj")
47
 
      find_program(DUMPBIN dumpbin)
48
 
      find_program(NM nm)
49
 
      foreach(ofile ${O_OBJFILES} ${OBJ_OBJFILES})
50
 
        if(DEPENDS)
51
 
          execute_process(COMMAND ${DUMPBIN} /symbols "${ofile}" 
52
 
            OUTPUT_VARIABLE out)
53
 
          message("symbols in ${ofile}:\n${out}")
54
 
        endif()
55
 
        if(NM)
56
 
          execute_process(COMMAND ${NM} "${ofile}" OUTPUT_VARIABLE out)
57
 
          message("symbols in ${ofile}:\n${out}")
58
 
        endif()
59
 
      endforeach()
 
59
  if(NOT FortranCInterface_GLOBAL_FOUND OR
 
60
      (NOT FortranCInterface_MODULE_FOUND AND module_expected) )
 
61
    find_program(FortranCInterface_EXE
 
62
      NAMES FortranCInterface
 
63
      PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
 
64
      NO_DEFAULT_PATH
 
65
      )
 
66
    find_program(DUMPBIN dumpbin)
 
67
    find_program(NM nm)
 
68
    if(FortranCInterface_EXE)
 
69
      if(DEPENDS)
 
70
        execute_process(COMMAND ${DUMPBIN} /symbols "${FortranCInterface_EXE}"
 
71
                        OUTPUT_VARIABLE out)
 
72
        message("symbols in ${FortranCInterface_EXE}:\n${out}")
 
73
      endif()
 
74
      if(NM)
 
75
        execute_process(COMMAND ${NM} "${FortranCInterface_EXE}"
 
76
                        OUTPUT_VARIABLE out)
 
77
        message("symbols in ${FortranCInterface_EXE}:\n${out}")
 
78
      endif()
60
79
    endif()
61
80
  endif()
62
81
  message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
63
82
  message("C = ${CMAKE_C_COMPILER_ID}")
64
 
  add_executable(foo ${srcs})
65
 
  if(NOT ("$ENV{EXTRA_FORTRAN_C_LIBS}" STREQUAL ""))
66
 
    message(STATUS 
67
 
      "linking in extra C to Fortran libs $ENV{EXTRA_FORTRAN_C_LIBS}")
68
 
    target_link_libraries(foo $ENV{EXTRA_FORTRAN_C_LIBS})
69
 
  endif()
 
83
 
 
84
  add_library(myfort mysub.f ${srcs})
 
85
 
 
86
  add_library(myc myc.c)
 
87
  target_link_libraries(myc myfort)
 
88
  set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
 
89
 
 
90
  add_library(mycxx mycxx.cxx)
 
91
  target_link_libraries(mycxx myc)
 
92
 
 
93
  add_executable(mainc mainc.c)
 
94
  target_link_libraries(mainc myc)
 
95
  add_executable(maincxx maincxx.c)
 
96
  target_link_libraries(maincxx mycxx)
 
97
 
70
98
  # print out some stuff to help debug on machines via cdash
71
99
  file(READ "${testf_BINARY_DIR}/foo.h" fooh)
72
100
  message("foo.h contents:\n${fooh}")
138
166
  # Make sure it uses the same build configuration as this test.
139
167
  if(CMAKE_CONFIGURATION_TYPES)
140
168
    set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
 
169
    set(External_BUILD_TYPE)
141
170
  else(CMAKE_CONFIGURATION_TYPES)
142
171
    set(External_CONFIG_TYPE)
 
172
    set(External_BUILD_TYPE -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE})
143
173
  endif(CMAKE_CONFIGURATION_TYPES)
144
174
  add_custom_command(
145
175
    OUTPUT ${testf_BINARY_DIR}/ExternalProject
159
189
                         -DCMAKE_Fortran_FLAGS_RELEASE:STRING=${CMAKE_Fortran_FLAGS_RELEASE}
160
190
                         -DCMAKE_Fortran_FLAGS_MINSIZEREL:STRING=${CMAKE_Fortran_FLAGS_MINSIZEREL}
161
191
                         -DCMAKE_Fortran_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}
 
192
                         ${External_BUILD_TYPE}
162
193
         )
163
194
  add_custom_target(ExternalTarget ALL DEPENDS ${testf_BINARY_DIR}/ExternalProject)
164
195