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