1# Copyright (c) 2022-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14###############################
15# find python3
16find_package (Python3 COMPONENTS Interpreter)
17
18IF(Python3_FOUND)
19    SET(PYTHON ${Python3_EXECUTABLE})
20ELSE()
21    MESSAGE(FATAL_ERROR "No Python interpreter found")
22ENDIF(Python3_FOUND)
23
24###############################
25# definitions
26
27set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
28
29IF(UNIX OR MINGW)
30ADD_DEFINITIONS(
31    -g -ggdb
32)
33IF(UNIX)
34ADD_LINK_OPTIONS(
35    -rdynamic
36)
37ELSE()
38ADD_LINK_OPTIONS(
39    -Wl,--export-all-symbols
40)
41ENDIF(UNIX)
42ENDIF(UNIX OR MINGW)
43
44ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS -DHST_WORKING_DIR="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
45
46IF(CMAKE_CL_64)
47    ADD_DEFINITIONS(-DWIN64)
48ENDIF(CMAKE_CL_64)
49
50IF(MSVC)
51  ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS /source-charset:utf-8)
52ENDIF(MSVC)
53
54set(TOP_DIR ${CMAKE_SOURCE_DIR})
55
56ADD_DEFINITIONS(
57        -D__STDC_FORMAT_MACROS
58        -DHST_PLUGIN_PATH="./"
59)
60if (WIN32)
61    add_definitions( -DHST_PLUGIN_FILE_TAIL=".dll" )
62else()
63    add_definitions( -DHST_PLUGIN_FILE_TAIL=".so" )
64endif()
65
66###############################
67# includes
68
69INCLUDE_DIRECTORIES(BEFORE
70        ${TOP_DIR}/3rdparty/testngpp2/include
71        ${TOP_DIR}/demo/system_tests
72        ${TOP_DIR}/histreamer/engine
73        ${TOP_DIR}/histreamer/engine/include
74        ${TOP_DIR}/histreamer/engine/scene/standard
75        ${TOP_DIR}/histreamer/engine/plugin
76        ${TOP_DIR}/3rdparty/ohos
77        ${TOP_DIR}/3rdparty/debug)
78IF(MSVC)
79#INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/include/msinttypes)
80ENDIF(MSVC)
81
82###############################
83# Generate Test Suite cxx files
84
85SET(TEST_SUITES_DIR ${TOP_DIR}/histreamer/test/scenetest/gen_testsuites)
86SET(TEST_GENERATOR ${TOP_DIR}/3rdparty/testngpp2/generator/testngppgen.py)
87SET(TEST_SUITE_PREFIX st_)
88
89SET(TESTSUITE_ENTRY ${TEST_SUITES_DIR}/AllTestSuites.cxx)
90SET(TESTSUITE_SRCS ${TESTSUITE_ENTRY})
91
92SET(UT_CASE_DIR ${TOP_DIR}/histreamer/test/scenetest)
93file(GLOB_RECURSE UT_CASES_PATH
94        ${UT_CASE_DIR}/*.h
95        ./helper/media_data_source_imp.cpp
96        ./helper/std_player.cpp
97        ./audio_player/TestFastPlayer.cpp
98        ./*.cpp
99        )
100
101FOREACH(CASE_PATH ${UT_CASES_PATH})
102
103GET_FILENAME_COMPONENT(CASE ${CASE_PATH} NAME_WE)
104
105SET(INPUT_H ${UT_CASE_DIR}/${CASE}.h)
106SET(OUTPUT_CXX ${TEST_SUITES_DIR}/scenetest_${CASE}.cxx)
107
108SET(TESTSUITE_SRCS ${TESTSUITE_SRCS} ${OUTPUT_CXX})
109
110ADD_CUSTOM_COMMAND(
111  OUTPUT ${OUTPUT_CXX} ${TESTSUITE_ENTRY}
112  COMMAND ${PYTHON} ${TEST_GENERATOR} -d ${TEST_SUITES_DIR} -p ${TEST_SUITE_PREFIX} ${INPUT_H}
113  DEPENDS ${INPUT_H}
114)
115
116ENDFOREACH()
117
118###############################
119# src files
120SET(TEST_PLUGIN_SRCS
121        ${TOP_DIR}/histreamer/engine/plugin/core/plugin_register.cpp
122        ${TOP_DIR}/histreamer/engine/plugin/core/muxer.cpp
123        ${TOP_DIR}/histreamer/engine/plugin/core/source.cpp
124        ${TOP_DIR}/histreamer/engine/plugin/core/demuxer.cpp
125        ${TOP_DIR}/histreamer/engine/plugin/core/base.cpp
126        ${TOP_DIR}/histreamer/engine/plugin/core/audio_sink.cpp
127        ${TOP_DIR}/histreamer/engine/plugin/core/codec.cpp
128        ${TOP_DIR}/histreamer/engine/plugin/core/video_sink.cpp
129        ${TOP_DIR}/histreamer/engine/plugin/core/plugin_core_utils.cpp
130        ${TOP_DIR}/histreamer/engine/plugin/core/plugin_wrapper.cpp
131        ${TOP_DIR}/histreamer/engine/plugin/core/output_sink.cpp
132        ${TOP_DIR}/histreamer/engine/foundation/osal/filesystem/file_system.cpp
133        ${TOP_DIR}/histreamer/engine/foundation/osal/thread/mutex.cpp
134        ${TOP_DIR}/histreamer/engine/foundation/osal/thread/scoped_lock.cpp)
135
136###############################
137# dependencies
138if (MINGW)
139    set(ffmpeg_lib_path ${TOP_DIR}/3rdparty/ffmpeg/windows/lib)
140    set(sdl_lib_path ${TOP_DIR}/3rdparty/SDL2.0/windows/lib/x64)
141    set(curl_lib_path ${TOP_DIR}/3rdparty/curl/lib/windows)
142else ()
143    if (${OHOS_LITE})
144        set(CMAKE_CXX_FLAGS "-g -ggdb3 -O0 -std=c++11 -Wall")
145    else()
146        set(CMAKE_CXX_FLAGS "-g -ggdb3 -O0 -std=c++17 -Wall")
147    endif()
148    set(ffmpeg_lib_path ${TOP_DIR}/3rdparty/ffmpeg/linux/lib)
149    set(sdl_lib_path ${TOP_DIR}/3rdparty/SDL2.0/linux/lib)
150    set(curl_lib_path ${TOP_DIR}/3rdparty/curl/lib/linux)
151    set(z_lib_path /usr/lib/x86_64-linux-gnu)
152endif ()
153
154link_directories(
155        ${ffmpeg_lib_path}
156        ${sdl_lib_path}
157        ${curl_lib_path}
158        ${z_lib_path}
159)
160
161file(GLOB OSAL_THREAD_SRCS ${TOP_DIR}/histreamer/engine/foundation/osal/thread/*.cpp)
162if (${OHOS_LITE})
163    # only for lite stream source player
164    set(TEST_HELPER_SRCS
165            ${TOP_DIR}/histreamer/test/scenetest/helper/lite_player.cpp
166            ${TOP_DIR}/histreamer/test/scenetest/helper/lite_stream_player.cpp
167            ${TOP_DIR}/histreamer/test/scenetest/helper/lite_audio_recorder.cpp
168            ${OSAL_THREAD_SRCS}
169            ${TOP_DIR}/histreamer/engine/scene/common/data_stream.cpp
170            ${TOP_DIR}/histreamer/engine/scene/common/data_stream_impl.cpp
171            )
172else()
173    set(TEST_HELPER_SRCS
174            ${TOP_DIR}/histreamer/test/scenetest/helper/media_data_source_imp.cpp
175            ${TOP_DIR}/histreamer/test/scenetest/helper/std_player.cpp
176            ${OSAL_THREAD_SRCS}
177            ${TOP_DIR}/histreamer/engine/foundation/osal/utils/util.cpp
178            ${TOP_DIR}/histreamer/test/scenetest/helper/std_audio_recorder.cpp
179            )
180endif ()
181
182set(TEST_HELPER_SRCS
183        ${TEST_HELPER_SRCS}
184        ${TOP_DIR}/3rdparty/debug/crashdump/common/crash_handler_register.cpp
185        ${TOP_DIR}/histreamer/test/scenetest/helper/main.cpp
186        )
187
188###############################
189# targets
190link_directories(${TOP_DIR}/3rdparty/testngpp2/lib)
191
192ADD_EXECUTABLE(histreamer_scenetest ${TESTSUITE_SRCS} ${TEST_HELPER_SRCS} ${3RDPARTY_SRCS} ${TEST_PLUGIN_SRCS})
193
194IF(UNIX)
195TARGET_LINK_LIBRARIES(histreamer_scenetest
196                      ${TOP_DIR}/3rdparty/testngpp2/lib/libtestngpp.a
197                      dl
198                      histreamer
199                      pthread
200                      ${ffmpeg_lib_path}/libavformat.a
201                      ${ffmpeg_lib_path}/libavcodec.a
202                      ${ffmpeg_lib_path}/libavdevice.a
203                      ${ffmpeg_lib_path}/libavfilter.a
204                      ${ffmpeg_lib_path}/libavutil.a
205                      ${ffmpeg_lib_path}/libswscale.a
206                      ${ffmpeg_lib_path}/libswresample.a
207                      ${ffmpeg_lib_path}/liblzma.a
208                      curl
209                      SDL2-2.0
210                      z
211                      )
212ELSE()
213TARGET_LINK_LIBRARIES(histreamer_scenetest testngpp2 histreamer)
214ENDIF()
215