Merge "Enable cmake testing" into main am: ff18ea26f8

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3123791

Change-Id: Iffdb6bc3bf26d234b331f390a4a8fdccfaa126f8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/cc/cmake_main.txt b/cc/cmake_main.txt
index deb1de1..e9177d6 100644
--- a/cc/cmake_main.txt
+++ b/cc/cmake_main.txt
@@ -1,6 +1,7 @@
 cmake_minimum_required(VERSION 3.18)
 project(<<.M.Name>> CXX)
 set(CMAKE_CXX_STANDARD 20)
+enable_testing()
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 include(AddAidlLibrary)
diff --git a/cc/cmake_module_cc.txt b/cc/cmake_module_cc.txt
index 488e5e1..693406d 100644
--- a/cc/cmake_module_cc.txt
+++ b/cc/cmake_module_cc.txt
@@ -8,15 +8,24 @@
 (getLinkerProperties .M).Header_libs
 (getExtraLibs .M)
 ) .Pprop.LibraryMapping>>
+<<$moduleType := getModuleType .M>>
+<<$moduleTypeCmake := "executable">>
+<<if eq $moduleType "library">>
+<<$moduleTypeCmake = "library">>
+<<end>>
 
 # <<.M.Name>>
 <<if $srcs>>
 <<setList .M.Name "_SRCS" "${ANDROID_BUILD_TOP}/" (toStrings $srcs)>>
-add_<<getModuleType .M>>(<<.M.Name>> ${<<.M.Name>>_SRCS})
+add_<<$moduleTypeCmake>>(<<.M.Name>> ${<<.M.Name>>_SRCS})
 <<- else>>
-add_<<getModuleType .M>>(<<.M.Name>> INTERFACE)
+add_<<$moduleTypeCmake>>(<<.M.Name>> INTERFACE)
 <<- end>>
-add_<<getModuleType .M>>(android::<<.M.Name>> ALIAS <<.M.Name>>)
+<<- if eq $moduleType "library">>
+add_library(android::<<.M.Name>> ALIAS <<.M.Name>>)
+<<- else if eq $moduleType "test">>
+add_test(NAME <<.M.Name>> COMMAND <<.M.Name>>)
+<<- end>>
 <<print "">>
 
 <<- if $includeDirs>>
diff --git a/cc/cmake_snapshot.go b/cc/cmake_snapshot.go
index 9ac6350..ad7beed 100644
--- a/cc/cmake_snapshot.go
+++ b/cc/cmake_snapshot.go
@@ -488,9 +488,9 @@
 	case *libraryDecorator:
 		return "library"
 	case *testBinary:
-		return "executable"
+		return "test"
 	case *benchmarkDecorator:
-		return "executable"
+		return "test"
 	}
 	panic(fmt.Sprintf("Unexpected module type: %T", m.linker))
 }