[Openmp-commits] [openmp] [OpenMP] Add target to build OpenMP runtime (PR #189557)

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Wed Apr 22 06:58:16 PDT 2026


https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/189557

>From b96b7c092162b42322bbb099ceb02218e1a19d30 Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Wed, 11 Mar 2026 06:55:10 -0500
Subject: [PATCH] Use meta target and register subtargets accordingly

As suggested during review, this implements a top-level meta target
'openmp' that can be used to build all the OpenMP runtime components.

Assisted-by: Cursor Composer
---
 openmp/CMakeLists.txt                    | 6 ++++++
 openmp/cmake/modules/LibompUtils.cmake   | 9 +++++++++
 openmp/device/CMakeLists.txt             | 2 ++
 openmp/libompd/gdb-plugin/CMakeLists.txt | 2 ++
 openmp/libompd/src/CMakeLists.txt        | 2 ++
 openmp/module/CMakeLists.txt             | 2 ++
 openmp/runtime/src/CMakeLists.txt        | 3 +++
 openmp/tools/archer/CMakeLists.txt       | 2 ++
 openmp/tools/omptest/CMakeLists.txt      | 2 ++
 9 files changed, 30 insertions(+)

diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index ff2bfba240e59..a629c9065f85a 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -139,6 +139,12 @@ else()
   get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
 endif()
 
+# Meta-target for building OpenMP runtime artifacts (libraries, device RTL, tools).
+# Subdirectories call openmp_register_meta_dep() for each target they add.
+add_custom_target(openmp ALL
+  COMMENT "OpenMP meta-target. Use 'ninja openmp' to build all OpenMP runtime targets."
+)
+
 # Use the current compiler target to determine the appropriate runtime to build.
 if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgcn|^nvptx|^spirv64" OR
    "${CMAKE_CXX_COMPILER_TARGET}" MATCHES "^amdgcn|^nvptx|^spirv64")
diff --git a/openmp/cmake/modules/LibompUtils.cmake b/openmp/cmake/modules/LibompUtils.cmake
index 011e675d62e37..b0de6895a2686 100644
--- a/openmp/cmake/modules/LibompUtils.cmake
+++ b/openmp/cmake/modules/LibompUtils.cmake
@@ -210,3 +210,12 @@ function(libomp_string_to_list str return_list)
   set(${return_list} "${outstr}" PARENT_SCOPE)
 endfunction()
 
+# Register built targets with the top-level `openmp` meta-target in openmp/CMakeLists.txt.
+function(openmp_register_meta_dep)
+  foreach(tgt IN LISTS ARGN)
+    if(TARGET openmp AND TARGET "${tgt}")
+      add_dependencies(openmp "${tgt}")
+    endif()
+  endforeach()
+endfunction()
+
diff --git a/openmp/device/CMakeLists.txt b/openmp/device/CMakeLists.txt
index 1dbb6e7b494a3..3100fa6c4dd14 100644
--- a/openmp/device/CMakeLists.txt
+++ b/openmp/device/CMakeLists.txt
@@ -106,3 +106,5 @@ set_target_properties(ompdevice PROPERTIES
 )
 target_link_libraries(ompdevice PRIVATE ompdevice.all_objs)
 install(TARGETS ompdevice ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
+
+openmp_register_meta_dep(ompdevice)
diff --git a/openmp/libompd/gdb-plugin/CMakeLists.txt b/openmp/libompd/gdb-plugin/CMakeLists.txt
index 20cb4680e4cbf..f882f6d2cd9e4 100644
--- a/openmp/libompd/gdb-plugin/CMakeLists.txt
+++ b/openmp/libompd/gdb-plugin/CMakeLists.txt
@@ -36,5 +36,7 @@ target_link_libraries (ompdModule ${CMAKE_DL_LIBS})
 set_target_properties (ompdModule PROPERTIES PREFIX "")
 set_target_properties (ompdModule PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/python-module/ompd/")
 
+openmp_register_meta_dep(ompd_gdb_plugin ompdModule)
+
 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python-module/ompd DESTINATION share/gdb/python/ PATTERN ompdModule.so PERMISSIONS OWNER_READ WORLD_READ GROUP_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
 
diff --git a/openmp/libompd/src/CMakeLists.txt b/openmp/libompd/src/CMakeLists.txt
index d3a6061153123..f9804f746158b 100644
--- a/openmp/libompd/src/CMakeLists.txt
+++ b/openmp/libompd/src/CMakeLists.txt
@@ -13,6 +13,8 @@ cmake_minimum_required(VERSION 3.20.0)
 
 add_library (ompd SHARED TargetValue.cpp omp-debug.cpp omp-state.cpp omp-icv.cpp)
 
+openmp_register_meta_dep(ompd)
+
 # libompd must not link against libomp, there is no code dependency.
 add_dependencies(ompd omp) # ensure generated import library is created first
 
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 48f5b0f7a2e86..0a7dfda0cdeec 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -74,3 +74,5 @@ if (BUILD_FORTRAN_MODULES)
     DESTINATION ${destination}
   )
 endif ()
+
+openmp_register_meta_dep(libomp-mod)
diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt
index 5b3e437ba4321..f4e000d7ccc2b 100644
--- a/openmp/runtime/src/CMakeLists.txt
+++ b/openmp/runtime/src/CMakeLists.txt
@@ -189,6 +189,9 @@ else()
   # libomp must be a C++ library such that it can link libLLVMSupport
   set(LIBOMP_LINKER_LANGUAGE CXX)
 endif()
+
+openmp_register_meta_dep(omp)
+
 if(LIBOMP_USE_HWLOC)
   # Since we are using an OBJECT library, the PRIVATE and INTERFACE options are split
   # (instead of using PUBLIC): obj.omp for compiling itself, omp for propagating
diff --git a/openmp/tools/archer/CMakeLists.txt b/openmp/tools/archer/CMakeLists.txt
index a1c768c449d04..c2c5b4cd04b3e 100644
--- a/openmp/tools/archer/CMakeLists.txt
+++ b/openmp/tools/archer/CMakeLists.txt
@@ -34,5 +34,7 @@ if(LIBOMP_OMPT_SUPPORT AND LIBOMP_ARCHER_SUPPORT)
     LIBRARY DESTINATION ${OPENMP_INSTALL_LIBDIR}
     ARCHIVE DESTINATION ${OPENMP_INSTALL_LIBDIR})
 
+  openmp_register_meta_dep(archer archer_static)
+
   add_subdirectory(tests)
 endif()
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index 6e255ea3cb496..f26e1947b4e24 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -122,6 +122,8 @@ if(TARGET cxxabi_shared)
   add_dependencies(omptest cxxabi_shared)
 endif()
 
+openmp_register_meta_dep(omptest)
+
 # Add common include directories.
 target_include_directories(omptest PUBLIC
   $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>



More information about the Openmp-commits mailing list