Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made unit testing enhancements if HWY_TEST_STANDALONE is 1 #2323

Merged
merged 2 commits into from
Oct 2, 2024
Merged
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
39 changes: 32 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ set(HWY_ENABLE_EXAMPLES ON CACHE BOOL "Build examples")
set(HWY_ENABLE_INSTALL ON CACHE BOOL "Install library")
set(HWY_ENABLE_TESTS ON CACHE BOOL "Enable HWY tests")

if (MSVC)
set(HWY_TEST_STANDALONE ON CACHE BOOL "Disable use of googletest")
else()
set(HWY_TEST_STANDALONE OFF CACHE BOOL "Disable use of googletest")
endif()

if (NOT DEFINED CMAKE_CXX_STANDARD)
if ("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(HWY_CXX_STD_TGT_COMPILE_FEATURE cxx_std_17)
Expand Down Expand Up @@ -579,6 +585,15 @@ if (HWY_ENABLE_CONTRIB)
list(APPEND HWY_PC_FILES libhwy-contrib.pc)
endif() # HWY_ENABLE_CONTRIB
if (HWY_ENABLE_TESTS)

if (HWY_TEST_STANDALONE)
set(HWY_PC_HWY_TEST_REQUIRES "")
set(HWY_PC_HWY_TEST_CFLAGS "-DHWY_TEST_STANDALONE=1")
else()
set(HWY_PC_HWY_TEST_REQUIRES "gtest")
set(HWY_PC_HWY_TEST_CFLAGS "")
endif()

list(APPEND HWY_PC_FILES libhwy-test.pc)
endif() # HWY_ENABLE_TESTS
foreach (pc ${HWY_PC_FILES})
Expand Down Expand Up @@ -628,6 +643,8 @@ enable_testing()
include(GoogleTest)

set(HWY_SYSTEM_GTEST OFF CACHE BOOL "Use pre-installed googletest?")

if(NOT HWY_TEST_STANDALONE)
if(HWY_SYSTEM_GTEST)
find_package(GTest REQUIRED)
else()
Expand Down Expand Up @@ -656,6 +673,7 @@ add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
endif() # HWY_SYSTEM_GTEST
endif() # HWY_TEST_STANDALONE

set(HWY_TEST_FILES
hwy/contrib/algo/copy_test.cc
Expand Down Expand Up @@ -745,15 +763,19 @@ list(APPEND HWY_TEST_FILES
)
endif() # HWY_ENABLE_CONTRIB

if(HWY_SYSTEM_GTEST)
if (CMAKE_VERSION VERSION_LESS 3.20)
set(HWY_GTEST_LIBS GTest::GTest GTest::Main)
if(HWY_TEST_STANDALONE)
set(HWY_GTEST_LIBS "")
else()
if(HWY_SYSTEM_GTEST)
if (CMAKE_VERSION VERSION_LESS 3.20)
set(HWY_GTEST_LIBS GTest::GTest GTest::Main)
else()
set(HWY_GTEST_LIBS GTest::gtest GTest::gtest_main)
endif()
else()
set(HWY_GTEST_LIBS GTest::gtest GTest::gtest_main)
set(HWY_GTEST_LIBS gtest gtest_main)
endif()
else()
set(HWY_GTEST_LIBS gtest gtest_main)
endif()
endif() # HWY_TEST_STANDALONE

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests)
foreach (TESTFILE IN LISTS HWY_TEST_FILES)
Expand All @@ -766,6 +788,9 @@ foreach (TESTFILE IN LISTS HWY_TEST_FILES)
# cause compile errors because only one may be set, and other CMakeLists.txt
# that include us may set them.
target_compile_options(${TESTNAME} PRIVATE -DHWY_IS_TEST=1)
if(HWY_TEST_STANDALONE)
target_compile_options(${TESTNAME} PRIVATE -DHWY_TEST_STANDALONE=1)
endif()
target_compile_features(${TESTNAME} PRIVATE ${HWY_CXX_STD_TGT_COMPILE_FEATURE})

target_link_libraries(${TESTNAME} PRIVATE ${HWY_TEST_LIBS} ${HWY_GTEST_LIBS})
Expand Down
Loading
Loading