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)
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.
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")
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)
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)
40
if(FortranCInterface_MODULE_FOUND OR module_expected)
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")
26
message("This will fail, but let the user see the error")
28
set(FORTRAN_FUNCTIONS test_mod:sub)
30
endif(FORTRAN_C_MODULE_MANGLING_FOUND)
43
set(MYC_DEFS TEST_MOD)
45
message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
46
" linking Fortran module procedures from C")
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
53
SYMBOLS ${FORTRAN_FUNCTIONS}
36
55
include_directories("${testf_BINARY_DIR}")
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"
45
file(GLOB_RECURSE OBJ_OBJFILES
46
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckFortranLink/*.obj")
47
find_program(DUMPBIN dumpbin)
49
foreach(ofile ${O_OBJFILES} ${OBJ_OBJFILES})
51
execute_process(COMMAND ${DUMPBIN} /symbols "${ofile}"
53
message("symbols in ${ofile}:\n${out}")
56
execute_process(COMMAND ${NM} "${ofile}" OUTPUT_VARIABLE out)
57
message("symbols in ${ofile}:\n${out}")
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
66
find_program(DUMPBIN dumpbin)
68
if(FortranCInterface_EXE)
70
execute_process(COMMAND ${DUMPBIN} /symbols "${FortranCInterface_EXE}"
72
message("symbols in ${FortranCInterface_EXE}:\n${out}")
75
execute_process(COMMAND ${NM} "${FortranCInterface_EXE}"
77
message("symbols in ${FortranCInterface_EXE}:\n${out}")
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 ""))
67
"linking in extra C to Fortran libs $ENV{EXTRA_FORTRAN_C_LIBS}")
68
target_link_libraries(foo $ENV{EXTRA_FORTRAN_C_LIBS})
84
add_library(myfort mysub.f ${srcs})
86
add_library(myc myc.c)
87
target_link_libraries(myc myfort)
88
set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
90
add_library(mycxx mycxx.cxx)
91
target_link_libraries(mycxx myc)
93
add_executable(mainc mainc.c)
94
target_link_libraries(mainc myc)
95
add_executable(maincxx maincxx.c)
96
target_link_libraries(maincxx mycxx)
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}")