Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ macro(add_llvm_library name)
if (ARG_MODULE AND NOT TARGET ${name})
# Add empty "phony" target
add_custom_target(${name})
elseif( EXCLUDE_FROM_ALL )
elseif ( EXCLUDE_FROM_ALL )
set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
elseif(ARG_BUILDTREE_ONLY)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
Expand Down
2 changes: 2 additions & 0 deletions llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ function(llvm_ExternalProject_Add name source_dir)
${verbose}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
${sysroot_arg}
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR}
-DLLVM_CONFIG_PATH=${llvm_config_path}
-DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
Expand Down
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