Debian Codegraph @

flang/tools/f18/CMakeLists.txt

raw
1 set(LLVM_LINK_COMPONENTS
2 FrontendOpenACC
3 FrontendOpenMP
4 Support
5 )
6
7 # Define the list of Fortran module files that need to be compiled
8 # to produce an object file for inclusion into the FortranRuntime
9 # library.
10 set(MODULES_WITH_IMPLEMENTATION
11 "iso_fortran_env_impl"
12 )
13
14 # Define the list of Fortran module files for which it is
15 # sufficient to generate the module file via -fsyntax-only.
16 set(MODULES_WITHOUT_IMPLEMENTATION
17 "__fortran_builtins"
18 "__fortran_ieee_exceptions"
19 "__fortran_type_info"
20 "__ppc_types"
21 "__ppc_intrinsics"
22 "mma"
23 "__cuda_builtins"
24 "cudadevice"
25 "ieee_arithmetic"
26 "ieee_exceptions"
27 "ieee_features"
28 "iso_c_binding"
29 "iso_fortran_env"
30 )
31
32 set(MODULES ${MODULES_WITH_IMPLEMENTATION} ${MODULES_WITHOUT_IMPLEMENTATION})
33
34 # Init variable to hold extra object files coming from the Fortran modules;
35 # these module files will be contributed from the CMakeLists in flang/tools/f18.
36 set(module_objects "")
37
38 # Create module files directly from the top-level module source directory.
39 # If CMAKE_CROSSCOMPILING, then the newly built flang-new executable was
40 # cross compiled, and thus can't be executed on the build system and thus
41 # can't be used for generating module files.
42 if (NOT CMAKE_CROSSCOMPILING)
43 foreach(filename ${MODULES})
44 set(depends "")
45 set(opts "")
46 if(${filename} STREQUAL "__fortran_builtins" OR
47 ${filename} STREQUAL "__ppc_types")
48 elseif(${filename} STREQUAL "__ppc_intrinsics" OR
49 ${filename} STREQUAL "mma")
50 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__ppc_types.mod)
51 elseif(${filename} STREQUAL "cudadevice")
52 set(opts -fc1 -xcuda)
53 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_builtins.mod)
54 else()
55 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
56 if(NOT ${filename} STREQUAL "__fortran_type_info")
57 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_type_info.mod)
58 endif()
59 if(${filename} STREQUAL "iso_fortran_env")
60 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/iso_fortran_env_impl.mod)
61 endif()
62 if(${filename} STREQUAL "ieee_arithmetic" OR
63 ${filename} STREQUAL "ieee_exceptions")
64 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_ieee_exceptions.mod)
65 endif()
66 endif()
67
68 # The module contains PPC vector types that needs the PPC target.
69 if(${filename} STREQUAL "__ppc_intrinsics" OR
70 ${filename} STREQUAL "mma")
71 if (PowerPC IN_LIST LLVM_TARGETS_TO_BUILD)
72 set(opts "--target=ppc64le")
73 else()
74 # Do not compile PPC module if the target is not available.
75 continue()
76 endif()
77 endif()
78
79
80 # Some modules have an implementation part that needs to be added to the
81 # FortranRuntime library.
82 set(compile_with "-fsyntax-only")
83 set(object_output "")
84 set(include_in_link FALSE)
85 if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
86 set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
87 set(compile_with -c -o ${object_output})
88 set(include_in_link TRUE)
89 endif()
90
91 set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
92 # TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support
93 add_custom_command(OUTPUT ${base}.mod ${object_output}
94 COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
95 COMMAND flang-new ${opts} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
96 ${FLANG_SOURCE_DIR}/module/${filename}.f90
97 DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}
98 )
99 list(APPEND MODULE_FILES ${base}.mod)
100 install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
101
102 # If a module has been compiled into an object file, add the file to
103 # the link line for the FortranRuntime library.
104 if(include_in_link)
105 list(APPEND module_objects ${object_output})
106 endif()
107 endforeach()
108
109 # Set a CACHE variable that is visible to the CMakeLists.txt in runtime/, so that
110 # the compiled Fortran modules can be added to the link line of the FortranRuntime
111 # library.
112 set(FORTRAN_MODULE_OBJECTS ${module_objects} CACHE INTERNAL "" FORCE)
113
114 # Special case for omp_lib.mod, because its source comes from openmp/runtime/src/include.
115 # It also produces two module files: omp_lib.mod and omp_lib_kinds.mod. Compile these
116 # files only if OpenMP support has been configured.
117 if (LLVM_TOOL_OPENMP_BUILD)
118 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLED_PROJECTS, building omp_lib.mod")
119 set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)
120 add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod
121 COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
122 COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
123 ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90
124 DEPENDS flang-new ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}
125 )
126 add_custom_command(OUTPUT ${base}.f18.mod
127 DEPENDS ${base}.mod
128 COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
129 add_custom_command(OUTPUT ${base}_kinds.f18.mod
130 DEPENDS ${base}.mod
131 COMMAND ${CMAKE_COMMAND} -E copy ${base}_kinds.mod ${base}_kinds.f18.mod)
132 list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod)
133 install(FILES ${base}.mod ${base}.f18.mod ${base}_kinds.mod ${base}_kinds.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
134 else()
135 message(STATUS "Not building omp_lib.mod, no OpenMP runtime in LLVM_ENABLED_PROJECTS")
136 endif()
137 endif()
138
139 add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
140 set_target_properties(module_files PROPERTIES FOLDER "Flang/Resources")
141
142 # TODO Move this to a more suitable location
143 # Copy the generated omp_lib.h header file, if OpenMP support has been configured.
144 if (LLVM_TOOL_OPENMP_BUILD)
145 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLED_PROJECTS, building omp_lib.h")
146 file(COPY ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
147 install(FILES ${CMAKE_BINARY_DIR}/include/flang/OpenMP/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")
148 else()
149 message(STATUS "Not copying omp_lib.h, no OpenMP runtime in LLVM_ENABLED_PROJECTS")
150 endif()