Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion openmp/cmake/modules/LibompHandleFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ endfunction()

# Linker flags
function(libomp_get_ldflags ldflags)
cmake_parse_arguments(ARG "FOR_UNITTESTS" "" "" ${ARGN})
set(ldflags_local)
libomp_append(ldflags_local "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_LIB_NAME}.def"
IF_DEFINED CMAKE_LINK_DEF_FILE_FLAG)
Expand All @@ -105,7 +106,11 @@ function(libomp_get_ldflags ldflags)
libomp_append(ldflags_local "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR}"
IF_DEFINED CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG)
libomp_append(ldflags_local -Wl,--as-needed LIBOMP_HAVE_AS_NEEDED_FLAG)
libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
if(ARG_FOR_UNITTESTS)
libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
else()
libomp_append(ldflags_local "-Wl,--version-script=${LIBOMP_SRC_DIR}/exports_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
endif()
libomp_append(ldflags_local -static-libgcc LIBOMP_HAVE_STATIC_LIBGCC_FLAG)
libomp_append(ldflags_local -Wl,-z,noexecstack LIBOMP_HAVE_Z_NOEXECSTACK_FLAG)
libomp_append(ldflags_local -no-intel-extensions LIBOMP_HAVE_NO_INTEL_EXTENSIONS_FLAG)
Expand Down
14 changes: 14 additions & 0 deletions openmp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ if(NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH TRUE)
endif()

# Remove any cmake-automatic linking of the standard C++ library.
# We neither need (nor want) the standard C++ library dependency even though we compile C++ files.
if(NOT LIBOMP_USE_STDCPPLIB)
set(LIBOMP_LINKER_LANGUAGE C)
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
else()
set(LIBOMP_LINKER_LANGUAGE CXX)
endif()

if(UNIX)
set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})
endif()

# User specified flags. These are appended to the configured flags.
set(LIBOMP_CXXFLAGS "" CACHE STRING
"Appended user specified C++ compiler flags.")
Expand Down Expand Up @@ -446,6 +459,7 @@ endif()

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(unittests)

# make these variables available for tools:
set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
Expand Down
32 changes: 14 additions & 18 deletions openmp/runtime/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,6 @@ libomp_get_asmflags(LIBOMP_CONFIGURED_ASMFLAGS)
set_source_files_properties(${LIBOMP_CXXFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}")
set_source_files_properties(${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_ASMFLAGS}")

# Remove any cmake-automatic linking of the standard C++ library.
# We neither need (nor want) the standard C++ library dependency even though we compile c++ files.
if(NOT ${LIBOMP_USE_STDCPPLIB})
set(LIBOMP_LINKER_LANGUAGE C)
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
else()
set(LIBOMP_LINKER_LANGUAGE CXX)
endif()

if(UNIX)
set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})
endif()

# Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
# avoid an unwanted dependency on libstdc++.so.
add_compile_definitions(_GLIBCXX_NO_ASSERTIONS)
Expand All @@ -174,17 +161,26 @@ if(NOT WIN32)
endif()

# Add the OpenMP library
libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)

# First, create an OBJECT library with all the runtime sources.
# This allows the unittests later to access internal symbols which don't export
# in libomp.
add_library(obj.omp OBJECT ${LIBOMP_SOURCE_FILES})
set_property(TARGET obj.omp PROPERTY FOLDER "OpenMP/Libraries")
set_property(TARGET obj.omp PROPERTY POSITION_INDEPENDENT_CODE ON)

libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)
libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS)
# Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled.

# Build libomp library. Add LLVMSupport dependency if building in-tree with
# libomptarget profiling enabled.
if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))
add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})
add_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:obj.omp>)
set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries")
# Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS
target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})
else()
add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED
add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} $<TARGET_OBJECTS:obj.omp> PARTIAL_SOURCES_INTENDED
LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}
LINK_COMPONENTS Support
BUILDTREE_ONLY
Expand Down Expand Up @@ -296,7 +292,7 @@ set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
# objects depend on : .inc files
add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc)
set_target_properties(libomp-needed-headers PROPERTIES FOLDER "OpenMP/Sourcegenning")
add_dependencies(omp libomp-needed-headers)
add_dependencies(obj.omp libomp-needed-headers)

# Windows specific build rules
if(WIN32)
Expand Down
22 changes: 22 additions & 0 deletions openmp/runtime/test/Unit/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- Python -*-

# Configuration file for the 'lit' test runner.

import os
import subprocess

import lit.formats

# name: The name of this test suite.
config.name = "OpenMP-Unit"

# suffixes: A list of file extensions to treat as test files.
config.suffixes = []

# test_source_root: The root path where tests are located.
# test_exec_root: The root path where tests should be run.
config.test_exec_root = config.openmp_unittests_dir
config.test_source_root = config.test_exec_root

# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests")
8 changes: 8 additions & 0 deletions openmp/runtime/test/Unit/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@AUTO_GEN_COMMENT@

config.openmp_unittests_dir = "@CMAKE_CURRENT_BINARY_DIR@/../unittests"
config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")

# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/../test/Unit/lit.cfg.py")

3 changes: 3 additions & 0 deletions openmp/runtime/test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ config.name = 'libomp'
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp']

# Exclude Unit tests - they are run separately via check-libomp-unit
config.excludes = ['Unit']

if config.test_fortran_compiler:
lit_config.note("OpenMP Fortran tests enabled")
config.suffixes += ['.f90', '.F90']
Expand Down
65 changes: 65 additions & 0 deletions openmp/runtime/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
add_custom_target(OpenMPUnitTests)
set_target_properties(OpenMPUnitTests PROPERTIES FOLDER "OpenMP/Tests")

if(WIN32 OR STUBS_LIBRARY)
message(WARNING "OpenMP unittests disabled due to stub library or Windows")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this doesn't work on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. But since the CMake changes are already complicated enough to review and test as they are, I thought it might be best to get things working first and then add something like the Windows support in a follow-up

return()
endif()

# Build a testing version of libomp that exports all symbols for unit tests.
# This library uses the same compiled objects as libomp, but with all symbols
# exported to allow testing internal functions.

libomp_get_ldflags(LIBOMP_TEST_LDFLAGS FOR_UNITTESTS)
libomp_get_libflags(LIBOMP_TEST_LIBFLAGS)

# Create the testing library from the same objects as libomp.
add_library(omp_testing SHARED $<TARGET_OBJECTS:obj.omp>)
set_property(TARGET omp_testing PROPERTY FOLDER "OpenMP/Libraries")
target_link_libraries(omp_testing PUBLIC default_gtest)
target_link_libraries(omp_testing PUBLIC ${LIBOMP_TEST_LIBFLAGS} ${LIBOMP_DL_LIBS})
set_target_properties(omp_testing PROPERTIES
PREFIX ""
SUFFIX ""
OUTPUT_NAME "libomp_testing${LIBOMP_LIBRARY_SUFFIX}"
LINK_FLAGS "${LIBOMP_TEST_LDFLAGS}"
LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
EXCLUDE_FROM_ALL TRUE # Don't build by default, only when tests need it
)
target_include_directories(omp_testing PUBLIC
${LIBOMP_INCLUDE_DIR}
${LIBOMP_SRC_DIR}
)

# Make the targets default_gtest and default_gtest_main available.
build_gtest()

function(add_openmp_unittest test_name)
add_unittest(OpenMPUnitTests ${test_name} ${ARGN})

# Link against the testing library which exports all symbols.
target_link_libraries(${test_name} PRIVATE omp_testing)

if(TARGET default_gtest)
target_link_libraries(${test_name} PRIVATE default_gtest_main default_gtest)
else ()
target_link_libraries(${test_name} PRIVATE llvm_gtest_main llvm_gtest)
endif ()
endfunction()

configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/../test/Unit/lit.cfg.py
)

add_openmp_testsuite(
check-libomp-unit
"Running libomp unit tests"
${CMAKE_CURRENT_BINARY_DIR}
EXCLUDE_FROM_CHECK_ALL
DEPENDS OpenMPUnitTests
)

add_subdirectory(String)
9 changes: 9 additions & 0 deletions openmp/runtime/unittests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# libomp Unit Tests

Usage:
```
cd <your-llvm-build-directory>/runtimes/runtimes-bins
ninja check-libomp-unit
```

Note: unit tests are currently not supported on Windows
3 changes: 3 additions & 0 deletions openmp/runtime/unittests/String/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_openmp_unittest(StringTests
TestKmpStr.cpp
)
Loading
Loading