-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
207 lines (178 loc) · 5.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
207 lines (178 loc) · 5.41 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
cmake_minimum_required(VERSION 3.14)
# Google Test
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.11.0
)
message(STATUS "Fetching Google Test archive...")
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
if(NOT DEFINED LIBYUV_REPO_URL)
if(DEFINED ENV{LIBYUV_REPO_URL})
set(LIBYUV_REPO_URL $ENV{LIBYUV_REPO_URL})
else()
set(LIBYUV_REPO_URL https://github.com/lemenkov/libyuv)
endif()
endif()
message(STATUS "Fetching libYUV from repository: ${LIBYUV_REPO_URL}")
# LibYUV for performance comparison
FetchContent_Declare(
libyuv
GIT_REPOSITORY ${LIBYUV_REPO_URL}
GIT_TAG b7d97d5f3f8f897b88872b6935e4c996b955bc1f
)
# Set libyuv options to minimize dependencies
set(UNIT_TEST OFF CACHE BOOL "" FORCE)
set(JPEG_FOUND OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(libyuv)
# Common test utilities
add_library(ccap_test_utils
test_utils.cpp
test_utils.h
)
target_link_libraries(ccap_test_utils
PUBLIC
ccap
gtest
gtest_main
gmock
gmock_main
)
target_include_directories(ccap_test_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# Add MSVC specific compile options for test utils
if(MSVC)
target_compile_options(ccap_test_utils PRIVATE
/MP
/std:c++17
/Zc:__cplusplus
/bigobj
/wd4996
/D_CRT_SECURE_NO_WARNINGS
)
endif()
# Test executables - Refactored and simplified
add_executable(
ccap_convert_test
test_accuracy.cpp
test_color_conversions.cpp
test_yuv_conversions.cpp
test_platform_features.cpp
)
target_link_libraries(
ccap_convert_test
ccap_test_utils
gtest_main
)
# GUID definition verification test (Windows only)
# This test verifies that locally defined GUIDs match strmiids.lib values
if(WIN32)
add_executable(
ccap_guid_test
test_guid_definitions.cpp
)
target_link_libraries(
ccap_guid_test
gtest
gtest_main
strmiids # Link against strmiids.lib to get reference GUID values
ole32 # For CoCreateInstance, CoInitializeEx
)
set_target_properties(ccap_guid_test PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
if(MSVC)
target_compile_options(ccap_guid_test PRIVATE
/MP
/std:c++17
/Zc:__cplusplus
/bigobj
/wd4996
/D_CRT_SECURE_NO_WARNINGS
)
endif()
endif()
# Performance test executable - should be compiled in Release mode
add_executable(
ccap_performance_test
test_performance.cpp
)
target_link_libraries(
ccap_performance_test
ccap_test_utils
gtest_main
yuv
)
# Add LibYUV include directory for performance test
target_include_directories(ccap_performance_test PRIVATE ${libyuv_SOURCE_DIR}/include)
# Enable testing before any test registration
enable_testing()
# Register tests with CTest
include(GoogleTest)
# When cross-compiling (e.g., building ARM64 on x86_64), avoid discovering tests
# at configure/build time because it would attempt to execute the target binary
# for test listing on the host. We'll run tests explicitly (e.g., via QEMU) in CI.
if(NOT CMAKE_CROSSCOMPILING)
# Defer discovery to test time to avoid executing the binary during configure
gtest_discover_tests(ccap_convert_test DISCOVERY_MODE PRE_TEST)
gtest_discover_tests(ccap_performance_test DISCOVERY_MODE PRE_TEST)
if(WIN32)
gtest_discover_tests(ccap_guid_test DISCOVERY_MODE PRE_TEST)
endif()
else()
message(STATUS "CMAKE_CROSSCOMPILING is ON: skipping GoogleTest discovery at configure time.")
endif()
# Set test properties
set_target_properties(ccap_convert_test PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# Set performance test properties - optimize for Release builds
set_target_properties(ccap_performance_test PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# Add compile definitions for tests
target_compile_definitions(ccap_convert_test PRIVATE
$<$<CONFIG:Debug>:DEBUG> # Define DEBUG macro for Debug builds
$<$<CONFIG:Release>:NDEBUG> # Define NDEBUG macro for Release builds
$<$<NOT:$<BOOL:${MSVC}>>:GTEST_HAS_PTHREAD=1> # Enable pthread for non-MSVC compilers
)
target_compile_definitions(ccap_performance_test PRIVATE
$<$<CONFIG:Debug>:DEBUG> # Define DEBUG macro for Debug builds
$<$<CONFIG:Release>:NDEBUG> # Define NDEBUG macro for Release builds
$<$<NOT:$<BOOL:${MSVC}>>:GTEST_HAS_PTHREAD=1> # Enable pthread for non-MSVC compilers
)
if(MSVC)
target_compile_options(ccap_convert_test PRIVATE
/MP
/std:c++17
/Zc:__cplusplus
/Zc:preprocessor
/source-charset:utf-8
/bigobj # Allow big object files
/wd4996 # Disable deprecated function warnings
/D_CRT_SECURE_NO_WARNINGS
)
target_compile_options(ccap_performance_test PRIVATE
/MP
/std:c++17
/Zc:__cplusplus
/Zc:preprocessor
/source-charset:utf-8
/bigobj # Allow big object files
/wd4996 # Disable deprecated function warnings
/D_CRT_SECURE_NO_WARNINGS
)
else()
target_compile_options(ccap_convert_test PRIVATE
-std=c++17
)
target_compile_options(ccap_performance_test PRIVATE
-std=c++17
-O3
)
endif()