[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / flang / tools / f18 / CMakeLists.txt
blob270124bce324046a79b3eaf805943e522aebc7ba
1 set(LLVM_LINK_COMPONENTS
2   FrontendOpenACC
3   FrontendOpenMP
4   Support
5   )
7 set(MODULES
8   "__fortran_builtins"
9   "__fortran_ieee_exceptions"
10   "__fortran_type_info"
11   "__ppc_types"
12   "__ppc_intrinsics"
13   "mma"
14   "__cuda_builtins"
15   "ieee_arithmetic"
16   "ieee_exceptions"
17   "ieee_features"
18   "iso_c_binding"
19   "iso_fortran_env"
20   "omp_lib"
21   "__fortran_builtins"
22   "__fortran_type_info"
25 # Create module files directly from the top-level module source directory.
26 # If CMAKE_CROSSCOMPILING, then the newly built flang-new executable was
27 # cross compiled, and thus can't be executed on the build system and thus
28 # can't be used for generating module files.
29 if (NOT CMAKE_CROSSCOMPILING)
30   foreach(filename ${MODULES})
31     set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
32     if(${filename} STREQUAL "__fortran_builtins")
33       set(depends "")
34     elseif(${filename} STREQUAL "__ppc_types")
35       set(depends "")
36     elseif(${filename} STREQUAL "__ppc_intrinsics" OR
37            ${filename} STREQUAL "mma")
38       set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__ppc_types.mod)
39     else()
40       set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
41       if(NOT ${filename} STREQUAL "__fortran_type_info")
42         set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_type_info.mod)
43       endif()
44       if(${filename} STREQUAL "ieee_arithmetic" OR
45          ${filename} STREQUAL "ieee_exceptions")
46         set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_ieee_exceptions.mod)
47       endif()
48     endif()
50     # The module contains PPC vector types that needs the PPC target.
51     set(opts "")
52     if(${filename} STREQUAL "__ppc_intrinsics" OR
53        ${filename} STREQUAL "mma")
54       set(opts "--target=ppc64le")
55     endif()
57     add_custom_command(OUTPUT ${base}.mod
58       COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
59       COMMAND flang-new -cpp -fsyntax-only ${opts} -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
60         ${FLANG_SOURCE_DIR}/module/${filename}.f90
61       DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${depends}
62     )
63     add_custom_command(OUTPUT ${base}.f18.mod
64       DEPENDS ${base}.mod
65       COMMAND ${CMAKE_COMMAND} -E copy ${base}.mod ${base}.f18.mod)
66     list(APPEND MODULE_FILES ${base}.mod ${base}.f18.mod)
67     install(FILES ${base}.mod ${base}.f18.mod DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang")
68   endforeach()
69 endif()
71 add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
73 # This flang shell script will only work in a POSIX shell.
74 if (NOT WIN32)
75   configure_file(
76     ${CMAKE_CURRENT_SOURCE_DIR}/flang-to-external-fc.in
77     ${CMAKE_BINARY_DIR}/bin/flang-to-external-fc
78     @ONLY
79   )
80   add_custom_target(flang-to-external-fc ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/flang-to-external-fc)
81   install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang-to-external-fc DESTINATION "${CMAKE_INSTALL_BINDIR}")
82 endif()
84 # TODO Move this to a more suitable location
85 file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_BINARY_DIR}/include/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)
86 install(FILES ${CMAKE_BINARY_DIR}/include/flang/OpenMP/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP")