Skip to content

Commit ee56190

Browse files
committed
CMake: Add support for non-main.cpp greentea tests
Greentea tests with name other than main.cpp can now be built with CMake macro using an optional flag.
1 parent ff66b63 commit ee56190

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tools/cmake/mbed_greentea.cmake

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,39 @@ include(${CMAKE_CURRENT_LIST_DIR}/app.cmake)
2222

2323
macro(mbed_greentea_add_test)
2424
set(options)
25-
set(singleValueArgs TEST_NAME)
25+
set(singleValueArgs
26+
TEST_NAME
27+
TEST_MAIN)
2628
set(multipleValueArgs
2729
TEST_INCLUDE_DIRS
2830
TEST_SOURCES
29-
TEST_REQUIRED_LIBS
30-
)
31+
TEST_REQUIRED_LIBS)
3132
cmake_parse_arguments(MBED_GREENTEA
3233
"${options}"
3334
"${singleValueArgs}"
3435
"${multipleValueArgs}"
3536
${ARGN}
3637
)
3738

38-
set(TEST_NAME ${MBED_GREENTEA_TEST_NAME})
39-
4039
add_subdirectory(${MBED_PATH} build)
4140

42-
add_executable(${TEST_NAME})
43-
44-
# Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
41+
add_executable(${MBED_GREENTEA_TEST_NAME}) # Explicitly enable BUILD_TESTING until CTest is added to the Greentea client
4542
set(BUILD_TESTING ON)
4643

47-
mbed_configure_app_target(${TEST_NAME})
44+
mbed_configure_app_target(${MBED_GREENTEA_TEST_NAME})
4845

49-
target_include_directories(${TEST_NAME}
46+
target_include_directories(${MBED_GREENTEA_TEST_NAME}
5047
PRIVATE
5148
.
5249
${MBED_GREENTEA_TEST_INCLUDE_DIRS}
5350
)
5451

55-
target_sources(${TEST_NAME}
52+
if("${MBED_GREENTEA_TEST_MAIN}" STREQUAL "")
53+
set(MBED_GREENTEA_TEST_MAIN main.cpp)
54+
endif()
55+
target_sources(${MBED_GREENTEA_TEST_NAME}
5656
PRIVATE
57-
main.cpp
57+
${MBED_GREENTEA_TEST_MAIN}
5858
${MBED_GREENTEA_TEST_SOURCES}
5959
)
6060

@@ -71,12 +71,12 @@ macro(mbed_greentea_add_test)
7171
list(APPEND MBED_GREENTEA_TEST_REQUIRED_LIBS mbed-greentea)
7272
endif()
7373

74-
target_link_libraries(${TEST_NAME}
74+
target_link_libraries(${MBED_GREENTEA_TEST_NAME}
7575
PRIVATE
7676
${MBED_GREENTEA_TEST_REQUIRED_LIBS}
7777
)
7878

79-
mbed_set_post_build(${TEST_NAME})
79+
mbed_set_post_build(${MBED_GREENTEA_TEST_NAME})
8080

8181
option(VERBOSE_BUILD "Have a verbose build process")
8282
if(VERBOSE_BUILD)

0 commit comments

Comments
 (0)