[llvm-branch-commits] [openmp] release/22.x: [OpenMP][omptest] Fix CMake target properties (#176802) (PR #183775)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Feb 27 09:22:50 PST 2026
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/183775
Backport d5fea7e4f0f2be1f0eae7a3f9e59860632134383 696b91aeb7e55d5fbc82b2e6a625f2a7ca4a6911
Requested by: @mstorsjo
>From 3aa90495848295c99160932fe65b033606edd077 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 4233931ec8660b3c427acf40cbd6672c9eb161b4 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 20:09:29 +0100
Subject: [PATCH 2/2] [OpenMP][omptest] Fix CMake target properties (#176802)
Fix visibility of target properties:
* INCLUDE_DIRECTORIES
* COMPILE_DEFINITIONS
implicitly pulled in from `default_gtest`.
Fixes: https://github.com/llvm/llvm-project/pull/159416
(cherry picked from commit 696b91aeb7e55d5fbc82b2e6a625f2a7ca4a6911)
---
openmp/tools/omptest/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index 63bbd3d7adb84..98ca822367284 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -85,7 +85,7 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
# 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)
+ target_link_libraries(omptest PUBLIC default_gtest)
# Link against Threads (recommended for GTest).
find_package(Threads REQUIRED)
More information about the llvm-branch-commits
mailing list