aboutsummaryrefslogblamecommitdiff
path: root/test/CMakeLists.txt
blob: 9c76576e85e9a1e74a372f4388b4bfd46b59bee3 (plain) (tree)
1
2
3
4
5
6
7
                                                        


                                                                            


                                                           








                                                  


                                        
                                                        
                                                           
                                  


                                                          
                                    



















                                                          
# Fetch googletest (latest greatest, okay in this repo).
# https://google.github.io/googletest/quickstart-cmake.html#set-up-a-project
include(FetchContent)
FetchContent_Declare(
    googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG        main
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# Generate CTestTestfile.cmake.
enable_testing()
# Include gtest_discover_tests macro.
include(GoogleTest)

macro(test_int name kind)
    set(target test-${name})
    add_executable(${target} ${name}.cc)
    target_include_directories(${target} PRIVATE ${src})
    target_compile_options(${target} PRIVATE -Wall -Wextra)
    if("${kind}" STREQUAL "gtest")
        target_link_libraries(${target} GTest::gmock_main)
        target_link_libraries(${target} SystemC::systemc)
        gtest_discover_tests(${target})
    elseif("${kind}" STREQUAL "sim")
        target_link_libraries(${target} SystemC::systemc)
        add_test(NAME ${target} COMMAND ${target})
    else()
        message(FATAL_ERROR "unknown test kind '${kind}'")
    endif()
endmacro()

macro(sim_test name)
    test_int(${name} "sim")
endmacro()

macro(gtest_test name)
    test_int(${name} "gtest")
endmacro()

# Google tests.
gtest_test("lt_bus")

# Simulation tests.
sim_test("lt_bus_locked")