Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion flang-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ if (LLVM_INCLUDE_EXAMPLES)
endif ()

if (FLANG_RT_INCLUDE_TESTS)
add_subdirectory(unittests)
add_subdirectory(test)
add_subdirectory(unittests)
else ()
add_custom_target(check-flang-rt)
endif()
28 changes: 12 additions & 16 deletions flang-rt/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,24 @@ configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

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

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


add_custom_target(flang-rt-test-depends)
set_target_properties(flang-rt-test-depends PROPERTIES FOLDER "Flang-RT/Meta")
add_dependencies(flang-rt-test-depends
FlangRTUnitTests
flang_rt.runtime.unittest
flang_rt.runtime
)

Expand Down
42 changes: 24 additions & 18 deletions flang-rt/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,39 @@
#
#===------------------------------------------------------------------------===#

# Target that depends on all unittests
add_custom_target(FlangRTUnitTests)
set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")

# LLVM uses a modified version of GTest that uses LLVMSupport for console
# output. Therefore it also needs to include files from LLVM. Unfortunately,
# LLVM/GTest doesn't add the include search path itself. Limiting the scope
# using target_include_directories does not work because with
# LLVM_INSTALL_GTEST=ON, as llvm_gtest is an IMPORT library.
include_directories("${LLVM_INCLUDE_DIR}" "${LLVM_MAIN_INCLUDE_DIR}")

# Add GTest if not already present.
# Using a function so LLVM_SUBPROJECT_TITLE does not propagate.
function (build_gtest)
set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest")
endfunction ()
# output. We are using the pre-compiled GTest library from the LLVM build,
# if available. Otherwise, do nothing.

if (CMAKE_CROSSCOMPILING)
# TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or
# ssh remote command invocation; for this case provide an option to
# enable unittests.
message(STATUS "Flang-RT unittests disabled because we are cross-compiling")
return ()
endif ()

if (NOT TARGET llvm_gtest)
build_gtest()
message(WARNING "Flang-RT unittests disabled due to GTest being unavailable; "
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
return ()
endif ()


add_dependencies(flang-rt-test-depends
FlangRTUnitTests
flang_rt.runtime.unittest
)

if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
add_compile_options("-Wno-suggest-override")
endif()


# Target that depends on all unittests
add_custom_target(FlangRTUnitTests)
set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")


function(add_flangrt_unittest_offload_properties target)
# Set CUDA_RESOLVE_DEVICE_SYMBOLS.
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
Expand Down
12 changes: 1 addition & 11 deletions offload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,5 @@ add_subdirectory(liboffload)
# Add tests.
if(OFFLOAD_INCLUDE_TESTS)
add_subdirectory(test)

# Add unit tests if GMock/GTest is present
if(NOT LLVM_THIRD_PARTY_DIR)
set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
endif()
if(EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest AND NOT TARGET llvm_gtest)
add_subdirectory(${LLVM_THIRD_PARTY_DIR}/unittest ${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest)
endif()
if(TARGET llvm_gtest)
add_subdirectory(unittests)
endif()
add_subdirectory(unittests)
endif()
14 changes: 14 additions & 0 deletions offload/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
add_custom_target(OffloadUnitTests)
set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")

if (CMAKE_CROSSCOMPILING)
# TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or
# ssh remote command invocation; for this case provide an option to
# enable unittests.
message(STATUS "Offload unittests disabled because we are cross-compiling")
return ()
endif ()

if (NOT TARGET llvm_gtest)
message(WARNING "Offload unittests disabled due to GTest being unavailable; "
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
return ()
endif ()

function(add_offload_unittest test_dirname)
set(target_name "${test_dirname}.unittests")

Expand Down
18 changes: 14 additions & 4 deletions third-party/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ if (HAVE_LIBPTHREAD)
list(APPEND LIBS pthread)
endif()

# Do not build unittest libraries automatically, they will be pulled in
# by unittests if these are built.
# Make available for runtimes using the LLVM buildtree
# (required for unittests in bootstrapping builds)
set(EXCLUDE_FROM_ALL OFF)

# Install GTest only if requested.
set(BUILDTREE_ONLY BUILDTREE_ONLY)
set(EXCLUDE_FROM_ALL ON)
if (LLVM_INSTALL_GTEST)
set(EXCLUDE_FROM_ALL OFF)
set(BUILDTREE_ONLY "")
endif ()

Expand Down Expand Up @@ -82,6 +82,16 @@ target_include_directories(llvm_gtest
PRIVATE googletest googlemock
)

# When used from the buildtree, also force use of buildtree LLVM headers,
# (instead locally installed version)
# FIXME: Shouldn't this be done for all LLVM libraries? Currently, LLVM uses a
# big giant `include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})`
# which CMake does not add to the import library.
target_include_directories(llvm_gtest BEFORE
PUBLIC $<BUILD_INTERFACE:${LLVM_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${LLVM_BINARY_DIR}/include>
)

add_subdirectory(UnitTestMain)

if (LLVM_INSTALL_GTEST)
Expand Down
Loading