Skip to content

Commit a2d3ae2

Browse files
committed
cmake: tests refactoring
1 parent 0d67a78 commit a2d3ae2

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

build/cmake/unit_tests.cmake

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# if the library is compiled by vcpkg during the port build,
1+
# if the library is compiled by vcpkg during the port build (i.e. during the package installation),
22
# then we don't need to build unit tests
33
if(IS_VCPKG_PORT_BUILD)
44
return()
@@ -9,42 +9,76 @@ if(IOS)
99
return()
1010
endif()
1111

12-
set(test_srcs)
13-
myci_add_source_files(test_srcs
14-
DIRECTORY
15-
${CMAKE_CURRENT_LIST_DIR}/../../tests/unit/src
16-
RECURSIVE
17-
)
18-
12+
# For unit tests we need the tst testing framework library which in turn depends on utki.
1913
if(CPPFW_MONOREPO)
20-
set(utki_test_harness_dir ${CMAKE_CURRENT_LIST_DIR}/../../..)
14+
# In case of monorepo build we can add necessary tst dependencies right here.
15+
16+
myci_add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../clargs/build/cmake
17+
BINARY_DIR
18+
clargs
19+
)
20+
myci_add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../opros/build/cmake
21+
BINARY_DIR
22+
opros
23+
)
24+
myci_add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../nitki/build/cmake
25+
BINARY_DIR
26+
nitki
27+
)
28+
myci_add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../tst/build/cmake
29+
BINARY_DIR
30+
tst
31+
)
32+
33+
set(tst_dep tst::tst)
2134
else()
35+
# In case of non-monorepo build, we need to build the tst framework
36+
# from sources (from git submodules) together with unit tests.
37+
2238
set(utki_test_harness_dir ${CMAKE_CURRENT_LIST_DIR}/../../tests/harness)
23-
endif()
2439

25-
myci_add_source_files(test_srcs
26-
DIRECTORY
27-
${utki_test_harness_dir}/tst/src
28-
RECURSIVE
29-
)
40+
myci_add_source_files(tst_srcs
41+
DIRECTORY
42+
${utki_test_harness_dir}/tst/src
43+
RECURSIVE
44+
)
45+
46+
myci_add_source_files(tst_srcs
47+
DIRECTORY
48+
${utki_test_harness_dir}/clargs/src
49+
RECURSIVE
50+
)
3051

52+
myci_declare_library(tst
53+
SOURCES
54+
${tst_srcs}
55+
PUBLIC_INCLUDE_DIRECTORIES
56+
${utki_test_harness_dir}/tst/src
57+
PRIVATE_INCLUDE_DIRECTORIES
58+
${utki_test_harness_dir}/clargs/src
59+
PREPROCESSOR_DEFINITIONS
60+
TST_NO_PAR
61+
DEPENDENCIES
62+
utki
63+
)
64+
65+
set(tst_dep ${PROJECT_NAME}::tst)
66+
endif()
67+
68+
set(test_srcs)
3169
myci_add_source_files(test_srcs
3270
DIRECTORY
33-
${utki_test_harness_dir}/clargs/src
71+
${CMAKE_CURRENT_LIST_DIR}/../../tests/unit/src
3472
RECURSIVE
3573
)
3674

3775
myci_declare_application(${PROJECT_NAME}-tests
3876
GUI
3977
SOURCES
4078
${test_srcs}
41-
INCLUDE_DIRECTORIES
42-
${utki_test_harness_dir}/tst/src
43-
${utki_test_harness_dir}/clargs/src
44-
PREPROCESSOR_DEFINITIONS
45-
TST_NO_PAR
4679
DEPENDENCIES
4780
utki
81+
${tst_dep}
4882
)
4983

5084
myci_declare_test(${PROJECT_NAME})

build/vcpkg/test/vcpkg-configuration.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"kind": "git",
1010
"repository": "https://github.com/cppfw/vcpkg-repo/",
11-
"baseline": "9fd38ca696d8fa2a0cdff1e580108a6e4514ee1a",
11+
"baseline": "0ff688afe5409ffc80ff8d1be654bc5a6a8ac9fc",
1212
"reference": "main",
1313
"packages": [
1414
"myci"

0 commit comments

Comments
 (0)