172 lines · plain
1set(LLVM_LINK_COMPONENTS2 FrontendOpenACC3 FrontendOpenMP4 Support5 )6 7# Define the list of Fortran module files for which it is8# sufficient to generate the module file via -fsyntax-only.9set(MODULES10 "__fortran_builtins"11 "__fortran_ieee_exceptions"12 "__fortran_type_info"13 "__ppc_types"14 "__ppc_intrinsics"15 "mma"16 "__cuda_builtins"17 "__cuda_device"18 "cooperative_groups"19 "cudadevice"20 "ieee_arithmetic"21 "ieee_exceptions"22 "ieee_features"23 "iso_c_binding"24 "iso_fortran_env"25 "iso_fortran_env_impl"26 "flang_debug"27)28 29# Check if 128-bit float computations can be done via long double.30check_cxx_source_compiles(31 "#include <cfloat>32 #if LDBL_MANT_DIG != 11333 #error LDBL_MANT_DIG != 11334 #endif35 int main() { return 0; }36 "37 HAVE_LDBL_MANT_DIG_113)38 39# Figure out whether we can support REAL(KIND=16)40if (FLANG_RUNTIME_F128_MATH_LIB)41 set(FLANG_SUPPORT_R16 "1")42elseif (HAVE_LDBL_MANT_DIG_113)43 set(FLANG_SUPPORT_R16 "1")44else()45 set(FLANG_SUPPORT_R16 "0")46endif()47 48# Init variable to hold extra object files coming from the Fortran modules;49# these module files will be contributed from the CMakeLists in flang/tools/f18.50set(module_objects "")51 52# Create module files directly from the top-level module source directory.53# If CMAKE_CROSSCOMPILING, then the newly built flang executable was54# cross compiled, and thus can't be executed on the build system and thus55# can't be used for generating module files.56if (NOT CMAKE_CROSSCOMPILING)57 foreach(filename ${MODULES})58 set(depends "")59 set(opts "")60 if(${filename} STREQUAL "__fortran_builtins" OR61 ${filename} STREQUAL "__ppc_types")62 elseif(${filename} STREQUAL "__ppc_intrinsics" OR63 ${filename} STREQUAL "mma")64 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__ppc_types.mod)65 elseif(${filename} STREQUAL "__cuda_device" OR66 ${filename} STREQUAL "cudadevice" OR67 ${filename} STREQUAL "cooperative_groups")68 set(opts -fc1 -xcuda)69 if(${filename} STREQUAL "__cuda_device")70 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_builtins.mod)71 elseif(${filename} STREQUAL "cudadevice")72 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_device.mod)73 elseif(${filename} STREQUAL "cooperative_groups")74 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/cudadevice.mod)75 endif()76 else()77 set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)78 if(${filename} STREQUAL "iso_fortran_env")79 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/iso_fortran_env_impl.mod)80 endif()81 if(${filename} STREQUAL "ieee_arithmetic" OR82 ${filename} STREQUAL "ieee_exceptions")83 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_ieee_exceptions.mod)84 endif()85 endif()86 if(NOT ${filename} STREQUAL "__fortran_type_info" AND NOT ${filename} STREQUAL "__fortran_builtins")87 set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_type_info.mod)88 endif()89 90 # The module contains PPC vector types that needs the PPC target.91 if(${filename} STREQUAL "__ppc_intrinsics" OR92 ${filename} STREQUAL "mma")93 if (PowerPC IN_LIST LLVM_TARGETS_TO_BUILD)94 set(opts "--target=ppc64le")95 else()96 # Do not compile PPC module if the target is not available.97 continue()98 endif()99 endif()100 101 set(decls "")102 if (FLANG_SUPPORT_R16)103 set(decls "-DFLANG_SUPPORT_R16")104 endif()105 106 # Some modules have an implementation part that needs to be added to the107 # flang_rt.runtime library.108 set(compile_with "-fsyntax-only")109 set(object_output "")110 set(include_in_link FALSE)111 112 set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})113 # TODO: We may need to flag this with conditional, in case Flang is built w/o OpenMP support114 add_custom_command(OUTPUT ${base}.mod ${object_output}115 COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}116 COMMAND flang ${opts} ${decls} -cpp ${compile_with} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}117 ${FLANG_SOURCE_DIR}/module/${filename}.f90118 DEPENDS flang ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${FLANG_SOURCE_DIR}/module/__fortran_builtins.f90 ${depends}119 )120 list(APPEND MODULE_FILES ${base}.mod)121 install(FILES ${base}.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang" COMPONENT flang-module-interfaces)122 123 # If a module has been compiled into an object file, add the file to124 # the link line for the flang_rt.runtime library.125 if(include_in_link)126 list(APPEND module_objects ${object_output})127 endif()128 endforeach()129 130 # Set a CACHE variable that is visible to the CMakeLists.txt in runtime/, so that131 # the compiled Fortran modules can be added to the link line of the flang_rt.runtime132 # library.133 set(FORTRAN_MODULE_OBJECTS ${module_objects} CACHE INTERNAL "" FORCE)134 135 # Special case for omp_lib.mod, because its source comes from openmp/runtime/src/include.136 # It also produces two module files: omp_lib.mod and omp_lib_kinds.mod. Compile these137 # files only if OpenMP support has been configured.138 if (LLVM_TOOL_OPENMP_BUILD)139 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLE_PROJECTS, building omp_lib.mod")140 set(base ${FLANG_INTRINSIC_MODULES_DIR}/omp_lib)141 add_custom_command(OUTPUT ${base}.mod ${base}_kinds.mod142 COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}143 COMMAND flang -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}144 ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90145 DEPENDS flang ${FLANG_INTRINSIC_MODULES_DIR}/iso_c_binding.mod ${CMAKE_BINARY_DIR}/projects/openmp/runtime/src/omp_lib.F90 ${depends}146 )147 list(APPEND MODULE_FILES ${base}.mod ${base}_kinds.mod)148 install(FILES ${base}.mod ${base}_kinds.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang" COMPONENT flang-module-interfaces)149 elseif ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)150 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLE_RUNTIMES, assuming omp_lib.mod is built there")151 else()152 message(WARNING "Not building omp_lib.mod, no OpenMP runtime in either LLVM_ENABLE_PROJECTS or LLVM_ENABLE_RUNTIMES")153 endif()154 add_llvm_install_targets(install-flang-module-interfaces155 COMPONENT flang-module-interfaces)156endif()157 158add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})159set_target_properties(module_files PROPERTIES FOLDER "Flang/Resources")160 161# TODO Move this to a more suitable location162# Copy the generated omp_lib.h header file, if OpenMP support has been configured.163if (LLVM_TOOL_OPENMP_BUILD)164 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLE_PROJECTS, building omp_lib.h")165 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)166 install(FILES ${CMAKE_BINARY_DIR}/include/flang/OpenMP/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")167elseif ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)168 message(STATUS "OpenMP runtime support enabled via LLVM_ENABLE_RUNTIMES, assuming omp_lib.h is built there")169else()170 message(STATUS "Not copying omp_lib.h, no OpenMP runtime in either LLVM_ENABLE_PROJECTS or LLVM_ENABLE_RUNTIMES")171endif()172