[Openmp-commits] [openmp] [OpenMP][omptest] Improve CMake and address review comments (PR #159416)
Michael Halkenhäuser via Openmp-commits
openmp-commits at lists.llvm.org
Mon Jan 19 09:34:59 PST 2026
https://github.com/mhalk updated https://github.com/llvm/llvm-project/pull/159416
>From dbe29b7b0f1c19c2cc4ecc56dd46683a513db63f Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <MichaelGerald.Halkenhauser at amd.com>
Date: Wed, 17 Sep 2025 12:59:59 -0500
Subject: [PATCH 1/4] [OpenMP][omptest] Improve CMake and address review
comments
Avoid explicit ABI breaking check deactivation
Replace whole-archive linking with dedicated build of GoogleTest lib
---
openmp/tools/omptest/CMakeLists.txt | 62 +++++++++++++++++++++--------
1 file changed, 46 insertions(+), 16 deletions(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index b313f223c354c..c9fd9643eb10e 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -51,7 +51,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,26 +65,56 @@ 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)
+ # Set and check GTest's source directory.
+ set(OMPTEST_GTEST_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googletest)
+ if(NOT EXISTS "${OMPTEST_GTEST_PATH}/src/gtest-all.cc")
+ message(FATAL_ERROR "Missing gtest-all.cc under ${OMPTEST_GTEST_PATH}. "
+ "Make sure LLVM_THIRD_PARTY_DIR is set properly.")
+ endif()
+
+ # Build GTest as OBJECT library, so we can merge it into omptest.
+ add_library(omptest_gtest OBJECT "${OMPTEST_GTEST_PATH}/src/gtest-all.cc")
- # Link llvm_gtest as whole-archive to expose required symbols
- set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
- "-Wl,--no-whole-archive" LLVMSupport)
+ # Ensure PIC for inclusion into a shared library on ELF platforms.
+ set_target_properties(omptest_gtest PROPERTIES POSITION_INDEPENDENT_CODE ON)
- # Add GoogleTest-based header
- target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
+ # Set GTest include directories for omptest_gtest
+ target_include_directories(omptest_gtest PRIVATE
+ "${OMPTEST_GTEST_PATH}"
+ "${OMPTEST_GTEST_PATH}/include"
+ )
- # Add LLVM-provided GoogleTest include directories.
- target_include_directories(omptest PRIVATE
- ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)
+ # Set GTest include directories for omptest
+ target_include_directories(omptest PUBLIC
+ $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}>
+ $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}/include>
+ )
- # TODO: Re-visit ABI breaking checks, disable for now.
- target_compile_definitions(omptest PUBLIC
- -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)
+ # Avoid using LLVM-specific ostream helpers inside GoogleTest.
+ target_compile_definitions(omptest_gtest PRIVATE GTEST_NO_LLVM_SUPPORT=1)
- # Link against gtest and gtest_main
- target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
+ # Add GoogleTest-based header and merge GTest into the shared lib.
+ target_sources(omptest PRIVATE
+ ./include/OmptTesterGoogleTest.h
+ $<TARGET_OBJECTS:omptest_gtest>
+ )
+
+ # Link against LLVMSupport and Threads (recommended for GTest).
+ find_package(Threads REQUIRED)
+ target_link_libraries(omptest PUBLIC LLVMSupport 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
+ )
+
+ # Make sure correct include directories are used, e.g. by the unit tests.
+ # Otherwise, ABI-checks may fail.
+ if(DEFINED LLVM_INCLUDE_DIRS)
+ target_include_directories(omptest PUBLIC ${LLVM_INCLUDE_DIRS})
+ endif()
else()
# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
>From b0f7dadd618e771828029952eaaa6228bc246bde Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <MichaelGerald.Halkenhauser at amd.com>
Date: Wed, 12 Nov 2025 10:27:14 -0600
Subject: [PATCH 2/4] fixup! [OpenMP][omptest] Improve CMake and address review
comments
---
openmp/tools/omptest/CMakeLists.txt | 55 ++++++++++++------------
openmp/tools/omptest/test/CMakeLists.txt | 7 +--
2 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index c9fd9643eb10e..3a2cc7e2b3d9c 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})
@@ -65,6 +73,8 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
set(LIBOMPTEST_BUILD_STANDALONE OFF)
endif()
+ message(STATUS "omptest build mode: GTest-based")
+
# Set and check GTest's source directory.
set(OMPTEST_GTEST_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googletest)
if(NOT EXISTS "${OMPTEST_GTEST_PATH}/src/gtest-all.cc")
@@ -72,36 +82,31 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
"Make sure LLVM_THIRD_PARTY_DIR is set properly.")
endif()
- # Build GTest as OBJECT library, so we can merge it into omptest.
- add_library(omptest_gtest OBJECT "${OMPTEST_GTEST_PATH}/src/gtest-all.cc")
-
- # Ensure PIC for inclusion into a shared library on ELF platforms.
- set_target_properties(omptest_gtest PROPERTIES POSITION_INDEPENDENT_CODE ON)
-
- # Set GTest include directories for omptest_gtest
- target_include_directories(omptest_gtest PRIVATE
- "${OMPTEST_GTEST_PATH}"
- "${OMPTEST_GTEST_PATH}/include"
- )
-
# Set GTest include directories for omptest
target_include_directories(omptest PUBLIC
$<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}>
$<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}/include>
)
- # Avoid using LLVM-specific ostream helpers inside GoogleTest.
- target_compile_definitions(omptest_gtest PRIVATE GTEST_NO_LLVM_SUPPORT=1)
+ # Avoid including LLVM-specific header files (e.g. raw-ostream) inside GTest.
+ # This prevents required linking against LLVMSupport.
+ # Make definition public, so dependant targets also get it (e.g. unit tests).
+ target_compile_definitions(omptest PUBLIC GTEST_NO_LLVM_SUPPORT=1)
+
+ # Make the targets default_gtest and default_gtest_main available.
+ build_gtest()
- # Add GoogleTest-based header and merge GTest into the shared lib.
+ # Add GoogleTest-based header and embed GTest symbols into the shared lib.
+ # Merging of GTest is desired, such that omptest is self-contained and
+ # independant of external GTest installations.
target_sources(omptest PRIVATE
./include/OmptTesterGoogleTest.h
- $<TARGET_OBJECTS:omptest_gtest>
+ $<TARGET_OBJECTS:default_gtest>
)
- # Link against LLVMSupport and Threads (recommended for GTest).
+ # Link against Threads (recommended for GTest).
find_package(Threads REQUIRED)
- target_link_libraries(omptest PUBLIC LLVMSupport Threads::Threads)
+ target_link_libraries(omptest PUBLIC Threads::Threads)
# Ensure that embedded GTest symbols are exported from libomptest.so even in
# builds that default to hidden.
@@ -109,13 +114,9 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
CXX_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN OFF
)
-
- # Make sure correct include directories are used, e.g. by the unit tests.
- # Otherwise, ABI-checks may fail.
- if(DEFINED LLVM_INCLUDE_DIRS)
- target_include_directories(omptest PUBLIC ${LLVM_INCLUDE_DIRS})
- endif()
else()
+ message(STATUS "omptest build mode: standalone")
+
# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)
@@ -168,7 +169,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 1b8e0e7af428b189fb7cd7036b10e428c41b37c5 Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <MichaelGerald.Halkenhauser at amd.com>
Date: Thu, 15 Jan 2026 11:27:06 -0600
Subject: [PATCH 3/4] fixup! fixup! [OpenMP][omptest] Improve CMake and address
review comments
---
openmp/tools/omptest/CMakeLists.txt | 28 ++++++----------------------
1 file changed, 6 insertions(+), 22 deletions(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index 3a2cc7e2b3d9c..2b8929e336c6d 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -75,35 +75,19 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
message(STATUS "omptest build mode: GTest-based")
- # Set and check GTest's source directory.
- set(OMPTEST_GTEST_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googletest)
- if(NOT EXISTS "${OMPTEST_GTEST_PATH}/src/gtest-all.cc")
- message(FATAL_ERROR "Missing gtest-all.cc under ${OMPTEST_GTEST_PATH}. "
- "Make sure LLVM_THIRD_PARTY_DIR is set properly.")
- endif()
-
- # Set GTest include directories for omptest
- target_include_directories(omptest PUBLIC
- $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}>
- $<BUILD_INTERFACE:${OMPTEST_GTEST_PATH}/include>
- )
-
- # Avoid including LLVM-specific header files (e.g. raw-ostream) inside GTest.
- # This prevents required linking against LLVMSupport.
- # Make definition public, so dependant targets also get it (e.g. unit tests).
- target_compile_definitions(omptest PUBLIC GTEST_NO_LLVM_SUPPORT=1)
-
- # Make the targets default_gtest and default_gtest_main available.
- build_gtest()
-
# Add GoogleTest-based header and embed GTest symbols into the shared lib.
# Merging of GTest is desired, such that omptest is self-contained and
- # independant of external GTest installations.
+ # independent of external GTest installations.
target_sources(omptest PRIVATE
./include/OmptTesterGoogleTest.h
$<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)
>From d569737e93ec546502eb603ebf3876ce562c0dfd Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <MichaelGerald.Halkenhauser at amd.com>
Date: Mon, 19 Jan 2026 11:31:12 -0600
Subject: [PATCH 4/4] fixup! fixup! fixup! [OpenMP][omptest] Improve CMake and
address review comments
---
openmp/tools/omptest/CMakeLists.txt | 2 --
1 file changed, 2 deletions(-)
diff --git a/openmp/tools/omptest/CMakeLists.txt b/openmp/tools/omptest/CMakeLists.txt
index 2b8929e336c6d..63bbd3d7adb84 100644
--- a/openmp/tools/omptest/CMakeLists.txt
+++ b/openmp/tools/omptest/CMakeLists.txt
@@ -79,7 +79,6 @@ if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
# Merging of GTest is desired, such that omptest is self-contained and
# independent of external GTest installations.
target_sources(omptest PRIVATE
- ./include/OmptTesterGoogleTest.h
$<TARGET_OBJECTS:default_gtest>
)
@@ -107,7 +106,6 @@ else()
# Add 'standalone' source files
target_sources(omptest PRIVATE
- ./include/OmptTesterStandalone.h
./src/OmptTesterStandalone.cpp)
endif()
More information about the Openmp-commits
mailing list