summaryrefslogtreecommitdiff
path: root/CMAKE/FortranMangling.cmake
blob: 98b8443ef4e7b5812741d57a43411ba3e6dbce7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Macro that defines variables describing the Fortran name mangling
# convention
#
# Sets the following outputs on success:
#
#  INTFACE
#    Add_
#    NoChange
#    f77IsF2C
#    UpCase
#    
macro(FORTRAN_MANGLING CDEFS)
MESSAGE(STATUS "=========")
  GET_FILENAME_COMPONENT(F77_NAME ${CMAKE_Fortran_COMPILER} NAME)
  GET_FILENAME_COMPONENT(F77_PATH ${CMAKE_Fortran_COMPILER} PATH)
  SET(F77 ${F77_NAME} CACHE INTERNAL "Name of the fortran compiler.")

  IF(${F77} STREQUAL "ifort.exe")
    #settings for Intel Fortran
    SET(F77_OPTION_COMPILE "/c" CACHE INTERNAL
      "Fortran compiler option for compiling without linking.")
    SET(F77_OUTPUT_OBJ "/Fo" CACHE INTERNAL
      "Fortran compiler option for setting object file name.")
    SET(F77_OUTPUT_EXE "/Fe" CACHE INTERNAL
      "Fortran compiler option for setting executable file name.")
  ELSE(${F77} STREQUAL "ifort.exe")
    # in other case, let user specify their fortran configrations.
    SET(F77_OPTION_COMPILE "-c" CACHE STRING
      "Fortran compiler option for compiling without linking.")
    SET(F77_OUTPUT_OBJ "-o" CACHE STRING
      "Fortran compiler option for setting object file name.")
    SET(F77_OUTPUT_EXE "-o" CACHE STRING
      "Fortran compiler option for setting executable file name.")
    SET(F77_LIB_PATH "" CACHE PATH
      "Library path for the fortran compiler")
    SET(F77_INCLUDE_PATH "" CACHE PATH
      "Include path for the fortran compiler")
  ENDIF(${F77} STREQUAL "ifort.exe")


MESSAGE(STATUS "Testing FORTRAN_MANGLING")
       
MESSAGE(STATUS "Compiling Finface.f...")

    execute_process ( COMMAND  ${CMAKE_Fortran_COMPILER} ${F77_OPTION_COMPILE} ${PROJECT_SOURCE_DIR}/lapacke/mangling/Fintface.f
      WORKING_DIRECTORY  ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
      OUTPUT_VARIABLE    OUTPUT
      RESULT_VARIABLE    RESULT
      ERROR_VARIABLE     ERROR)

    if(RESULT EQUAL 0)
    MESSAGE(STATUS "Compiling Finface.f successful")
    else()
    MESSAGE(FATAL_ERROR " Compiling Finface.f FAILED")
    MESSAGE(FATAL_ERROR " Error:\n ${ERROR}")
    endif()

MESSAGE(STATUS "Compiling Cintface.c...")

    execute_process ( COMMAND  ${CMAKE_C_COMPILER} ${F77_OPTION_COMPILE} ${PROJECT_SOURCE_DIR}/lapacke/mangling/Cintface.c
      WORKING_DIRECTORY  ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
      OUTPUT_VARIABLE    OUTPUT
      RESULT_VARIABLE    RESULT
      ERROR_VARIABLE     ERROR)

    if(RESULT EQUAL 0)
    MESSAGE(STATUS "Compiling Cintface.c successful")
    else()
    MESSAGE(FATAL_ERROR " Compiling Cintface.c FAILED")
    MESSAGE(FATAL_ERROR " Error:\n ${ERROR}")
    endif()

MESSAGE(STATUS "Linking Finface.f and Cintface.c...")

    execute_process ( COMMAND  ${CMAKE_Fortran_COMPILER} ${F77_OUTPUT_OBJ} xintface.exe Fintface.o Cintface.o
      WORKING_DIRECTORY  ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
      OUTPUT_VARIABLE    OUTPUT
      RESULT_VARIABLE    RESULT
      ERROR_VARIABLE     ERROR)

    if(RESULT EQUAL 0)
    MESSAGE(STATUS "Linking Finface.f and Cintface.c successful")
    else()
    MESSAGE(FATAL_ERROR " Linking Finface.f and Cintface.c FAILED")
    MESSAGE(FATAL_ERROR " Error:\n ${ERROR}")
    endif()

MESSAGE(STATUS "Running ./xintface...")

    execute_process ( COMMAND  ./xintface.exe
      WORKING_DIRECTORY  ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
      RESULT_VARIABLE xintface_RES
      OUTPUT_VARIABLE xintface_OUT
      ERROR_VARIABLE xintface_ERR)
                         

       if (xintface_RES EQUAL 0)
          STRING(REPLACE "\n" "" xintface_OUT "${xintface_OUT}")
          MESSAGE(STATUS "Fortran MANGLING convention: ${xintface_OUT}")
          SET(CDEFS ${xintface_OUT})
      else()
          MESSAGE(FATAL_ERROR "FORTRAN_MANGLING:ERROR ${xintface_ERR}")
      endif() 
      
endmacro(FORTRAN_MANGLING)