Skip to content

Commit ef54ed2

Browse files
committed
Seperate the CMake cc_test based on target platform
Most of the tests are platform specific, so defining them as cc_test, cc_test_on_ios, etc, instead of all in cc_test is a more sensible approach. PiperOrigin-RevId: 260042373
1 parent c3dfb4d commit ef54ed2

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

cmake/test_rules.cmake

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,57 @@ include(CMakeParseArguments)
2323
# Defines a new test executable target with the given target name, sources, and
2424
# dependencies. Implicitly adds DEPENDS on gtest and gtest_main.
2525
function(cc_test name)
26-
set(multi DEPENDS SOURCES INCLUDES DEFINES
27-
ANDROID_DEPENDS ANDROID_SOURCES ANDROID_INCLUDES ANDROID_DEFINES
28-
IOS_DEPENDS IOS_SOURCES IOS_INCLUDES IOS_DEFINES
29-
DESKTOP_DEPENDS DESKTOP_SOURCES DESKTOP_INCLUDES DESKTOP_DEFINES)
26+
if (ANDROID OR IOS)
27+
return()
28+
endif()
29+
30+
set(multi DEPENDS SOURCES INCLUDES DEFINES)
3031
# Parse the arguments into cc_test_SOURCES and cc_test_DEPENDS.
3132
cmake_parse_arguments(cc_test "" "" "${multi}" ${ARGN})
3233

3334
list(APPEND cc_test_DEPENDS gmock gtest gtest_main)
34-
if (ANDROID)
35-
list(APPEND cc_test_SOURCES "${cc_test_ANDROID_SOURCES}")
36-
list(APPEND cc_test_DEPENDS "${cc_test_ANDROID_DEPENDS}")
37-
list(APPEND cc_test_INCLUDES "${cc_test_ANDROID_INCLUDES}")
38-
list(APPEND cc_test_DEFINES "${cc_test_ANDROID_DEFINES}")
39-
elseif (IOS)
40-
list(APPEND cc_test_SOURCES "${cc_test_IOS_SOURCES}")
41-
list(APPEND cc_test_DEPENDS
42-
"${cc_test_IOS_DEPENDS}"
43-
"-framework CoreFoundation"
44-
"-framework Foundation"
45-
)
46-
list(APPEND cc_test_INCLUDES "${cc_test_IOS_INCLUDES}")
47-
list(APPEND cc_test_DEFINES "${cc_test_IOS_DEFINES}")
48-
else()
49-
list(APPEND cc_test_SOURCES "${cc_test_DESKTOP_SOURCES}")
50-
list(APPEND cc_test_DEPENDS "${cc_test_DESKTOP_DEPENDS}")
51-
list(APPEND cc_test_INCLUDES "${cc_test_DESKTOP_INCLUDES}")
52-
list(APPEND cc_test_DEFINES "${cc_test_DESKTOP_DEFINES}")
35+
36+
add_executable(${name} ${cc_test_SOURCES})
37+
add_test(${name} ${name})
38+
target_include_directories(${name}
39+
PRIVATE
40+
${FIREBASE_SOURCE_DIR}
41+
${cc_test_INCLUDES}
42+
)
43+
target_link_libraries(${name} PRIVATE ${cc_test_DEPENDS})
44+
target_compile_definitions(${name}
45+
PRIVATE
46+
-DINTERNAL_EXPERIMENTAL=1
47+
${cc_test_DEFINES}
48+
)
49+
endfunction()
50+
51+
# cc_test_on_ios(
52+
# target
53+
# SOURCES sources...
54+
# DEPENDS libraries...
55+
# )
56+
#
57+
# Defines a new test executable target with the given target name, sources, and
58+
# dependencies. Implicitly adds DEPENDS on gtest, gtest_main, Foundation and
59+
# CoreFoundation frameworks.
60+
function(cc_test_on_ios name)
61+
if (NOT IOS)
62+
return()
5363
endif()
5464

65+
set(multi DEPENDS SOURCES INCLUDES DEFINES)
66+
# Parse the arguments into cc_test_SOURCES and cc_test_DEPENDS.
67+
cmake_parse_arguments(cc_test "" "" "${multi}" ${ARGN})
68+
69+
list(APPEND cc_test_DEPENDS
70+
gmock
71+
gtest
72+
gtest_main
73+
"-framework CoreFoundation"
74+
"-framework Foundation"
75+
)
76+
5577
add_executable(${name} ${cc_test_SOURCES})
5678
add_test(${name} ${name})
5779
target_include_directories(${name}
@@ -65,4 +87,4 @@ function(cc_test name)
6587
-DINTERNAL_EXPERIMENTAL=1
6688
${cc_test_DEFINES}
6789
)
68-
endfunction()
90+
endfunction()

0 commit comments

Comments
 (0)