This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
164 lines (147 loc) · 5.47 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
cmake_minimum_required(VERSION 3.14)
project(live-paper VERSION 0.0.0)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24.0)
cmake_policy(SET CMP0135 NEW)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(FetchContent)
# FFmpeg
if(NOT MSVC)
find_package(FFmpeg 6.0 REQUIRED COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE)
else()
FetchContent_Declare(
FFmpeg
URL https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z
)
FetchContent_GetProperties(FFmpeg)
if(NOT ffmpeg_POPULATED)
FetchContent_MakeAvailable(FFmpeg)
add_library(FFmpeg::FFmpeg INTERFACE IMPORTED)
set_target_properties(FFmpeg::FFmpeg PROPERTIES
INTERFACE_LINK_DIRECTORIES "${ffmpeg_SOURCE_DIR}/lib"
INTERFACE_INCLUDE_DIRECTORIES "${ffmpeg_SOURCE_DIR}/include/"
INTERFACE_LINK_LIBRARIES "avcodec;avformat;avutil;swscale"
)
set(FFMPEG_DLL_NAMES "avcodec" "avformat" "avutil" "swresample" "swscale")
set(FFMPEG_DLLS)
foreach(DLL_NAME ${FFMPEG_DLL_NAMES})
file(GLOB DLL_FILES "${ffmpeg_SOURCE_DIR}/bin/${DLL_NAME}*.dll")
list(LENGTH DLL_FILES DLL_FILES_LENGTH)
if(NOT DLL_FILES_LENGTH EQUAL 1)
message(FATAL_ERROR "Expected exactly one DLL for ${DLL_NAME}, but found ${DLL_FILES_LENGTH}")
endif()
list(APPEND FFMPEG_DLLS ${DLL_FILES})
endforeach()
endif()
endif()
# SDL2
if(NOT MSVC)
find_package(SDL2 REQUIRED)
if (NOT TARGET SDL2::SDL2)
add_library(SDL2::SDL2 UNKNOWN IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LOCATION "${SDL2_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
)
endif()
else()
FetchContent_Declare(
SDL2
URL https://www.libsdl.org/release/SDL2-devel-2.30.9-VC.zip
)
FetchContent_GetProperties(SDL2)
if(NOT sdl2_POPULATED)
FetchContent_MakeAvailable(SDL2)
add_library(SDL2::SDL2 SHARED IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LOCATION "${sdl2_SOURCE_DIR}/lib/x64/SDL2.dll"
IMPORTED_IMPLIB "${sdl2_SOURCE_DIR}/lib/x64/SDL2.lib"
INTERFACE_INCLUDE_DIRECTORIES "${sdl2_SOURCE_DIR}/include/"
)
add_library(SDL2::SDL2main STATIC IMPORTED)
set_target_properties(SDL2::SDL2main PROPERTIES
IMPORTED_LOCATION "${sdl2_SOURCE_DIR}/lib/x64/SDL2main.lib"
)
endif()
endif()
# tray (on windows only)
if(WIN32)
FetchContent_Declare(
tray
URL https://raw.githubusercontent.com/zserge/tray/master/tray.h
DOWNLOAD_NO_EXTRACT TRUE
)
FetchContent_GetProperties(tray)
if(NOT tray_POPULATED)
FetchContent_MakeAvailable(tray)
add_library(tray::tray INTERFACE IMPORTED)
set_target_properties(tray::tray PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${tray_SOURCE_DIR}"
)
endif()
endif()
# argtable
FetchContent_Declare(
argtable
URL https://github.com/argtable/argtable3/releases/download/v3.2.2.f25c624/argtable-v3.2.2.f25c624-amalgamation.tar.gz
)
FetchContent_GetProperties(argtable)
if(NOT argtable_POPULATED)
FetchContent_MakeAvailable(argtable)
add_library(argtable::argtable INTERFACE IMPORTED)
set_target_properties(argtable::argtable PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${argtable_SOURCE_DIR}/"
INTERFACE_SOURCES "${argtable_SOURCE_DIR}/argtable3.c"
)
endif()
# executable
add_executable(live-paper
$<$<PLATFORM_ID:Windows>:src/platform_windows.c;assets/win.rc>
$<$<PLATFORM_ID:Linux>:src/platform_linux.c>
$<$<PLATFORM_ID:Darwin>:src/platform_macos.c>
src/main.c src/fail.c src/video.c
)
set_target_properties(live-paper PROPERTIES
WIN32_EXECUTABLE $<PLATFORM_ID:Windows>
C_STANDARD 99
)
target_link_libraries(live-paper PRIVATE
$<$<BOOL:${MINGW}>:mingw32>
"$<$<PLATFORM_ID:Windows>:SDL2::SDL2main;tray::tray;shell32;shlwapi>"
"$<$<PLATFORM_ID:Linux>:m;X11>"
SDL2::SDL2 FFmpeg::FFmpeg argtable::argtable
)
add_custom_command(TARGET live-paper POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico"
$<TARGET_FILE_DIR:live-paper>
)
if(MSVC)
add_custom_command(TARGET live-paper POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${FFMPEG_DLLS}
$<TARGET_FILE:SDL2::SDL2>
$<TARGET_FILE_DIR:live-paper>
)
endif()
# binaries
if(MSVC)
set(INSTALL_DIR ".")
install(TARGETS live-paper RUNTIME DESTINATION ${INSTALL_DIR})
install(FILES $<TARGET_FILE:SDL2::SDL2> ${FFMPEG_DLLS} "${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico"
DESTINATION ${INSTALL_DIR}
)
set(CPACK_PACKAGE_DIRECTORY dist)
set(CPACK_GENERATOR WIX ZIP)
set(CPACK_PACKAGE_NAME LivePaper)
set(CPACK_PACKAGE_VENDOR Zuranthus)
set(CPACK_PACKAGE_EXECUTABLES live-paper LivePaper)
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/zuranthus/LivePaper")
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico")
set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/assets/icon.ico")
set(CPACK_WIX_UPGRADE_GUID A73EF541-19D7-4E50-8CC6-B4E1BAFB760D)
include(CPack)
endif()