-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
142 lines (122 loc) · 5.57 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.10)
project(cloudstorage)
find_package(PkgConfig)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)
endif()
set(CMAKE_PREFIX_PATH ${PREFIX_PATH_RELEASE} ${PREFIX_PATH_DEBUG} ${CMAKE_PREFIX_PATH})
if(WIN32)
set(DEFAULT_BUILD_SHARED_LIBS OFF)
else()
set(DEFAULT_BUILD_SHARED_LIBS ON)
endif()
option(BUILD_SHARED_LIBS "whether to build shared libraries" ${DEFAULT_BUILD_SHARED_LIBS})
function(cloudstorage_find_library LIBRARY)
cmake_parse_arguments(CLOUDSTORAGE_LIBRARY
""
"INCLUDE"
"LIBRARY_PATH_SUFFIXES;INCLUDE_PATH_SUFFIXES;NAMES;DEBUG_NAMES"
${ARGN})
find_library(${LIBRARY}_LIBRARY
NAMES ${CLOUDSTORAGE_LIBRARY_NAMES}
PATH_SUFFIXES ${CLOUDSTORAGE_LIBRARY_LIBRARY_PATH_SUFFIXES})
set(${LIBRARY}_LIBRARY ${${LIBRARY}} PARENT_SCOPE)
if(NOT CLOUDSTORAGE_LIBRARY_DEBUG_NAMES)
set(CLOUDSTORAGE_LIBRARY_DEBUG_NAMES ${CLOUDSTORAGE_LIBRARY_NAMES})
endif()
find_library(${LIBRARY}_LIBRARY_DEBUG
NAMES ${CLOUDSTORAGE_LIBRARY_DEBUG_NAMES}
PATHS ${PREFIX_PATH_DEBUG}/lib ${QT_HOST_DATA}
PATH_SUFFIXES ${CLOUDSTORAGE_LIBRARY_LIBRARY_PATH_SUFFIXES}
NO_DEFAULT_PATH)
set(${LIBRARY}_LIBRARY_DEBUG ${${LIBRARY}_DEBUG} PARENT_SCOPE)
if(CLOUDSTORAGE_LIBRARY_INCLUDE)
find_path(${LIBRARY}_INCLUDE_DIR
${CLOUDSTORAGE_LIBRARY_INCLUDE}
PATH_SUFFIXES ${CLOUDSTORAGE_LIBRARY_INCLUDE_PATH_SUFFIXES})
set(${LIBRARY}_INCLUDE_DIR ${${LIBRARY}_INCLUDE_DIR} PARENT_SCOPE)
endif()
endfunction()
function(cloudstorage_target_link_library TARGET LIBRARY)
if(${LIBRARY} STREQUAL "ffmpeg")
cloudstorage_target_link_library(${TARGET} avformat)
cloudstorage_target_link_library(${TARGET} avfilter)
cloudstorage_target_link_library(${TARGET} avcodec)
cloudstorage_target_link_library(${TARGET} avutil)
cloudstorage_target_link_library(${TARGET} swresample)
cloudstorage_target_link_library(${TARGET} swscale)
return()
endif()
if(PKG_CONFIG_FOUND)
pkg_search_module(${LIBRARY} IMPORTED_TARGET ${LIBRARY} lib${LIBRARY})
if(${LIBRARY}_FOUND)
if(${BUILD_SHARED_LIBS})
target_link_libraries(${TARGET} PRIVATE PkgConfig::${LIBRARY})
else()
foreach(ENTRY ${${LIBRARY}_STATIC_LDFLAGS})
set(FLAGS "${FLAGS} ${ENTRY}")
endforeach()
string(STRIP ${FLAGS} FLAGS)
target_link_libraries(${TARGET} PRIVATE "${FLAGS}")
target_link_directories(${TARGET} PRIVATE ${${LIBRARY}_STATIC_LIBRARY_DIRS})
target_include_directories(${TARGET} PRIVATE ${${LIBRARY}_STATIC_INCLUDE_DIRS})
target_compile_options(${TARGET} PRIVATE ${${LIBRARY}_STATIC_CFLAGS})
endif()
return()
endif()
endif()
if(${LIBRARY}_LIBRARY_DEBUG)
target_link_libraries(${TARGET} PRIVATE
optimized ${${LIBRARY}_LIBRARY}
debug ${${LIBRARY}_LIBRARY_DEBUG}
)
else()
target_link_libraries(${TARGET} PRIVATE ${${LIBRARY}_LIBRARY})
endif()
target_include_directories(${TARGET} PRIVATE ${${LIBRARY}_INCLUDE_DIR})
endfunction()
if(CMAKE_SYSTEM_NAME STREQUAL iOS)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
endif()
find_package(Threads REQUIRED)
cloudstorage_find_library(jsoncpp INCLUDE_PATH_SUFFIXES jsoncpp INCLUDE json/json.h NAMES jsoncpp)
cloudstorage_find_library(curl INCLUDE curl/curl.h NAMES libcurl curl DEBUG_NAMES libcurl-d)
cloudstorage_find_library(microhttpd INCLUDE microhttpd.h NAMES microhttpd libmicrohttpd DEBUG_NAMES libmicrohttpd_d)
cloudstorage_find_library(avcodec INCLUDE libavcodec/avcodec.h NAMES avcodec)
cloudstorage_find_library(avfilter INCLUDE libavfilter/avfilter.h NAMES avfilter)
cloudstorage_find_library(avformat INCLUDE libavformat/avformat.h NAMES avformat)
cloudstorage_find_library(avutil INCLUDE libavutil/avutil.h NAMES avutil)
cloudstorage_find_library(swresample INCLUDE libswresample/swresample.h NAMES swresample)
cloudstorage_find_library(swscale INCLUDE libswscale/swscale.h NAMES swscale)
if(avcodec_LIBRARY AND avfilter_LIBRARY AND avformat_LIBRARY AND avutil_LIBRARY AND swresample_LIBRARY AND swscale_LIBRARY)
set(ffmpeg_FOUND true)
endif()
if(NOT CMAKE_CROSSCOMPILING)
add_subdirectory(tools)
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/build-tools)
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build-tools ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/tools)
if(CMAKE_CONFIGURATION_TYPES)
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build-tools ${CMAKE_COMMAND} --build . --config ${CONFIG})
endforeach()
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR}/build-tools ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE})
endif()
include(${CMAKE_CURRENT_BINARY_DIR}/build-tools/ImportExecutables.cmake)
endif()
add_subdirectory(src)
if(curl_LIBRARY AND microhttpd_LIBRARY)
add_subdirectory(bin)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
add_subdirectory(examples)
endif()
endif()
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
add_subdirectory(test)
endif()
endif()