Debian Codegraph @

openmp/module/CMakeLists.txt

raw
1 #//===----------------------------------------------------------------------===//
2 #//
3 #// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 #// See https://llvm.org/LICENSE.txt for license information.
5 #// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 #//
7 #//===----------------------------------------------------------------------===//
8
9 include(LibompCheckFortranFlag)
10
11 set(LIBOMP_FFLAGS "" CACHE STRING
12 "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
13
14 # Enabling Fortran if it is needed
15 if (LIBOMP_FORTRAN_MODULES)
16 enable_language(Fortran)
17
18 libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
19 endif ()
20
21 # Building the Fortran module files
22 # One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
23 configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
24 configure_file(omp_lib.h.var "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h" @ONLY)
25
26 set(BUILD_FORTRAN_MODULES False)
27 if (LIBOMP_FORTRAN_MODULES_COMPILER)
28 # If libomp is built as an LLVM runtime and the flang compiler is available,
29 # compile the Fortran module files.
30 message(STATUS "configuring openmp to build Fortran module files using '${LIBOMP_FORTRAN_MODULES_COMPILER}'")
31 set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
32 add_custom_target(libomp-mod ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod")
33 add_custom_command(
34 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
35 COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
36 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
37 )
38 set(BUILD_FORTRAN_MODULES True)
39 elseif (LIBOMP_FORTRAN_MODULES)
40 # The following requests explicit building of the Fortran module files
41 # Workaround for gfortran to build modules with the
42 # omp_sched_monotonic integer parameter
43 if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
44 set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
45 endif ()
46 add_custom_target(libomp-mod ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod")
47 set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
48 libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
49 if (CMAKE_Fortran_COMPILER_SUPPORTS_F90)
50 set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
51 else ()
52 message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
53 endif ()
54 add_custom_command(
55 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
56 COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
57 ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
58 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
59 )
60 set_property(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src" PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "omp_lib${CMAKE_C_OUTPUT_EXTENSION}")
61 set(BUILD_FORTRAN_MODULES True)
62 endif ()
63
64
65 if (BUILD_FORTRAN_MODULES)
66 set(destination "${LIBOMP_HEADERS_INSTALL_PATH}")
67 if (LIBOMP_MODULES_INSTALL_PATH)
68 set(destination "${LIBOMP_MODULES_INSTALL_PATH}")
69 endif ()
70 install(FILES
71 "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod"
72 "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
73 "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h"
74 DESTINATION ${destination}
75 )
76 endif ()