-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathgtest.cmake
More file actions
57 lines (48 loc) · 2.19 KB
/
gtest.cmake
File metadata and controls
57 lines (48 loc) · 2.19 KB
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
if(TESTING)
include(GoogleTest) # Standart CMake modülü
include(FetchContent)
# 🚀 UPGRADE: Updated to v1.14.0.
# The comment about WASI-SDK 12 is likely obsolete. Modern GTest handles
# 'no-exception' environments much better via internal macros.
FetchContent_Declare(
GTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
SYSTEM # 🛡️ Automatically suppresses warnings from GTest headers
FIND_PACKAGE_ARGS
)
# ⚡ CONFIGURATION: Set cache variables explicitly to control GTest behavior.
set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "gTest installation disabled" FORCE)
# 🕸️ WASM SPECIFIC CONFIGURATION
if(WASM)
# WASM environments often lack Pthread support or filesystem access.
set(gtest_disable_pthreads ON CACHE BOOL "Disable pthreads for WASM" FORCE)
# Instead of manually patching definitions later, we inject them here if possible,
# or rely on GTest auto-detecting '-fno-exceptions' from the compiler flags.
# However, forcing these is safe for Aztec's circuit environment:
add_compile_definitions(
GTEST_HAS_EXCEPTIONS=0
GTEST_HAS_STREAM_REDIRECTION=0
GTEST_HAS_POSIX_RE=0
GTEST_HAS_CLONE=0
)
endif()
# 🧠 SMART PATTERN: "Populate & Add"
FetchContent_GetProperties(GTest)
if(NOT GTest_POPULATED)
FetchContent_Populate(GTest)
# 🛡️ ISOLATION: Don't build GTest as part of 'all', only when tests are requested.
add_subdirectory(${gtest_SOURCE_DIR} ${gtest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
# 🔗 ALIASING: Modern GTest exports GTest::gtest, but for compatibility
# with older find_package calls or custom scripts, we keep these if needed.
if(NOT TARGET GTest::gtest)
add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()
# CMake'in standart test mekanizmasını aç
enable_testing()
# GTest'in kendi test keşif (discovery) modülünü dahil et
include(GoogleTest)
endif()