@@ -568,52 +568,26 @@ if(INFO)
568568 # modifications on blas_connector and lapack_connector
569569endif ()
570570
571- IF (BUILD_TESTING)
572- set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
573- include (CTest )
574- enable_testing ( )
575- find_package (GTest HINTS /usr/local/lib/ ${GTEST_DIR } )
576- if ( NOT ${GTest_FOUND} )
571+ # Add performance test in abacus
572+ IF (ENABLE_GOOGLEBENCH)
573+ set (BUILD_TESTING ON )
574+ find_package (benchmark HINTS ${BENCHMARK_DIR} )
575+ if ( NOT ${benchmark_FOUND } )
576+ set (BENCHMARK_USE_BUNDLED_GTEST OFF )
577577 include (FetchContent)
578578 FetchContent_Declare(
579- googletest
580- GIT_REPOSITORY https://github.com/google/googletest .git
579+ benchmark
580+ GIT_REPOSITORY https://github.com/google/benchmark .git
581581 GIT_TAG "origin/main"
582582 GIT_SHALLOW TRUE
583583 GIT_PROGRESS TRUE
584584 )
585- FetchContent_MakeAvailable(googletest )
585+ FetchContent_MakeAvailable(benchmark )
586586 endif ()
587- # TODO: Try the GoogleTest module.
588- # https://cmake.org/cmake/help/latest/module/GoogleTest.html
589- add_subdirectory (tests) # Contains integration tests
590-
591- function (AddTest) # function for UT
592- cmake_parse_arguments (UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN} )
593- add_executable (${UT_TARGET} ${UT_SOURCES} )
594-
595- if (ENABLE_COVERAGE)
596- add_coverage(${UT_TARGET} )
597- endif ()
598-
599- #dependencies & link library
600- target_link_libraries (${UT_TARGET} ${UT_LIBS}
601- Threads::Threads GTest::gtest_main GTest::gmock_main)
602- if (USE_OPENMP)
603- target_link_libraries (${UT_TARGET} OpenMP::OpenMP_CXX)
604- endif ()
605- install (TARGETS ${UT_TARGET} DESTINATION ${CMAKE_BINARY_DIR} /tests )
606- add_test (NAME ${UT_TARGET}
607- COMMAND ${UT_TARGET}
608- WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET} >
609- )
610- endfunction (AddTest)
611587endif ()
612588
613-
614- # Add performance test in abacus
615- IF (ENABLE_GOOGLEBENCH)
616- set (CMAKE_CXX_STANDARD 14) # Required in orbital
589+ IF (BUILD_TESTING)
590+ set_if_higher(CMAKE_CXX_STANDARD 14) # Required in orbital
617591 include (CTest)
618592 enable_testing ()
619593 find_package (GTest HINTS /usr/local/lib/ ${GTEST_DIR} )
@@ -628,37 +602,27 @@ IF (ENABLE_GOOGLEBENCH)
628602 )
629603 FetchContent_MakeAvailable(googletest)
630604 endif ()
605+ # TODO: Try the GoogleTest module.
606+ # https://cmake.org/cmake/help/latest/module/GoogleTest.html
607+ add_subdirectory (tests) # Contains integration tests
631608
632- find_package (benchmark REQUIRED)
633- if (NOT ${benchmark_FOUND} )
634- include (FetchContent)
635- FetchContent_Declare(
636- benchmark
637- GIT_REPOSITORY https://github.com/google/benchmark.git
638- GIT_TAG "origin/main"
639- GIT_SHALLOW TRUE
640- GIT_PROGRESS TRUE
641- )
642- FetchContent_MakeAvailable(benchmark)
643- endif ()
644-
645- function (AddPerfTest) # function for UT
646- add_compile_options (-O2)
609+ function (AddTest) # function for UT
647610 cmake_parse_arguments (UT "DYN" "TARGET" "LIBS;DYN_LIBS;STATIC_LIBS;SOURCES;DEPENDS" ${ARGN} )
648611 add_executable (${UT_TARGET} ${UT_SOURCES} )
649612
650613 if (ENABLE_COVERAGE)
651614 add_coverage(${UT_TARGET} )
652615 endif ()
653616
654-
655- # Link Google Benchmark to the project
656- target_link_libraries (${UT_TARGET} benchmark::benchmark)
657-
658-
659617 #dependencies & link library
660- target_link_libraries (${UT_TARGET} ${UT_LIBS}
661- Threads::Threads GTest::gtest_main GTest::gmock_main)
618+ if (ENABLE_GOOGLEBENCH)
619+ target_link_libraries (${UT_TARGET} ${UT_LIBS}
620+ Threads::Threads GTest::gtest_main GTest::gmock_main benchmark::benchmark)
621+ else ()
622+ target_link_libraries (${UT_TARGET} ${UT_LIBS}
623+ Threads::Threads GTest::gtest_main GTest::gmock_main)
624+ endif ()
625+
662626 if (USE_OPENMP)
663627 target_link_libraries (${UT_TARGET} OpenMP::OpenMP_CXX)
664628 endif ()
@@ -668,10 +632,8 @@ IF (ENABLE_GOOGLEBENCH)
668632 WORKING_DIRECTORY $<TARGET_FILE_DIR:${UT_TARGET} >
669633 )
670634 endfunction (AddTest)
671- endif ()
672-
673-
674635
636+ endif ()
675637
676638add_subdirectory (source )
677639
0 commit comments