-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
132 lines (108 loc) · 4.47 KB
/
CMakeLists.txt
File metadata and controls
132 lines (108 loc) · 4.47 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
if(${CMAKE_VERSION} VERSION_LESS "3.20")
message(FATAL_ERROR "CMake >= 3.20 required")
endif()
cmake_minimum_required(VERSION 3.20)
project(slark)
#C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#
## Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wcast-align -Wcast-qual -Wconversion -Wdisabled-optimization -Wendif-labels -Wfloat-equal -Winit-self -Winline -Wmissing-include-dirs -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wpacked -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-promo -Wwrite-strings -Wno-variadic-macros -Wno-unknown-pragmas -Wno-undef")
# Set thread library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# print current path
message(STATUS "current path: " ${CMAKE_CURRENT_SOURCE_DIR})
# add core library
set(BUILD_PLATFORM "PC" CACHE STRING "build platform")
option(DISABLE_TEST "disable test" OFF)
option(DISABLE_HTTP "disable http" OFF)
macro(read_config)
# Check if config.json exists
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.json)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/config.json CONFIG_JSON_STRING)
else()
# Provide default configuration if file doesn't exist
set(CONFIG_JSON_STRING "{\"platform\": \"PC\", \"build_type\": \"Debug\", \"disable_http\": false, \"disable_test\": false }")
message(WARNING "config.json not found, using default configuration: ${CONFIG_JSON_STRING}")
endif()
#parse build platform
string(JSON BUILD_PLATFORM_VALUE GET ${CONFIG_JSON_STRING} platform)
set(BUILD_PLATFORM ${BUILD_PLATFORM_VALUE} CACHE STRING "build platform" FORCE)
#parse and set build type
string(JSON BUILD_TYPE GET ${CONFIG_JSON_STRING} build_type)
message(STATUS "build:${BUILD_TYPE}")
if(${BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_BUILD_TYPE DEBUG)
add_definitions(-DDEBUG) #set DEBUG = 1
else()
set(CMAKE_BUILD_TYPE RELEASE)
add_definitions(-DRELEASE) #set RELEASE = 1
endif()
if(${BUILD_PLATFORM_VALUE} STREQUAL "iOS" OR ${BUILD_PLATFORM_VALUE} STREQUAL "Android")
set(DISABLE_TEST ON CACHE BOOL "Disable test" FORCE)
else()
string(JSON DISABLE_TEST_VALUE GET ${CONFIG_JSON_STRING} disable_test)
set(DISABLE_TEST ${DISABLE_TEST_VALUE} CACHE BOOL "Disable test" FORCE)
endif()
string(JSON DISABLE_HTTP_VALUE GET ${CONFIG_JSON_STRING} disable_http)
set(DISABLE_HTTP ${DISABLE_HTTP_VALUE} CACHE BOOL "Disable http" FORCE)
endmacro()
#add base file
macro(add_base_file TARGET_NAME)
set(BASE_FILE_LISTS src/base/*.cpp src/base/*.hpp src/base/*.h)
file(GLOB BASE_FILES ${BASE_FILE_LISTS})
target_sources(${TARGET_NAME} PUBLIC ${BASE_FILES})
target_include_directories(${TARGET_NAME} PUBLIC src/base)
endmacro()
macro(add_core_file TARGET_NAME)
set(CORE_FILE_LISTS src/core/*.cpp src/core/*.hpp src/core/*.h
src/core/audio/*.cpp src/core/audio/*.hpp src/core/audio/*.h
src/core/demuxer/*.cpp src/core/demuxer/*.hpp src/core/demuxer/*.h
src/core/codec/*.cpp src/core/codec/*.hpp src/core/codec/*.h
src/core/video/*.h src/core/public/*.cpp public/*.h
)
file(GLOB CORE_FILES ${CORE_FILE_LISTS})
target_sources(${TARGET_NAME} PUBLIC ${CORE_FILES})
target_include_directories(${TARGET_NAME} PUBLIC src/core/public)
target_include_directories(${TARGET_NAME} PUBLIC src/core
src/core/demuxer
src/core/audio
src/core/codec
src/core/video
)
endmacro()
read_config()
add_library(${PROJECT_NAME} SHARED "")
#add base file
add_base_file(${PROJECT_NAME})
#add core file
add_core_file(${PROJECT_NAME})
if(${BUILD_PLATFORM} STREQUAL "iOS")
message(STATUS "add iOS interface")
include(CMake-iOS.cmake)
add_ios_sources(${PROJECT_NAME})
configure_ios_target(${PROJECT_NAME})
elseif (${BUILD_PLATFORM} STREQUAL "Android")
message(STATUS "add Android interface")
include(CMake-Android.cmake)
add_android_sources(${PROJECT_NAME})
endif ()
if(NOT DISABLE_HTTP)
message(STATUS "enable http")
add_subdirectory(src/http)
target_link_libraries(${PROJECT_NAME} PUBLIC http_request)
else()
message(STATUS "disable http")
endif()
if(NOT DISABLE_TEST)
message(STATUS "enable testing")
enable_testing()
include(cmake/gtest.cmake)
add_subdirectory(test)
else()
message(STATUS "disable testing")
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})