Skip to content

Commit 5d1d166

Browse files
committed
Always use LLVM-built GTest (2)
1 parent 80ea5f4 commit 5d1d166

File tree

7 files changed

+68
-40
lines changed

7 files changed

+68
-40
lines changed

flang-rt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ if (LLVM_INCLUDE_EXAMPLES)
334334
endif ()
335335

336336
if (FLANG_RT_INCLUDE_TESTS)
337-
add_subdirectory(unittests)
338337
add_subdirectory(test)
338+
add_subdirectory(unittests)
339339
else ()
340340
add_custom_target(check-flang-rt)
341341
endif()

flang-rt/test/CMakeLists.txt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,24 @@ configure_lit_site_cfg(
2323
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
2424
)
2525

26-
if (TARGET FlangRTUnitTests)
27-
configure_lit_site_cfg(
28-
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
29-
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
30-
MAIN_CONFIG
31-
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
32-
)
26+
configure_lit_site_cfg(
27+
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
28+
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
29+
MAIN_CONFIG
30+
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
31+
)
3332

34-
configure_lit_site_cfg(
35-
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.site.cfg.py.in
36-
${CMAKE_CURRENT_BINARY_DIR}/NonGtestUnit/lit.site.cfg.py
37-
MAIN_CONFIG
38-
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.cfg.py
39-
)
40-
endif ()
33+
configure_lit_site_cfg(
34+
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.site.cfg.py.in
35+
${CMAKE_CURRENT_BINARY_DIR}/NonGtestUnit/lit.site.cfg.py
36+
MAIN_CONFIG
37+
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.cfg.py
38+
)
4139

4240

4341
add_custom_target(flang-rt-test-depends)
4442
set_target_properties(flang-rt-test-depends PROPERTIES FOLDER "Flang-RT/Meta")
4543
add_dependencies(flang-rt-test-depends
46-
FlangRTUnitTests
47-
flang_rt.runtime.unittest
4844
flang_rt.runtime
4945
)
5046

flang-rt/unittests/CMakeLists.txt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,39 @@
66
#
77
#===------------------------------------------------------------------------===#
88

9+
# Target that depends on all unittests
10+
add_custom_target(FlangRTUnitTests)
11+
set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")
12+
913
# LLVM uses a modified version of GTest that uses LLVMSupport for console
10-
# output. Therefore it also needs to include files from LLVM. Unfortunately,
11-
# LLVM/GTest doesn't add the include search path itself. Limiting the scope
12-
# using target_include_directories does not work because with
13-
# LLVM_INSTALL_GTEST=ON, as llvm_gtest is an IMPORT library.
14-
include_directories("${LLVM_INCLUDE_DIR}" "${LLVM_MAIN_INCLUDE_DIR}")
15-
16-
# Add GTest if not already present.
17-
# Using a function so LLVM_SUBPROJECT_TITLE does not propagate.
18-
function (build_gtest)
19-
set(LLVM_SUBPROJECT_TITLE "Third-Party/Google Test")
20-
add_subdirectory("${LLVM_THIRD_PARTY_DIR}/unittest" "${CMAKE_CURRENT_BINARY_DIR}/third-party/unittest")
21-
endfunction ()
14+
# output. We are using the pre-compiled GTest library from the LLVM build,
15+
# if available. Otherwise, do nothing.
16+
17+
if (CMAKE_CROSSCOMPILING)
18+
# TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or
19+
# ssh remote command invocation; for this case provide an option to
20+
# enable unittests.
21+
message(STATUS "Flang-RT unittests disabled because we are cross-compiling")
22+
return ()
23+
endif ()
24+
2225
if (NOT TARGET llvm_gtest)
23-
build_gtest()
26+
message(WARNING "Flang-RT unittests disabled due to GTest being unavailable; "
27+
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
28+
return ()
2429
endif ()
2530

31+
32+
add_dependencies(flang-rt-test-depends
33+
FlangRTUnitTests
34+
flang_rt.runtime.unittest
35+
)
36+
2637
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
2738
add_compile_options("-Wno-suggest-override")
2839
endif()
2940

3041

31-
# Target that depends on all unittests
32-
add_custom_target(FlangRTUnitTests)
33-
set_target_properties(FlangRTUnitTests PROPERTIES FOLDER "Flang-RT/Meta")
34-
35-
3642
function(add_flangrt_unittest_offload_properties target)
3743
# Set CUDA_RESOLVE_DEVICE_SYMBOLS.
3844
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ macro(add_llvm_library name)
955955
if (ARG_MODULE AND NOT TARGET ${name})
956956
# Add empty "phony" target
957957
add_custom_target(${name})
958-
elseif( EXCLUDE_FROM_ALL )
958+
elseif ( EXCLUDE_FROM_ALL )
959959
set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
960960
elseif(ARG_BUILDTREE_ONLY)
961961
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})

llvm/cmake/modules/LLVMExternalProjectUtils.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ function(llvm_ExternalProject_Add name source_dir)
392392
${verbose}
393393
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
394394
${sysroot_arg}
395+
-DCMAKE_C_COMPILER_LAUNCHER=ccache
396+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
395397
-DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR}
396398
-DLLVM_CONFIG_PATH=${llvm_config_path}
397399
-DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}

offload/unittests/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
add_custom_target(OffloadUnitTests)
22
set_target_properties(OffloadUnitTests PROPERTIES FOLDER "Tests/UnitTests")
33

4+
if (CMAKE_CROSSCOMPILING)
5+
# TODO: It is possible that LLVM_GTEST_RUN_UNDER defines an emulator or
6+
# ssh remote command invocation; for this case provide an option to
7+
# enable unittests.
8+
message(STATUS "Offload unittests disabled because we are cross-compiling")
9+
return ()
10+
endif ()
11+
12+
if (NOT TARGET llvm_gtest)
13+
message(WARNING "Offload unittests disabled due to GTest being unavailable; "
14+
"Try LLVM_INSTALL_GTEST=ON for the LLVM build")
15+
return ()
16+
endif ()
17+
418
function(add_offload_unittest test_dirname)
519
set(target_name "${test_dirname}.unittests")
620

third-party/unittest/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ if (HAVE_LIBPTHREAD)
3838
list(APPEND LIBS pthread)
3939
endif()
4040

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

45+
# Install GTest only if requested.
4446
set(BUILDTREE_ONLY BUILDTREE_ONLY)
45-
set(EXCLUDE_FROM_ALL ON)
4647
if (LLVM_INSTALL_GTEST)
47-
set(EXCLUDE_FROM_ALL OFF)
4848
set(BUILDTREE_ONLY "")
4949
endif ()
5050

@@ -82,6 +82,16 @@ target_include_directories(llvm_gtest
8282
PRIVATE googletest googlemock
8383
)
8484

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

8797
if (LLVM_INSTALL_GTEST)

0 commit comments

Comments
 (0)