[llvm-branch-commits] [openmp] release/22.x: [openmp] Allow testing OpenMP in runtimes builds without a full clang build tree (PR #183054)
Martin Storsjö via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Feb 24 05:23:58 PST 2026
https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/183054
None
>From cde7f25aa7ac5c2efbac82491fbfbf6da0d956f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Halkenh=C3=A4user?=
<MichaelGerald.Halkenhauser at amd.com>
Date: Mon, 19 Jan 2026 18:40:32 +0100
Subject: [PATCH 1/2] [OpenMP][omptest] Improve CMake and address review
comments (#159416)
Avoid explicit ABI breaking check deactivation
Replace whole-archive linking with dedicated build of GoogleTest lib
Addresses remaining post-merge review comments of
https://github.com/llvm/llvm-project/pull/154786
(cherry picked from commit d5fea7e4f0f2be1f0eae7a3f9e59860632134383)
---
openmp/tools/omptest/CMakeLists.txt | 61 ++++++++++++++----------
openmp/tools/omptest/test/CMakeLists.txt | 7 +--
2 files changed, 39 insertions(+), 29 deletions(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index b313f223c354c..63bbd3d7adb84 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -8,8 +8,7 @@ cmake_minimum_required(VERSION 3.20)
project(omptest LANGUAGES CXX)
option(LIBOMPTEST_BUILD_STANDALONE
- "Build ompTest 'standalone', i.e. w/o GoogleTest."
- ${OPENMP_STANDALONE_BUILD})
+ "Build ompTest 'standalone', i.e. w/o GoogleTest." OFF)
option(LIBOMPTEST_BUILD_UNITTESTS
"Build ompTest's unit tests, requires GoogleTest." OFF)
option(LIBOMPTEST_INSTALL_COMPONENTS
@@ -20,6 +19,15 @@ if((NOT ${LIBOMP_OMPT_SUPPORT}) OR (NOT ${LLVM_INCLUDE_TESTS}))
return()
endif()
+# Only support OpenMP runtime 'bootstrap' build mode.
+# Check as seen in 'runtimes/CMakeLists.txt', due to passing HAVE_LLVM_LIT to
+# llvm_ExternalProject_Add() only.
+if (NOT HAVE_LLVM_LIT)
+ message(STATUS "Skipping omptest build. Reason: Only supported in bootstrap"
+ " build mode of OpenMP runtime.")
+ return()
+endif()
+
include(CMakePackageConfigHelpers)
include_directories(${LIBOMP_INCLUDE_DIR})
@@ -51,7 +59,7 @@ add_library(omptest
)
# Target: ompTest library
-# On (implicit) request of GoogleTest, link against the one provided with LLVM.
+# On (implicit) request of GoogleTest, embed the sources provided with LLVM.
if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
# Check if standalone build was requested together with unittests
if (LIBOMPTEST_BUILD_STANDALONE)
@@ -65,34 +73,39 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
set(LIBOMPTEST_BUILD_STANDALONE OFF)
endif()
- # Add dependency llvm_gtest; emits error if unavailable.
- add_dependencies(omptest llvm_gtest)
-
- # Link llvm_gtest as whole-archive to expose required symbols
- set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
- "-Wl,--no-whole-archive" LLVMSupport)
-
- # Add GoogleTest-based header
- target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
+ message(STATUS "omptest build mode: GTest-based")
- # Add LLVM-provided GoogleTest include directories.
- target_include_directories(omptest PRIVATE
- ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
-
- # TODO: Re-visit ABI breaking checks, disable for now.
- target_compile_definitions(omptest PUBLIC
- -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
-
- # Link against gtest and gtest_main
- target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
+ # Add GoogleTest-based header and embed GTest symbols into the shared lib.
+ # Merging of GTest is desired, such that omptest is self-contained and
+ # independent of external GTest installations.
+ target_sources(omptest PRIVATE
+ $<TARGET_OBJECTS:default_gtest>
+ )
+
+ # Link against the default GTest which at this point primarily pulls in the
+ # include directories and compile definitions. It is important to make these
+ # available to dependant targets, e.g. for unit tests.
+ target_link_libraries(omptest INTERFACE default_gtest)
+
+ # Link against Threads (recommended for GTest).
+ find_package(Threads REQUIRED)
+ target_link_libraries(omptest PUBLIC Threads::Threads)
+
+ # Ensure that embedded GTest symbols are exported from libomptest.so even in
+ # builds that default to hidden.
+ set_target_properties(omptest PROPERTIES
+ CXX_VISIBILITY_PRESET default
+ VISIBILITY_INLINES_HIDDEN OFF
+ )
else()
+ message(STATUS "omptest build mode: standalone")
+
# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)
# Add 'standalone' source files
target_sources(omptest PRIVATE
- ./include/OmptTesterStandalone.h
./src/OmptTesterStandalone.cpp)
endif()
@@ -138,7 +151,7 @@ if(LIBOMPTEST_INSTALL_COMPONENTS)
# Install library and export targets.
# Note: find_package(omptest) may require setting of PATH_SUFFIXES
- # Example: "lib/cmake/openmp/omptest", this is due to the install location
+ # Example: "lib/cmake/openmp/omptest", due to the install location
install(TARGETS omptest
EXPORT OPENMPomptest
LIBRARY COMPONENT omptest
diff --git a/openmp/tools/omptest/test/CMakeLists.txt b/openmp/tools/omptest/test/CMakeLists.txt
index 2b4aa78b0bc16..1d043b0d8ea4a 100644
--- a/openmp/tools/omptest/test/CMakeLists.txt
+++ b/openmp/tools/omptest/test/CMakeLists.txt
@@ -14,11 +14,8 @@ set(UNITTEST_SOURCES
)
add_executable(omptest-unittests ${UNITTEST_SOURCES})
-# Add local and LLVM-provided GoogleTest include directories.
-target_include_directories(omptest-unittests PRIVATE
- ../include
- ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
-
+# Add local include directory and link omptest library
+target_include_directories(omptest-unittests PRIVATE ../include)
target_link_libraries(omptest-unittests PRIVATE omptest)
set_target_properties(omptest-unittests PROPERTIES
>From 0d6f14f22d2e0acb5255dd49f45017f080856cb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Tue, 24 Feb 2026 14:51:06 +0200
Subject: [PATCH 2/2] [openmp] Allow testing OpenMP in runtimes builds without
a full clang build tree
Having a build tree with "not" and "FileCheck" is still required, but if
Clang/Flang isn't configured in that build, run the tests with the same
compiler CMake uses. This is how testing worked in the standalone build
configurations that now have been removed.
This is a manually adapted backport of
48a5119d8e7d7236a28c14d06ec215ef3366ef90 / #182470 to the 22.x
release branch.
This allows testing OpenMP in the same way on both git main
and the 22.x release branch.
---
openmp/CMakeLists.txt | 33 ++++++++++++++++++--------------
openmp/cmake/OpenMPTesting.cmake | 8 ++++++--
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt
index df568419824a6..cfe01daaa80d5 100644
--- a/openmp/CMakeLists.txt
+++ b/openmp/CMakeLists.txt
@@ -71,13 +71,26 @@ else()
"Path where built OpenMP libraries should be installed.")
endif()
- if (NOT MSVC)
- set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
- set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
- else()
- set(OPENMP_TEST_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang.exe)
- set(OPENMP_TEST_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++.exe)
+ set(OPENMP_TEST_C_COMPILER_default "${LLVM_TOOLS_BINARY_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")
+ set(OPENMP_TEST_CXX_COMPILER_default "${LLVM_TOOLS_BINARY_DIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}")
+ set(OPENMP_TEST_Fortran_COMPILER_default "${LLVM_TOOLS_BINARY_DIR}/flang${CMAKE_EXECUTABLE_SUFFIX}")
+ if (NOT TARGET "clang")
+ set(OPENMP_TEST_C_COMPILER_default "${CMAKE_C_COMPILER}")
+ set(OPENMP_TEST_CXX_COMPILER_default "${CMAKE_CXX_COMPILER}")
+ endif()
+ if (NOT TARGET "flang")
+ if (CMAKE_Fortran_COMPILER)
+ set(OPENMP_TEST_Fortran_COMPILER_default "${CMAKE_Fortran_COMPILER}")
+ else()
+ unset(OPENMP_TEST_Fortran_COMPILER_default)
+ endif()
endif()
+ set(OPENMP_TEST_C_COMPILER "${OPENMP_TEST_C_COMPILER_default}" CACHE STRING
+ "C compiler to use for testing OpenMP runtime libraries.")
+ set(OPENMP_TEST_CXX_COMPILER "${OPENMP_TEST_CXX_COMPILER_default}" CACHE STRING
+ "C++ compiler to use for testing OpenMP runtime libraries.")
+ set(OPENMP_TEST_Fortran_COMPILER "${OPENMP_TEST_Fortran_COMPILER_default}" CACHE STRING
+ "Fortran compiler to use for testing OpenMP runtime libraries.")
# Set fortran test compiler if flang is found
if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
@@ -116,14 +129,6 @@ math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
set(LIBOMP_BUILD_DATE "No_Timestamp")
-# Check for flang
-set(OPENMP_TEST_Fortran_COMPILER_default "")
-if (CMAKE_Fortran_COMPILER)
- set(OPENMP_TEST_Fortran_COMPILER_default "${CMAKE_Fortran_COMPILER}")
-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)")
diff --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake
index 262ea968c8351..f46ff4268b731 100644
--- a/openmp/cmake/OpenMPTesting.cmake
+++ b/openmp/cmake/OpenMPTesting.cmake
@@ -221,19 +221,23 @@ function(add_openmp_testsuite target comment)
USES_TERMINAL
)
else()
+ set(EXTRA_CHECK_DEPENDS "")
+ if (TARGET "clang")
+ list(APPEND EXTRA_CHECK_DEPENDS clang)
+ endif()
if (ARG_EXCLUDE_FROM_CHECK_ALL)
add_lit_testsuite(${target}
${comment}
${ARG_UNPARSED_ARGUMENTS}
EXCLUDE_FROM_CHECK_ALL
- DEPENDS clang FileCheck not ${ARG_DEPENDS}
+ DEPENDS ${EXTRA_CHECK_DEPENDS} FileCheck not ${ARG_DEPENDS}
ARGS ${ARG_ARGS}
)
else()
add_lit_testsuite(${target}
${comment}
${ARG_UNPARSED_ARGUMENTS}
- DEPENDS clang FileCheck not ${ARG_DEPENDS}
+ DEPENDS ${EXTRA_CHECK_DEPENDS} FileCheck not ${ARG_DEPENDS}
ARGS ${ARG_ARGS}
)
endif()
More information about the llvm-branch-commits
mailing list