2016-02-05 18:48:20 +03:00
|
|
|
cmake_minimum_required (VERSION 3.1)
|
2009-09-10 00:39:53 +04:00
|
|
|
project(testf C CXX Fortran)
|
2013-12-05 21:44:32 +04:00
|
|
|
|
2008-11-03 20:15:59 +03:00
|
|
|
message("CTEST_FULL_OUTPUT ")
|
2008-11-07 01:33:42 +03:00
|
|
|
set(CMAKE_VERBOSE_MAKEFILE 1)
|
|
|
|
message("ENV_FLAGS = $ENV{FFLAGS}")
|
|
|
|
message("CMAKE_Fortran_COMPILER_INIT = ${CMAKE_Fortran_COMPILER_INIT}")
|
|
|
|
message("CMAKE_Fortran_COMPILER_FULLPATH = ${CMAKE_Fortran_COMPILER_FULLPATH}")
|
|
|
|
message("CMAKE_Fortran_COMPILER = ${CMAKE_Fortran_COMPILER}")
|
|
|
|
message("CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}")
|
2005-02-15 17:01:14 +03:00
|
|
|
|
2009-10-26 18:32:19 +03:00
|
|
|
set(_SHARED SHARED)
|
2014-10-14 18:25:32 +04:00
|
|
|
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(XL|VisualAge)$")
|
2009-10-26 18:32:19 +03:00
|
|
|
# We do not implement SHARED Fortran libs on AIX yet!
|
|
|
|
# Workaround: Set LINKER_LANGUAGE to C, which uses 'xlc' and Fortran implicits.
|
|
|
|
set(_SHARED STATIC)
|
2014-10-14 18:25:32 +04:00
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
|
2009-10-26 18:32:19 +03:00
|
|
|
# g77 2.96 does not support shared libs on Itanium because g2c is not -fPIC
|
|
|
|
execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --version
|
|
|
|
OUTPUT_VARIABLE output ERROR_VARIABLE output)
|
|
|
|
if("${output}" MATCHES "Red Hat .* 2\\.96")
|
|
|
|
set(_SHARED STATIC)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2011-02-23 18:34:28 +03:00
|
|
|
# Pick a module .def file with the properly mangled symbol name.
|
|
|
|
set(world_def "")
|
|
|
|
if(WIN32 AND NOT CYGWIN)
|
2014-10-14 18:25:32 +04:00
|
|
|
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
|
2011-02-23 18:34:28 +03:00
|
|
|
set(world_def world_gnu.def)
|
2014-10-14 18:25:32 +04:00
|
|
|
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel" OR
|
|
|
|
CMAKE_GENERATOR MATCHES "Visual Studio") # Intel plugin
|
2011-02-23 18:34:28 +03:00
|
|
|
set(world_def world_icl.def)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2009-10-23 16:24:51 +04:00
|
|
|
add_library(hello STATIC hello.f)
|
2011-02-23 18:34:28 +03:00
|
|
|
add_library(world ${_SHARED} world.f ${world_def})
|
2009-10-23 16:24:51 +04:00
|
|
|
add_executable(testf testf.f)
|
|
|
|
target_link_libraries(testf hello world)
|
2008-11-05 18:20:51 +03:00
|
|
|
|
|
|
|
function(test_fortran_c_interface_module)
|
|
|
|
message(STATUS "Testing FortranCInterface module")
|
|
|
|
# test the C to Fortran interface module
|
|
|
|
include(FortranCInterface)
|
2009-08-24 21:07:43 +04:00
|
|
|
FortranCInterface_VERIFY()
|
|
|
|
FortranCInterface_VERIFY(CXX)
|
2008-11-05 18:20:51 +03:00
|
|
|
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
|
2011-01-24 19:21:41 +03:00
|
|
|
if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro|PathScale|Absoft")
|
2009-08-05 21:40:29 +04:00
|
|
|
set(module_expected 1)
|
|
|
|
endif()
|
|
|
|
if(FortranCInterface_MODULE_FOUND OR module_expected)
|
2008-10-31 23:08:56 +03:00
|
|
|
set(srcs foo.f)
|
|
|
|
set(FORTRAN_FUNCTIONS test_mod:sub)
|
2009-08-05 21:40:29 +04:00
|
|
|
set(MYC_DEFS TEST_MOD)
|
|
|
|
else()
|
|
|
|
message("${CMAKE_Fortran_COMPILER_ID} compilers do not support"
|
|
|
|
" linking Fortran module procedures from C")
|
|
|
|
endif()
|
2008-11-05 18:20:51 +03:00
|
|
|
endif()
|
2009-08-05 21:40:29 +04:00
|
|
|
list(APPEND FORTRAN_FUNCTIONS my_sub mysub)
|
|
|
|
FortranCInterface_HEADER(foo.h
|
|
|
|
MACRO_NAMESPACE "FC_"
|
|
|
|
SYMBOL_NAMESPACE "F_"
|
|
|
|
SYMBOLS ${FORTRAN_FUNCTIONS}
|
|
|
|
)
|
2016-09-22 21:21:21 +03:00
|
|
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
2009-08-05 21:40:29 +04:00
|
|
|
|
2008-11-05 18:20:51 +03:00
|
|
|
# if the name mangling is not found for a F90 compiler
|
|
|
|
# print out some diagnostic stuff for the dashboard
|
2009-08-05 21:40:29 +04:00
|
|
|
if(NOT FortranCInterface_GLOBAL_FOUND OR
|
|
|
|
(NOT FortranCInterface_MODULE_FOUND AND module_expected) )
|
|
|
|
find_program(FortranCInterface_EXE
|
|
|
|
NAMES FortranCInterface
|
|
|
|
PATHS ${FortranCInterface_BINARY_DIR} ${FortranCInterface_BINARY_DIR}/Debug
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
find_program(DUMPBIN dumpbin)
|
|
|
|
find_program(NM nm)
|
|
|
|
if(FortranCInterface_EXE)
|
|
|
|
if(DEPENDS)
|
|
|
|
execute_process(COMMAND ${DUMPBIN} /symbols "${FortranCInterface_EXE}"
|
|
|
|
OUTPUT_VARIABLE out)
|
|
|
|
message("symbols in ${FortranCInterface_EXE}:\n${out}")
|
|
|
|
endif()
|
|
|
|
if(NM)
|
|
|
|
execute_process(COMMAND ${NM} "${FortranCInterface_EXE}"
|
|
|
|
OUTPUT_VARIABLE out)
|
|
|
|
message("symbols in ${FortranCInterface_EXE}:\n${out}")
|
|
|
|
endif()
|
2008-10-31 23:08:56 +03:00
|
|
|
endif()
|
2008-11-05 18:20:51 +03:00
|
|
|
endif()
|
2008-11-03 20:15:59 +03:00
|
|
|
message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
|
|
|
|
message("C = ${CMAKE_C_COMPILER_ID}")
|
2009-08-04 22:06:45 +04:00
|
|
|
|
|
|
|
add_library(myfort mysub.f ${srcs})
|
|
|
|
|
|
|
|
add_library(myc myc.c)
|
|
|
|
target_link_libraries(myc myfort)
|
2009-08-05 21:40:29 +04:00
|
|
|
set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
|
2009-08-04 22:06:45 +04:00
|
|
|
|
|
|
|
add_library(mycxx mycxx.cxx)
|
|
|
|
target_link_libraries(mycxx myc)
|
|
|
|
|
|
|
|
add_executable(mainc mainc.c)
|
|
|
|
target_link_libraries(mainc myc)
|
|
|
|
add_executable(maincxx maincxx.c)
|
|
|
|
target_link_libraries(maincxx mycxx)
|
|
|
|
|
2008-11-05 18:20:51 +03:00
|
|
|
# print out some stuff to help debug on machines via cdash
|
2016-09-22 21:21:21 +03:00
|
|
|
file(READ "${CMAKE_CURRENT_BINARY_DIR}/foo.h" fooh)
|
2008-11-05 18:20:51 +03:00
|
|
|
message("foo.h contents:\n${fooh}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# if the id's match or the compilers are compatible, then
|
|
|
|
# call the test_fortran_c_interface_module function
|
2011-12-15 18:20:28 +04:00
|
|
|
if("${CMAKE_Fortran_COMPILER_ID}:${CMAKE_C_COMPILER_ID}" MATCHES
|
|
|
|
"(Intel:MSVC|Absoft:GNU)"
|
2016-02-05 18:48:20 +03:00
|
|
|
OR ("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "${CMAKE_C_COMPILER_ID}" ))
|
2008-11-05 18:20:51 +03:00
|
|
|
test_fortran_c_interface_module()
|
2008-11-03 20:15:59 +03:00
|
|
|
else()
|
|
|
|
message("Fortran does not match c compiler")
|
|
|
|
message("Fortran = ${CMAKE_Fortran_COMPILER_ID}")
|
|
|
|
message("C = ${CMAKE_C_COMPILER_ID}")
|
2012-08-13 21:42:58 +04:00
|
|
|
# hack to make g77 work after CL has been enabled
|
2008-11-07 01:33:42 +03:00
|
|
|
# as a languge, cmake needs language specific versions
|
|
|
|
# of these variables....
|
2014-10-14 18:25:32 +04:00
|
|
|
if(WIN32 AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
|
2008-11-07 01:33:42 +03:00
|
|
|
set(CMAKE_CREATE_CONSOLE_EXE )
|
|
|
|
set(CMAKE_LIBRARY_PATH_FLAG "-L")
|
|
|
|
set(CMAKE_LINK_LIBRARY_FLAG "-l")
|
|
|
|
set(CMAKE_LINK_LIBRARY_SUFFIX )
|
|
|
|
endif()
|
2008-11-11 22:03:14 +03:00
|
|
|
# gnu and sunpro do not use the same flags here...
|
|
|
|
# however if LDFLAGS is used to set -m64 it causes odd stuf
|
|
|
|
# with the fortran build
|
2014-10-14 18:25:32 +04:00
|
|
|
if( (CMAKE_C_COMPILER_ID MATCHES "GNU")
|
|
|
|
AND (CMAKE_Fortran_COMPILER_ID MATCHES "SunPro"))
|
2008-11-11 22:03:14 +03:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "")
|
|
|
|
set(CMAKE_Fortran_FLAGS "")
|
2008-11-10 18:53:36 +03:00
|
|
|
endif()
|
2008-11-07 01:33:42 +03:00
|
|
|
|
2008-11-03 20:15:59 +03:00
|
|
|
endif()
|