[Openmp-commits] [openmp] [openmp][NFCI] Move .mod code out of runtimes subdir (PR #169909)
Michael Kruse via Openmp-commits
openmp-commits at lists.llvm.org
Fri Nov 28 13:46:17 PST 2025
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/169909
>From eb6ed638be539dc5c514ca9f5d61ee8bb2292d9e Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 11:46:22 +0100
Subject: [PATCH 01/10] Backport openmp
---
openmp/CMakeLists.txt | 31 ++++++++++++
openmp/{runtime => }/cmake/LibompUtils.cmake | 0
openmp/module/CMakeLists.txt | 30 ++++++++++++
.../src/include => module}/omp_lib.F90.var | 0
openmp/runtime/CMakeLists.txt | 25 ++--------
.../cmake/LibompCheckFortranFlag.cmake | 29 ------------
openmp/runtime/cmake/LibompExports.cmake | 13 +++--
openmp/runtime/cmake/LibompHandleFlags.cmake | 11 -----
openmp/runtime/cmake/config-ix.cmake | 4 --
openmp/runtime/src/CMakeLists.txt | 47 +------------------
openmp/runtime/test/lit.cfg | 1 +
openmp/runtime/test/lit.site.cfg.in | 1 +
12 files changed, 75 insertions(+), 117 deletions(-)
rename openmp/{runtime => }/cmake/LibompUtils.cmake (100%)
create mode 100644 openmp/module/CMakeLists.txt
rename openmp/{runtime/src/include => module}/omp_lib.F90.var (100%)
delete mode 100644 openmp/runtime/cmake/LibompCheckFortranFlag.cmake
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index 44cef3fb3f413..b93d8c5701210 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -95,6 +95,24 @@ endif()
# Check and set up common compiler flags.
include(config-ix)
include(HandleOpenMPOptions)
+include(LibompUtils)
+
+
+# Set libomp version
+set(LIBOMP_VERSION_MAJOR 5)
+set(LIBOMP_VERSION_MINOR 0)
+
+# Set the OpenMP Year and Month associated with version
+set(LIBOMP_OMP_YEAR_MONTH 201611)
+
+# Get the build number from kmp_version.cpp
+libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}/runtime" LIBOMP_VERSION_BUILD)
+math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
+math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
+
+# Currently don't record any timestamps
+set(LIBOMP_BUILD_DATE "No_Timestamp")
+
# Check for flang
set(OPENMP_TEST_Fortran_COMPILER_default "")
@@ -104,6 +122,13 @@ endif ()
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
"Fortran compiler to use for testing OpenMP runtime libraries.")
+if (LLVM_RUNTIMES_BUILD)
+ set(LIBOMP_FORTRAN_MODULES "${RUNTIMES_FLANG_MODULES_ENABLED}" CACHE BOOL
+ "Create Fortran module files? (requires fortran compiler)")
+else ()
+ set(LIBOMP_FORTRAN_MODULES OFF)
+endif ()
+
# Set up testing infrastructure.
include(OpenMPTesting)
@@ -111,6 +136,8 @@ set(OPENMP_TEST_FLAGS "" CACHE STRING
"Extra compiler flags to send to the test compiler.")
set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")
+set(OPENMP_TEST_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING
+ "Additional compiler flags to use for testing Fortran programs (e.g. additional module search paths via -fintrinsic-modules-path )")
set(ENABLE_LIBOMPTARGET ON)
# Currently libomptarget cannot be compiled on Windows or MacOS X.
@@ -134,6 +161,10 @@ else()
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
endif()
+if(LIBOMP_FORTRAN_MODULES)
+ add_subdirectory(module)
+endif()
+
# Use the current compiler target to determine the appropriate runtime to build.
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
diff --git a/openmp/runtime/cmake/LibompUtils.cmake b/openmp/cmake/LibompUtils.cmake
similarity index 100%
rename from openmp/runtime/cmake/LibompUtils.cmake
rename to openmp/cmake/LibompUtils.cmake
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
new file mode 100644
index 0000000000000..29f7816aa5998
--- /dev/null
+++ b/openmp/module/CMakeLists.txt
@@ -0,0 +1,30 @@
+#//===----------------------------------------------------------------------===//
+#//
+#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+#// See https://llvm.org/LICENSE.txt for license information.
+#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#//
+#//===----------------------------------------------------------------------===//
+
+# Build the module files if a Fortran compiler is available.
+# Only LLVM_ENABLE_RUNTIMES=openmp is supported, LLVM_ENABLE_PROJECTS=openmp
+# has been deprecated.
+
+configure_file(omp_lib.F90.var "{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
+
+# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod. Only
+# these files are used, the object file itself can be discarded.
+# FIXME: Adding it to libomp.so would allow implementing Fortran API in Fortran
+add_library(libomp-mod OBJECT
+ "{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
+)
+set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Fortran Modules")
+
+if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
+ target_compile_options(libomp-mod PRIVATE -fno-range-check)
+endif()
+
+flang_module_target(libomp-mod PUBLIC)
+if (FORTRAN_MODULE_DEPS)
+ add_dependencies(libomp-mod ${FORTRAN_MODULE_DEPS})
+endif ()
diff --git a/openmp/runtime/src/include/omp_lib.F90.var b/openmp/module/omp_lib.F90.var
similarity index 100%
rename from openmp/runtime/src/include/omp_lib.F90.var
rename to openmp/module/omp_lib.F90.var
diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt
index 93eb14f10a50a..dc0e0e7a81e7c 100644
--- a/openmp/runtime/CMakeLists.txt
+++ b/openmp/runtime/CMakeLists.txt
@@ -15,10 +15,6 @@ endif()
# Add cmake directory to search for custom cmake functions
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
-# Set libomp version
-set(LIBOMP_VERSION_MAJOR 5)
-set(LIBOMP_VERSION_MINOR 0)
-
# These include files are in the cmake/ subdirectory
include(LibompUtils)
include(LibompGetArchitecture)
@@ -102,15 +98,12 @@ libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc ppc64 ppc64le aarch
set(LIBOMP_LIB_TYPE normal CACHE STRING
"Performance,Profiling,Stubs library (normal/profile/stubs)")
libomp_check_variable(LIBOMP_LIB_TYPE normal profile stubs)
-# Set the OpenMP Year and Month associated with version
-set(LIBOMP_OMP_YEAR_MONTH 201611)
set(LIBOMP_MIC_ARCH knc CACHE STRING
"Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
if("${LIBOMP_ARCH}" STREQUAL "mic")
libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
endif()
-set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
- "Create Fortran module files? (requires fortran compiler)")
+
# - Support for universal fat binary builds on Mac
# - Having this extra variable allows people to build this library as a universal library
@@ -147,8 +140,6 @@ else()
set(LIBOMP_LIBFLAGS "" CACHE STRING
"Appended user specified linked libs flags. (e.g., -lm)")
endif()
-set(LIBOMP_FFLAGS "" CACHE STRING
- "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
# Should the libomp library and generated headers be copied into the original source exports/ directory
# Turning this to FALSE aids parallel builds to not interfere with each other.
@@ -163,14 +154,6 @@ set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
"Install path for hwloc library")
-# Get the build number from kmp_version.cpp
-libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
-math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
-math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
-
-# Currently don't record any timestamps
-set(LIBOMP_BUILD_DATE "No_Timestamp")
-
# Architecture
set(IA32 FALSE)
set(INTEL64 FALSE)
@@ -272,10 +255,6 @@ set(LIBOMP_TOOLS_DIR ${LIBOMP_BASE_DIR}/tools)
set(LIBOMP_INC_DIR ${LIBOMP_SRC_DIR}/include)
set(LIBOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
-# Enabling Fortran if it is needed
-if(${LIBOMP_FORTRAN_MODULES})
- enable_language(Fortran)
-endif()
# Enable MASM Compiler if it is needed (Windows only)
if(WIN32)
enable_language(ASM_MASM)
@@ -477,3 +456,5 @@ set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
# make these variables available for tools/libompd:
set(LIBOMP_SRC_DIR ${LIBOMP_SRC_DIR} PARENT_SCOPE)
set(LIBOMP_OMPD_SUPPORT ${LIBOMP_OMPD_SUPPORT} PARENT_SCOPE)
+
+
diff --git a/openmp/runtime/cmake/LibompCheckFortranFlag.cmake b/openmp/runtime/cmake/LibompCheckFortranFlag.cmake
deleted file mode 100644
index 344389f989388..0000000000000
--- a/openmp/runtime/cmake/LibompCheckFortranFlag.cmake
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-#//===----------------------------------------------------------------------===//
-#//
-#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-#// See https://llvm.org/LICENSE.txt for license information.
-#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#//
-#//===----------------------------------------------------------------------===//
-#
-
-# Checking a fortran compiler flag
-# There is no real trivial way to do this in CMake, so we implement it here
-# this will have ${boolean} = TRUE if the flag succeeds, otherwise false.
-function(libomp_check_fortran_flag flag boolean)
- if(NOT DEFINED "${boolean}")
- set(retval TRUE)
- set(fortran_source
-" program hello
- print *, \"Hello World!\"
- end program hello")
-
- # Compiling as a part of runtimes introduces ARCH-unknown-linux-gnu as a
- # part of a working directory. So adding a guard for unknown.
- set(failed_regexes "[Ee]rror;[Uu]nknown[^-];[Ss]kipping")
- include(CheckFortranSourceCompiles)
- check_fortran_source_compiles("${fortran_source}" ${boolean} FAIL_REGEX "${failed_regexes}")
- set(${boolean} ${${boolean}} PARENT_SCOPE)
- endif()
-endfunction()
diff --git a/openmp/runtime/cmake/LibompExports.cmake b/openmp/runtime/cmake/LibompExports.cmake
index 461e47d449157..5b50c570519fb 100644
--- a/openmp/runtime/cmake/LibompExports.cmake
+++ b/openmp/runtime/cmake/LibompExports.cmake
@@ -56,8 +56,8 @@ set(LIBOMP_EXPORTS_LIB_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suf
# Put headers in exports/ directory post build
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_CMN_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ompx.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMP_HEADERS_INTDIR}/omp.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMP_HEADERS_INTDIR}/ompx.h ${LIBOMP_EXPORTS_CMN_DIR}
)
if(${LIBOMP_OMPT_SUPPORT})
add_custom_command(TARGET omp POST_BUILD
@@ -65,11 +65,14 @@ if(${LIBOMP_OMPT_SUPPORT})
)
endif()
if(${LIBOMP_FORTRAN_MODULES})
- add_custom_command(TARGET libomp-mod POST_BUILD
+ # We cannot attach a POST_BUILD command to libomp-mod, so instead attach it
+ # to omp and ensure that libomp-mod is built befoe by adding a dependency
+ add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
)
+ add_dependencies(omp libomp-mod)
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
)
diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/runtime/cmake/LibompHandleFlags.cmake
index c36a88fb862ae..a27c8cc407e11 100644
--- a/openmp/runtime/cmake/LibompHandleFlags.cmake
+++ b/openmp/runtime/cmake/LibompHandleFlags.cmake
@@ -156,17 +156,6 @@ function(libomp_get_libflags libflags)
set(${libflags} ${libflags_local_list} PARENT_SCOPE)
endfunction()
-# Fortran flags
-function(libomp_get_fflags fflags)
- set(fflags_local)
- if(CMAKE_SIZEOF_VOID_P EQUAL 4)
- libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
- endif()
- set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})
- libomp_setup_flags(fflags_local)
- set(${fflags} ${fflags_local} PARENT_SCOPE)
-endfunction()
-
# Python generate-defs.py flags (For Windows only)
function(libomp_get_gdflags gdflags)
set(gdflags_local)
diff --git a/openmp/runtime/cmake/config-ix.cmake b/openmp/runtime/cmake/config-ix.cmake
index 30b69d46a8bd1..150a0c3c7217b 100644
--- a/openmp/runtime/cmake/config-ix.cmake
+++ b/openmp/runtime/cmake/config-ix.cmake
@@ -16,7 +16,6 @@ include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckIncludeFiles)
include(CheckSymbolExists)
-include(LibompCheckFortranFlag)
include(LLVMCheckCompilerLinkerFlag)
# Check for versioned symbols
@@ -97,9 +96,6 @@ if(WIN32)
endforeach()
endforeach()
endif()
-if(${LIBOMP_FORTRAN_MODULES})
- libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
-endif()
# Check non-posix pthread API here before CMAKE_REQUIRED_DEFINITIONS gets messed up
check_symbol_exists(pthread_setname_np "pthread.h" LIBOMP_HAVE_PTHREAD_SETNAME_NP)
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 3202bdcd13524..40a94721bb7aa 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -377,50 +377,7 @@ if(WIN32)
endif()
endif()
-# Building the Fortran module files
-# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
-configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
-
-set(BUILD_FORTRAN_MODULES False)
-if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")
- # If libomp is built as an LLVM runtime and the flang compiler is available,
- # compile the Fortran module files.
- message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
- set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
- add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
- add_custom_command(
- OUTPUT omp_lib.mod omp_lib_kinds.mod
- COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
- )
- set(BUILD_FORTRAN_MODULES True)
-elseif(${LIBOMP_FORTRAN_MODULES})
- # The following requests explicit building of the Fortran module files
- # Workaround for gfortran to build modules with the
- # omp_sched_monotonic integer parameter
- if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
- set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
- endif()
- add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
- set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
- libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
- if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
- set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
- else()
- message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
- endif()
- add_custom_command(
- OUTPUT omp_lib.mod omp_lib_kinds.mod
- COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
- ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
- )
- set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})
- set(BUILD_FORTRAN_MODULES True)
-endif()
# Move files to exports/ directory if requested
if(${LIBOMP_COPY_EXPORTS})
@@ -502,15 +459,13 @@ if(${LIBOMP_OMPT_SUPPORT})
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
endif()
-if(${BUILD_FORTRAN_MODULES})
+if(LIBOMP_FORTRAN_MODULES)
set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
set (destination ${LIBOMP_MODULES_INSTALL_PATH})
endif()
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod
DESTINATION ${destination}
)
endif()
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index 72da1ba1411f8..a4e3aa505638a 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -48,6 +48,7 @@ if config.test_fortran_compiler:
ToolSubst(
"%flang",
command=config.test_fortran_compiler,
+ extra_args=config.test_fortran_flags.split(),
unresolved="fatal",
),
], [config.llvm_tools_dir])
diff --git a/openmp/runtime/test/lit.site.cfg.in b/openmp/runtime/test/lit.site.cfg.in
index cc8b3b252d7d1..fd0ad30228026 100644
--- a/openmp/runtime/test/lit.site.cfg.in
+++ b/openmp/runtime/test/lit.site.cfg.in
@@ -8,6 +8,7 @@ config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
config.test_not = "@OPENMP_NOT_EXECUTABLE@"
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
+config.test_fortran_flags = "@OPENMP_TEST_Fortran_FLAGS@"
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
config.libomp_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
config.library_dir = "@LIBOMP_LIBRARY_DIR@"
>From d9e77c8436257759e2993278226b9c0aa5a095b3 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 13:02:27 +0100
Subject: [PATCH 02/10] Use current .mod building mechanism
---
openmp/CMakeLists.txt | 20 ++--
.../modules/LibompCheckFortranFlag.cmake | 29 +++++
.../modules}/LibompHandleFlags.cmake | 11 ++
openmp/cmake/{ => modules}/LibompUtils.cmake | 0
openmp/module/CMakeLists.txt | 100 ++++++++++++------
openmp/runtime/CMakeLists.txt | 4 -
openmp/runtime/cmake/LibompExports.cmake | 10 +-
openmp/runtime/src/CMakeLists.txt | 2 +-
openmp/runtime/test/lit.cfg | 1 -
openmp/runtime/test/lit.site.cfg.in | 1 -
10 files changed, 126 insertions(+), 52 deletions(-)
create mode 100644 openmp/cmake/modules/LibompCheckFortranFlag.cmake
rename openmp/{runtime/cmake => cmake/modules}/LibompHandleFlags.cmake (96%)
rename openmp/cmake/{ => modules}/LibompUtils.cmake (100%)
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index b93d8c5701210..021052ed8e2a2 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
# Add path for custom modules
list(INSERT CMAKE_MODULE_PATH 0
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
)
@@ -96,6 +97,7 @@ endif()
include(config-ix)
include(HandleOpenMPOptions)
include(LibompUtils)
+include(LibompHandleFlags)
# Set libomp version
@@ -122,13 +124,6 @@ endif ()
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
"Fortran compiler to use for testing OpenMP runtime libraries.")
-if (LLVM_RUNTIMES_BUILD)
- set(LIBOMP_FORTRAN_MODULES "${RUNTIMES_FLANG_MODULES_ENABLED}" CACHE BOOL
- "Create Fortran module files? (requires fortran compiler)")
-else ()
- set(LIBOMP_FORTRAN_MODULES OFF)
-endif ()
-
# Set up testing infrastructure.
include(OpenMPTesting)
@@ -136,8 +131,6 @@ set(OPENMP_TEST_FLAGS "" CACHE STRING
"Extra compiler flags to send to the test compiler.")
set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
"OpenMP compiler flag to use for testing OpenMP runtime libraries.")
-set(OPENMP_TEST_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING
- "Additional compiler flags to use for testing Fortran programs (e.g. additional module search paths via -fintrinsic-modules-path )")
set(ENABLE_LIBOMPTARGET ON)
# Currently libomptarget cannot be compiled on Windows or MacOS X.
@@ -161,8 +154,15 @@ else()
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
endif()
+set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
+ "Create Fortran module files? (requires fortran compiler)")
+
if(LIBOMP_FORTRAN_MODULES)
- add_subdirectory(module)
+ if(LLVM_DEFAULT_TARGET_TRIPLE MATCHES "^amdgcn|^nvptx" OR
+ CMAKE_CXX_COMPILER_TARGET MATCHES "^amdgcn|^nvptx")
+ else ()
+ add_subdirectory(module)
+ endif ()
endif()
# Use the current compiler target to determine the appropriate runtime to build.
diff --git a/openmp/cmake/modules/LibompCheckFortranFlag.cmake b/openmp/cmake/modules/LibompCheckFortranFlag.cmake
new file mode 100644
index 0000000000000..344389f989388
--- /dev/null
+++ b/openmp/cmake/modules/LibompCheckFortranFlag.cmake
@@ -0,0 +1,29 @@
+#
+#//===----------------------------------------------------------------------===//
+#//
+#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+#// See https://llvm.org/LICENSE.txt for license information.
+#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#//
+#//===----------------------------------------------------------------------===//
+#
+
+# Checking a fortran compiler flag
+# There is no real trivial way to do this in CMake, so we implement it here
+# this will have ${boolean} = TRUE if the flag succeeds, otherwise false.
+function(libomp_check_fortran_flag flag boolean)
+ if(NOT DEFINED "${boolean}")
+ set(retval TRUE)
+ set(fortran_source
+" program hello
+ print *, \"Hello World!\"
+ end program hello")
+
+ # Compiling as a part of runtimes introduces ARCH-unknown-linux-gnu as a
+ # part of a working directory. So adding a guard for unknown.
+ set(failed_regexes "[Ee]rror;[Uu]nknown[^-];[Ss]kipping")
+ include(CheckFortranSourceCompiles)
+ check_fortran_source_compiles("${fortran_source}" ${boolean} FAIL_REGEX "${failed_regexes}")
+ set(${boolean} ${${boolean}} PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/openmp/runtime/cmake/LibompHandleFlags.cmake b/openmp/cmake/modules/LibompHandleFlags.cmake
similarity index 96%
rename from openmp/runtime/cmake/LibompHandleFlags.cmake
rename to openmp/cmake/modules/LibompHandleFlags.cmake
index a27c8cc407e11..c36a88fb862ae 100644
--- a/openmp/runtime/cmake/LibompHandleFlags.cmake
+++ b/openmp/cmake/modules/LibompHandleFlags.cmake
@@ -156,6 +156,17 @@ function(libomp_get_libflags libflags)
set(${libflags} ${libflags_local_list} PARENT_SCOPE)
endfunction()
+# Fortran flags
+function(libomp_get_fflags fflags)
+ set(fflags_local)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ libomp_append(fflags_local -m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
+ endif()
+ set(fflags_local ${fflags_local} ${LIBOMP_FFLAGS})
+ libomp_setup_flags(fflags_local)
+ set(${fflags} ${fflags_local} PARENT_SCOPE)
+endfunction()
+
# Python generate-defs.py flags (For Windows only)
function(libomp_get_gdflags gdflags)
set(gdflags_local)
diff --git a/openmp/cmake/LibompUtils.cmake b/openmp/cmake/modules/LibompUtils.cmake
similarity index 100%
rename from openmp/cmake/LibompUtils.cmake
rename to openmp/cmake/modules/LibompUtils.cmake
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 29f7816aa5998..cf26a08d57d04 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -1,30 +1,70 @@
-#//===----------------------------------------------------------------------===//
-#//
-#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-#// See https://llvm.org/LICENSE.txt for license information.
-#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#//
-#//===----------------------------------------------------------------------===//
-
-# Build the module files if a Fortran compiler is available.
-# Only LLVM_ENABLE_RUNTIMES=openmp is supported, LLVM_ENABLE_PROJECTS=openmp
-# has been deprecated.
-
-configure_file(omp_lib.F90.var "{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90" @ONLY)
-
-# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod. Only
-# these files are used, the object file itself can be discarded.
-# FIXME: Adding it to libomp.so would allow implementing Fortran API in Fortran
-add_library(libomp-mod OBJECT
- "{CMAKE_CURRENT_BINARY_DIR}/omp_lib.F90"
-)
-set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Fortran Modules")
-
-if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
- target_compile_options(libomp-mod PRIVATE -fno-range-check)
-endif()
-
-flang_module_target(libomp-mod PUBLIC)
-if (FORTRAN_MODULE_DEPS)
- add_dependencies(libomp-mod ${FORTRAN_MODULE_DEPS})
-endif ()
+#//===----------------------------------------------------------------------===//
+#//
+#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+#// See https://llvm.org/LICENSE.txt for license information.
+#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#//
+#//===----------------------------------------------------------------------===//
+
+enable_language(Fortran)
+
+include(LibompCheckFortranFlag)
+
+set(LIBOMP_FFLAGS "" CACHE STRING
+ "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
+
+libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
+
+# Building the Fortran module files
+# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
+configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
+set(BUILD_FORTRAN_MODULES False)
+if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")
+ # If libomp is built as an LLVM runtime and the flang compiler is available,
+ # compile the Fortran module files.
+ message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
+ set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
+ add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
+ add_custom_command(
+ OUTPUT omp_lib.mod omp_lib_kinds.mod
+ COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
+ )
+ set(BUILD_FORTRAN_MODULES True)
+elseif(${LIBOMP_FORTRAN_MODULES})
+ # The following requests explicit building of the Fortran module files
+ # Workaround for gfortran to build modules with the
+ # omp_sched_monotonic integer parameter
+ if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
+ set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
+ endif()
+ add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
+ set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
+ libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
+ if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
+ else()
+ message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
+ endif()
+ add_custom_command(
+ OUTPUT omp_lib.mod omp_lib_kinds.mod
+ COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
+ ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
+ )
+ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})
+ set(BUILD_FORTRAN_MODULES True)
+endif()
+
+
+if(${BUILD_FORTRAN_MODULES})
+ set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
+ if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
+ set (destination ${LIBOMP_MODULES_INSTALL_PATH})
+ endif()
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod
+ ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod
+ DESTINATION ${destination}
+ )
+endif()
diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt
index dc0e0e7a81e7c..93948b941f0dc 100644
--- a/openmp/runtime/CMakeLists.txt
+++ b/openmp/runtime/CMakeLists.txt
@@ -16,9 +16,7 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# These include files are in the cmake/ subdirectory
-include(LibompUtils)
include(LibompGetArchitecture)
-include(LibompHandleFlags)
include(LibompDefinitions)
# Determine the target architecture
@@ -456,5 +454,3 @@ set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
# make these variables available for tools/libompd:
set(LIBOMP_SRC_DIR ${LIBOMP_SRC_DIR} PARENT_SCOPE)
set(LIBOMP_OMPD_SUPPORT ${LIBOMP_OMPD_SUPPORT} PARENT_SCOPE)
-
-
diff --git a/openmp/runtime/cmake/LibompExports.cmake b/openmp/runtime/cmake/LibompExports.cmake
index 5b50c570519fb..43a26e42b5517 100644
--- a/openmp/runtime/cmake/LibompExports.cmake
+++ b/openmp/runtime/cmake/LibompExports.cmake
@@ -56,8 +56,8 @@ set(LIBOMP_EXPORTS_LIB_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suf
# Put headers in exports/ directory post build
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_CMN_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMP_HEADERS_INTDIR}/omp.h ${LIBOMP_EXPORTS_CMN_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMP_HEADERS_INTDIR}/ompx.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ompx.h ${LIBOMP_EXPORTS_CMN_DIR}
)
if(${LIBOMP_OMPT_SUPPORT})
add_custom_command(TARGET omp POST_BUILD
@@ -66,11 +66,11 @@ if(${LIBOMP_OMPT_SUPPORT})
endif()
if(${LIBOMP_FORTRAN_MODULES})
# We cannot attach a POST_BUILD command to libomp-mod, so instead attach it
- # to omp and ensure that libomp-mod is built befoe by adding a dependency
+ # to omp and ensure that libomp-mod is built before by adding a dependency
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
)
add_dependencies(omp libomp-mod)
add_custom_command(TARGET omp POST_BUILD
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 40a94721bb7aa..a26f1d9d0d175 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -459,7 +459,7 @@ if(${LIBOMP_OMPT_SUPPORT})
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
endif()
-if(LIBOMP_FORTRAN_MODULES)
+if(${BUILD_FORTRAN_MODULES})
set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
set (destination ${LIBOMP_MODULES_INSTALL_PATH})
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index a4e3aa505638a..72da1ba1411f8 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -48,7 +48,6 @@ if config.test_fortran_compiler:
ToolSubst(
"%flang",
command=config.test_fortran_compiler,
- extra_args=config.test_fortran_flags.split(),
unresolved="fatal",
),
], [config.llvm_tools_dir])
diff --git a/openmp/runtime/test/lit.site.cfg.in b/openmp/runtime/test/lit.site.cfg.in
index fd0ad30228026..cc8b3b252d7d1 100644
--- a/openmp/runtime/test/lit.site.cfg.in
+++ b/openmp/runtime/test/lit.site.cfg.in
@@ -8,7 +8,6 @@ config.test_compiler_has_omp_h = @OPENMP_TEST_COMPILER_HAS_OMP_H@
config.test_filecheck = "@OPENMP_FILECHECK_EXECUTABLE@"
config.test_not = "@OPENMP_NOT_EXECUTABLE@"
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
-config.test_fortran_flags = "@OPENMP_TEST_Fortran_FLAGS@"
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
config.libomp_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
config.library_dir = "@LIBOMP_LIBRARY_DIR@"
>From 8233ec84d6229968e5bc1799d3dbfaef8cb36714 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 13:35:05 +0100
Subject: [PATCH 03/10] Allow non-LIBOMP_FORTRAN_MODULES mode
---
openmp/CMakeLists.txt | 13 ++---------
openmp/module/CMakeLists.txt | 45 +++++++++++++++++++-----------------
2 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index 021052ed8e2a2..a82fd20ffe3d9 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -154,17 +154,6 @@ else()
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
endif()
-set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
- "Create Fortran module files? (requires fortran compiler)")
-
-if(LIBOMP_FORTRAN_MODULES)
- if(LLVM_DEFAULT_TARGET_TRIPLE MATCHES "^amdgcn|^nvptx" OR
- CMAKE_CXX_COMPILER_TARGET MATCHES "^amdgcn|^nvptx")
- else ()
- add_subdirectory(module)
- endif ()
-endif()
-
# Use the current compiler target to determine the appropriate runtime to build.
if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
@@ -174,6 +163,8 @@ else()
# are needed to enable time profiling support in the OpenMP runtime.
add_subdirectory(runtime)
+ add_subdirectory(module)
+
set(ENABLE_OMPT_TOOLS ON)
# Currently tools are not tested well on Windows or MacOS X.
if (APPLE OR WIN32)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index cf26a08d57d04..136a679c2709e 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -6,20 +6,23 @@
#//
#//===----------------------------------------------------------------------===//
-enable_language(Fortran)
-
include(LibompCheckFortranFlag)
set(LIBOMP_FFLAGS "" CACHE STRING
"Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
-libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
+# Enabling Fortran if it is needed
+if (LIBOMP_FORTRAN_MODULES)
+ enable_language(Fortran)
+
+ libomp_check_fortran_flag(-m32 LIBOMP_HAVE_M32_FORTRAN_FLAG)
+endif ()
# Building the Fortran module files
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
set(BUILD_FORTRAN_MODULES False)
-if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")
+if (NOT LIBOMP_FORTRAN_MODULES_COMPILER STREQUAL "")
# If libomp is built as an LLVM runtime and the flang compiler is available,
# compile the Fortran module files.
message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
@@ -28,43 +31,43 @@ if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")
add_custom_command(
OUTPUT omp_lib.mod omp_lib_kinds.mod
COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
+ DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
)
set(BUILD_FORTRAN_MODULES True)
-elseif(${LIBOMP_FORTRAN_MODULES})
+elseif (LIBOMP_FORTRAN_MODULES)
# The following requests explicit building of the Fortran module files
# Workaround for gfortran to build modules with the
# omp_sched_monotonic integer parameter
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
- endif()
+ endif ()
add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
- if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
+ if (CMAKE_Fortran_COMPILER_SUPPORTS_F90)
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
- else()
+ else ()
message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
- endif()
+ endif ()
add_custom_command(
OUTPUT omp_lib.mod omp_lib_kinds.mod
COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
+ DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
)
- set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})
+ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "omp_lib${CMAKE_C_OUTPUT_EXTENSION}")
set(BUILD_FORTRAN_MODULES True)
-endif()
+endif ()
-if(${BUILD_FORTRAN_MODULES})
- set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
- if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
- set (destination ${LIBOMP_MODULES_INSTALL_PATH})
- endif()
+if (BUILD_FORTRAN_MODULES)
+ set(destination ${LIBOMP_HEADERS_INSTALL_PATH})
+ if (NOT LIBOMP_MODULES_INSTALL_PATH STREQUAL "")
+ set(destination ${LIBOMP_MODULES_INSTALL_PATH})
+ endif ()
install(FILES
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod
+ "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod"
+ "${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod"
DESTINATION ${destination}
)
-endif()
+endif ()
>From 13f950ace94bd654ac56e78f255b4175741e2930 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 13:54:49 +0100
Subject: [PATCH 04/10] Also move omp_lib.h
---
openmp/module/CMakeLists.txt | 3 +++
openmp/{runtime/src/include => module}/omp_lib.h.var | 0
openmp/runtime/cmake/LibompExports.cmake | 2 +-
openmp/runtime/src/CMakeLists.txt | 12 ------------
4 files changed, 4 insertions(+), 13 deletions(-)
rename openmp/{runtime/src/include => module}/omp_lib.h.var (100%)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 136a679c2709e..7ba78a0f835ea 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -21,6 +21,8 @@ endif ()
# Building the Fortran module files
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
+configure_file(omp_lib.h.var omp_lib.h @ONLY)
+
set(BUILD_FORTRAN_MODULES False)
if (NOT LIBOMP_FORTRAN_MODULES_COMPILER STREQUAL "")
# If libomp is built as an LLVM runtime and the flang compiler is available,
@@ -68,6 +70,7 @@ if (BUILD_FORTRAN_MODULES)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod"
"${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod"
+ "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h"
DESTINATION ${destination}
)
endif ()
diff --git a/openmp/runtime/src/include/omp_lib.h.var b/openmp/module/omp_lib.h.var
similarity index 100%
rename from openmp/runtime/src/include/omp_lib.h.var
rename to openmp/module/omp_lib.h.var
diff --git a/openmp/runtime/cmake/LibompExports.cmake b/openmp/runtime/cmake/LibompExports.cmake
index 43a26e42b5517..f5f454c817db0 100644
--- a/openmp/runtime/cmake/LibompExports.cmake
+++ b/openmp/runtime/cmake/LibompExports.cmake
@@ -74,7 +74,7 @@ if(${LIBOMP_FORTRAN_MODULES})
)
add_dependencies(omp libomp-mod)
add_custom_command(TARGET omp POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
)
endif()
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index a26f1d9d0d175..0c0804776a774 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -377,8 +377,6 @@ if(WIN32)
endif()
endif()
-configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
-
# Move files to exports/ directory if requested
if(${LIBOMP_COPY_EXPORTS})
include(LibompExports)
@@ -459,13 +457,3 @@ if(${LIBOMP_OMPT_SUPPORT})
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
endif()
-if(${BUILD_FORTRAN_MODULES})
- set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
- if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
- set (destination ${LIBOMP_MODULES_INSTALL_PATH})
- endif()
- install(FILES
- ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
- DESTINATION ${destination}
- )
-endif()
>From eea00f4d7b5605606e31778dd1ec05e8640d9fbd Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 14:35:46 +0100
Subject: [PATCH 05/10] CMake-ify
---
openmp/CMakeLists.txt | 4 ++--
openmp/module/CMakeLists.txt | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index a82fd20ffe3d9..514cbdd78f354 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -159,12 +159,12 @@ if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx" OR
"${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx")
add_subdirectory(device)
else()
+ add_subdirectory(module)
+
# Build host runtime library, after LIBOMPTARGET variables are set since they
# are needed to enable time profiling support in the OpenMP runtime.
add_subdirectory(runtime)
- add_subdirectory(module)
-
set(ENABLE_OMPT_TOOLS ON)
# Currently tools are not tested well on Windows or MacOS X.
if (APPLE OR WIN32)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 7ba78a0f835ea..b92ff1f946fc8 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -24,7 +24,7 @@ configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
configure_file(omp_lib.h.var omp_lib.h @ONLY)
set(BUILD_FORTRAN_MODULES False)
-if (NOT LIBOMP_FORTRAN_MODULES_COMPILER STREQUAL "")
+if (LIBOMP_FORTRAN_MODULES_COMPILER)
# If libomp is built as an LLVM runtime and the flang compiler is available,
# compile the Fortran module files.
message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
@@ -63,9 +63,9 @@ endif ()
if (BUILD_FORTRAN_MODULES)
- set(destination ${LIBOMP_HEADERS_INSTALL_PATH})
- if (NOT LIBOMP_MODULES_INSTALL_PATH STREQUAL "")
- set(destination ${LIBOMP_MODULES_INSTALL_PATH})
+ set(destination "${LIBOMP_HEADERS_INSTALL_PATH}")
+ if (LIBOMP_MODULES_INSTALL_PATH)
+ set(destination "${LIBOMP_MODULES_INSTALL_PATH}")
endif ()
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod"
>From 4c8d8ab80930c14ae7d1a0f2ad5d706d3d35026b Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 15:36:31 +0100
Subject: [PATCH 06/10] Diagnostics
---
openmp/module/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index b92ff1f946fc8..c56dd20bb83ad 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -27,7 +27,7 @@ set(BUILD_FORTRAN_MODULES False)
if (LIBOMP_FORTRAN_MODULES_COMPILER)
# If libomp is built as an LLVM runtime and the flang compiler is available,
# compile the Fortran module files.
- message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
+ message(STATUS "configuring openmp to build Fortran module files using '${LIBOMP_FORTRAN_MODULES_COMPILER}'")
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
add_custom_command(
>From 7ddc7a62fc96943d5f17682b3cef4470af89d0b9 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 16:58:13 +0100
Subject: [PATCH 07/10] Reuse original file location where check-flang expects
them
---
openmp/module/CMakeLists.txt | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index c56dd20bb83ad..3ec11407c3f9d 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -21,7 +21,7 @@ endif ()
# Building the Fortran module files
# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
configure_file(omp_lib.F90.var omp_lib.F90 @ONLY)
-configure_file(omp_lib.h.var omp_lib.h @ONLY)
+configure_file(omp_lib.h.var "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h" @ONLY)
set(BUILD_FORTRAN_MODULES False)
if (LIBOMP_FORTRAN_MODULES_COMPILER)
@@ -31,8 +31,8 @@ if (LIBOMP_FORTRAN_MODULES_COMPILER)
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
add_custom_command(
- OUTPUT omp_lib.mod omp_lib_kinds.mod
- COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
+ COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
)
set(BUILD_FORTRAN_MODULES True)
@@ -43,7 +43,7 @@ elseif (LIBOMP_FORTRAN_MODULES)
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
endif ()
- add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
+ 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")
set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
if (CMAKE_Fortran_COMPILER_SUPPORTS_F90)
@@ -52,12 +52,12 @@ elseif (LIBOMP_FORTRAN_MODULES)
message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
endif ()
add_custom_command(
- OUTPUT omp_lib.mod omp_lib_kinds.mod
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
- ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
+ ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}"
)
- set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "omp_lib${CMAKE_C_OUTPUT_EXTENSION}")
+ set_property(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src" PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "omp_lib${CMAKE_C_OUTPUT_EXTENSION}")
set(BUILD_FORTRAN_MODULES True)
endif ()
@@ -68,9 +68,9 @@ if (BUILD_FORTRAN_MODULES)
set(destination "${LIBOMP_MODULES_INSTALL_PATH}")
endif ()
install(FILES
- "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod"
- "${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod"
- "${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod"
+ "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
+ "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h"
DESTINATION ${destination}
)
endif ()
>From ac450527bd805697b713f99f13031835ed079acc Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 17:17:40 +0100
Subject: [PATCH 08/10] Fix DEPENDS
---
openmp/module/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 3ec11407c3f9d..48f5b0f7a2e86 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -29,7 +29,7 @@ if (LIBOMP_FORTRAN_MODULES_COMPILER)
# compile the Fortran module files.
message(STATUS "configuring openmp to build Fortran module files using '${LIBOMP_FORTRAN_MODULES_COMPILER}'")
set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
- add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
+ 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")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.mod" "${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib_kinds.mod"
COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE} "-J${CMAKE_CURRENT_BINARY_DIR}/../runtime/src"
>From 14953c414668a58c7113094d6b0c922502e4d832 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 18:32:15 +0100
Subject: [PATCH 09/10] LIBOMP_COPY_EXPORT from original location
---
openmp/runtime/cmake/LibompExports.cmake | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/openmp/runtime/cmake/LibompExports.cmake b/openmp/runtime/cmake/LibompExports.cmake
index f5f454c817db0..6dfe4f4569aa1 100644
--- a/openmp/runtime/cmake/LibompExports.cmake
+++ b/openmp/runtime/cmake/LibompExports.cmake
@@ -69,12 +69,12 @@ if(${LIBOMP_FORTRAN_MODULES})
# to omp and ensure that libomp-mod is built before by adding a dependency
add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR}
)
add_dependencies(omp libomp-mod)
add_custom_command(TARGET omp POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/../../module/omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
+ COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR}
)
endif()
>From 71005de0ca6de9193a89d49bd1f06afbd560d2f0 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Nov 2025 18:47:29 +0100
Subject: [PATCH 10/10] Re-add LIBOMP_FORTRAN_MODULES visible option
---
openmp/CMakeLists.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index 514cbdd78f354..df568419824a6 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -124,6 +124,9 @@ endif ()
set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
"Fortran compiler to use for testing OpenMP runtime libraries.")
+set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
+ "Create Fortran module files? (requires fortran compiler)")
+
# Set up testing infrastructure.
include(OpenMPTesting)
More information about the Openmp-commits
mailing list