aboutsummaryrefslogtreecommitdiff
path: root/libs/usvfs/test/CMakeLists.txt
blob: c34b31fb541ca41b00935cfb1b338a0bbc41bdb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
cmake_minimum_required(VERSION 3.16)

include(CMakeParseArguments)

#! usvfs_set_test_properties
#
# this function sets the following properties on the given executable or shared
# library test target:
# - OUTPUT_NAME to add arch-specific prefix
# - OUTPUT_DIRECTORY to put the test executable or shared library in the right location
# - FOLDER to organize the VS solution layout
#
# \param:FOLDER if present, specifies the subfolder to use in the solution
#
function(usvfs_set_test_properties TARGET)
	cmake_parse_arguments(USVFS_TEST "" "FOLDER" "" ${ARGN})
    if (NOT DEFINED USVFS_TEST_FOLDER)
		set(folder "tests")
    else()
        set(folder "tests/${USVFS_TEST_FOLDER}")
	endif()
    set_target_properties(${TARGET}
        PROPERTIES
        FOLDER ${folder}
        RUNTIME_OUTPUT_NAME ${TARGET}${ARCH_POSTFIX}
        RUNTIME_OUTPUT_DIRECTORY_DEBUG ${USVFS_TEST_BINDIR}
        RUNTIME_OUTPUT_DIRECTORY_RELEASE ${USVFS_TEST_BINDIR}
        RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${USVFS_TEST_BINDIR}
    )
endfunction()

#! usvfs_target_link_usvfs
#
# add a target link between the given target and the usvfs shared library with delay
# loading
#
function(usvfs_target_link_usvfs TARGET)
    target_link_libraries(${TARGET} PRIVATE usvfs_dll)
    target_link_options(${TARGET} PRIVATE "/DELAYLOAD:usvfs${ARCH_POSTFIX}.dll")
endfunction()


file(GLOB directories LIST_DIRECTORIES true "*")

# this goes through all the directories and
#
# 1. add them if there is a CMakeLists.txt inside
# 2. add correspondings tests (for CTest) for BOTH x86 and x64 when possible
#
foreach(directory ${directories})
    if(NOT(IS_DIRECTORY ${directory}))
        continue()
    endif()

    if(NOT(EXISTS ${directory}/CMakeLists.txt))
        continue()
    endif()

    add_subdirectory(${directory})

    get_filename_component(dirname ${directory} NAME)
    if((dirname STREQUAL "test_utils") OR (dirname STREQUAL "gtest_utils"))
        continue()
    endif()

    add_test(NAME ${dirname}_x64
        COMMAND ${USVFS_TEST_BINDIR}/${dirname}_x64.exe
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    )
    add_test(NAME ${dirname}_x86
        COMMAND ${USVFS_TEST_BINDIR}/${dirname}_x86.exe
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    )
endforeach()