summaryrefslogtreecommitdiff
path: root/CMakeModules
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeModules')
-rw-r--r--CMakeModules/FindDiscordRPC.cmake27
-rw-r--r--CMakeModules/FindFFmpeg.cmake195
-rw-r--r--CMakeModules/FindOpus.cmake15
-rw-r--r--CMakeModules/Findenet.cmake16
-rw-r--r--CMakeModules/Findhttplib.cmake21
-rw-r--r--CMakeModules/Findinih.cmake16
-rw-r--r--CMakeModules/Findlibusb.cmake16
-rw-r--r--CMakeModules/Findlz4.cmake26
-rw-r--r--CMakeModules/Findzstd.cmake26
-rw-r--r--CMakeModules/WindowsCopyFiles.cmake27
10 files changed, 385 insertions, 0 deletions
diff --git a/CMakeModules/FindDiscordRPC.cmake b/CMakeModules/FindDiscordRPC.cmake
new file mode 100644
index 000000000..44ca9904f
--- /dev/null
+++ b/CMakeModules/FindDiscordRPC.cmake
@@ -0,0 +1,27 @@
1# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4
5find_path(DiscordRPC_INCLUDE_DIR discord_rpc.h)
6
7find_library(DiscordRPC_LIBRARY discord-rpc)
8
9include(FindPackageHandleStandardArgs)
10find_package_handle_standard_args(DiscordRPC
11 REQUIRED_VARS
12 DiscordRPC_LIBRARY
13 DiscordRPC_INCLUDE_DIR
14)
15
16if (DiscordRPC_FOUND AND NOT TARGET DiscordRPC::discord-rpc)
17 add_library(DiscordRPC::discord-rpc UNKNOWN IMPORTED)
18 set_target_properties(DiscordRPC::discord-rpc PROPERTIES
19 IMPORTED_LOCATION "${DiscordRPC_LIBRARY}"
20 INTERFACE_INCLUDE_DIRECTORIES "${DiscordRPC_INCLUDE_DIR}"
21 )
22endif()
23
24mark_as_advanced(
25 DiscordRPC_INCLUDE_DIR
26 DiscordRPC_LIBRARY
27)
diff --git a/CMakeModules/FindFFmpeg.cmake b/CMakeModules/FindFFmpeg.cmake
new file mode 100644
index 000000000..eedf28aea
--- /dev/null
+++ b/CMakeModules/FindFFmpeg.cmake
@@ -0,0 +1,195 @@
1# SPDX-FileCopyrightText: 2019 Citra Emulator Project
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4# FindFFmpeg
5# ----------
6#
7# Find the native FFmpeg includes and libraries
8#
9# This module defines the following variables:
10#
11# FFmpeg_INCLUDE_<component>: where to find <component>.h
12# FFmpeg_LIBRARY_<component>: where to find the <component> library
13# FFmpeg_INCLUDE_DIR: aggregate all the include paths
14# FFmpeg_LIBRARIES: aggregate all the paths to the libraries
15# FFmpeg_FOUND: True if all components have been found
16#
17# This module defines the following targets, which are prefered over variables:
18#
19# FFmpeg::<component>: Target to use <component> directly, with include path,
20# library and dependencies set up. If you are using a static build, you are
21# responsible for adding any external dependencies (such as zlib, bzlib...).
22#
23# <component> can be one of:
24# avcodec
25# avdevice
26# avfilter
27# avformat
28# avutil
29# postproc
30# swresample
31# swscale
32#
33
34set(_FFmpeg_ALL_COMPONENTS
35 avcodec
36 avdevice
37 avfilter
38 avformat
39 avutil
40 postproc
41 swresample
42 swscale
43)
44
45set(_FFmpeg_DEPS_avcodec avutil)
46set(_FFmpeg_DEPS_avdevice avcodec avformat avutil)
47set(_FFmpeg_DEPS_avfilter avutil)
48set(_FFmpeg_DEPS_avformat avcodec avutil)
49set(_FFmpeg_DEPS_postproc avutil)
50set(_FFmpeg_DEPS_swresample avutil)
51set(_FFmpeg_DEPS_swscale avutil)
52
53function(find_ffmpeg LIBNAME)
54 if(DEFINED ENV{FFMPEG_DIR})
55 set(FFMPEG_DIR $ENV{FFMPEG_DIR})
56 endif()
57
58 if(FFMPEG_DIR)
59 list(APPEND INCLUDE_PATHS
60 ${FFMPEG_DIR}
61 ${FFMPEG_DIR}/ffmpeg
62 ${FFMPEG_DIR}/lib${LIBNAME}
63 ${FFMPEG_DIR}/include/lib${LIBNAME}
64 ${FFMPEG_DIR}/include/ffmpeg
65 ${FFMPEG_DIR}/include
66 NO_DEFAULT_PATH
67 NO_CMAKE_FIND_ROOT_PATH
68 )
69 list(APPEND LIB_PATHS
70 ${FFMPEG_DIR}
71 ${FFMPEG_DIR}/lib
72 ${FFMPEG_DIR}/lib${LIBNAME}
73 NO_DEFAULT_PATH
74 NO_CMAKE_FIND_ROOT_PATH
75 )
76 else()
77 list(APPEND INCLUDE_PATHS
78 /usr/local/include/ffmpeg
79 /usr/local/include/lib${LIBNAME}
80 /usr/include/ffmpeg
81 /usr/include/lib${LIBNAME}
82 /usr/include/ffmpeg/lib${LIBNAME}
83 )
84
85 list(APPEND LIB_PATHS
86 /usr/local/lib
87 /usr/lib
88 )
89 endif()
90
91 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
92 HINTS ${INCLUDE_PATHS}
93 )
94
95 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
96 HINTS ${LIB_PATHS}
97 )
98
99 if(NOT FFMPEG_DIR AND (NOT FFmpeg_LIBRARY_${LIBNAME} OR NOT FFmpeg_INCLUDE_${LIBNAME}))
100 # Didn't find it in the usual paths, try pkg-config
101 find_package(PkgConfig QUIET)
102 pkg_check_modules(FFmpeg_PKGCONFIG_${LIBNAME} QUIET lib${LIBNAME})
103
104 find_path(FFmpeg_INCLUDE_${LIBNAME} lib${LIBNAME}/${LIBNAME}.h
105 ${FFmpeg_PKGCONFIG_${LIBNAME}_INCLUDE_DIRS}
106 )
107
108 find_library(FFmpeg_LIBRARY_${LIBNAME} ${LIBNAME}
109 ${FFmpeg_PKGCONFIG_${LIBNAME}_LIBRARY_DIRS}
110 )
111 endif()
112
113 if(FFmpeg_INCLUDE_${LIBNAME} AND FFmpeg_LIBRARY_${LIBNAME})
114 set(FFmpeg_INCLUDE_${LIBNAME} "${FFmpeg_INCLUDE_${LIBNAME}}" PARENT_SCOPE)
115 set(FFmpeg_LIBRARY_${LIBNAME} "${FFmpeg_LIBRARY_${LIBNAME}}" PARENT_SCOPE)
116
117 # Extract FFmpeg version from version.h
118 foreach(v MAJOR MINOR MICRO)
119 set(FFmpeg_${LIBNAME}_VERSION_${v} 0)
120 endforeach()
121 string(TOUPPER ${LIBNAME} LIBNAME_UPPER)
122 file(STRINGS "${FFmpeg_INCLUDE_${LIBNAME}}/lib${LIBNAME}/version.h" _FFmpeg_VERSION_H_CONTENTS REGEX "#define LIB${LIBNAME_UPPER}_VERSION_(MAJOR|MINOR|MICRO) ")
123 set(_FFmpeg_VERSION_REGEX "([0-9]+)")
124 foreach(v MAJOR MINOR MICRO)
125 if("${_FFmpeg_VERSION_H_CONTENTS}" MATCHES "#define LIB${LIBNAME_UPPER}_VERSION_${v}[\\t ]+${_FFmpeg_VERSION_REGEX}")
126 set(FFmpeg_${LIBNAME}_VERSION_${v} "${CMAKE_MATCH_1}")
127 endif()
128 endforeach()
129 set(FFmpeg_${LIBNAME}_VERSION "${FFmpeg_${LIBNAME}_VERSION_MAJOR}.${FFmpeg_${LIBNAME}_VERSION_MINOR}.${FFmpeg_${LIBNAME}_VERSION_MICRO}")
130 set(FFmpeg_${c}_VERSION "${FFmpeg_${LIBNAME}_VERSION}" PARENT_SCOPE)
131 unset(_FFmpeg_VERSION_REGEX)
132 unset(_FFmpeg_VERSION_H_CONTENTS)
133
134 set(FFmpeg_${c}_FOUND TRUE PARENT_SCOPE)
135 if(NOT FFmpeg_FIND_QUIETLY)
136 message("-- Found ${LIBNAME}: ${FFmpeg_INCLUDE_${LIBNAME}} ${FFmpeg_LIBRARY_${LIBNAME}} (version: ${FFmpeg_${LIBNAME}_VERSION})")
137 endif()
138 endif()
139endfunction()
140
141foreach(c ${_FFmpeg_ALL_COMPONENTS})
142 find_ffmpeg(${c})
143endforeach()
144
145foreach(c ${_FFmpeg_ALL_COMPONENTS})
146 if(FFmpeg_${c}_FOUND)
147 list(APPEND FFmpeg_INCLUDE_DIR ${FFmpeg_INCLUDE_${c}})
148 list(APPEND FFmpeg_LIBRARIES ${FFmpeg_LIBRARY_${c}})
149
150 add_library(FFmpeg::${c} IMPORTED UNKNOWN)
151 set_target_properties(FFmpeg::${c} PROPERTIES
152 IMPORTED_LOCATION ${FFmpeg_LIBRARY_${c}}
153 INTERFACE_INCLUDE_DIRECTORIES ${FFmpeg_INCLUDE_${c}}
154 )
155 if(_FFmpeg_DEPS_${c})
156 set(deps)
157 foreach(dep ${_FFmpeg_DEPS_${c}})
158 list(APPEND deps FFmpeg::${dep})
159 endforeach()
160
161 set_target_properties(FFmpeg::${c} PROPERTIES
162 INTERFACE_LINK_LIBRARIES "${deps}"
163 )
164 unset(deps)
165 endif()
166 endif()
167endforeach()
168
169if(FFmpeg_INCLUDE_DIR)
170 list(REMOVE_DUPLICATES FFmpeg_INCLUDE_DIR)
171endif()
172
173foreach(c ${FFmpeg_FIND_COMPONENTS})
174 list(APPEND _FFmpeg_REQUIRED_VARS FFmpeg_INCLUDE_${c} FFmpeg_LIBRARY_${c})
175endforeach()
176
177include(FindPackageHandleStandardArgs)
178find_package_handle_standard_args(FFmpeg
179 REQUIRED_VARS ${_FFmpeg_REQUIRED_VARS}
180 HANDLE_COMPONENTS
181)
182
183foreach(c ${_FFmpeg_ALL_COMPONENTS})
184 unset(_FFmpeg_DEPS_${c})
185endforeach()
186unset(_FFmpeg_ALL_COMPONENTS)
187unset(_FFmpeg_REQUIRED_VARS)
188
189include(FindPackageHandleStandardArgs)
190find_package_handle_standard_args(FFmpeg
191 REQUIRED_VARS
192 FFmpeg_LIBRARIES
193 FFmpeg_INCLUDE_DIR
194 HANDLE_COMPONENTS
195)
diff --git a/CMakeModules/FindOpus.cmake b/CMakeModules/FindOpus.cmake
new file mode 100644
index 000000000..25a44fd87
--- /dev/null
+++ b/CMakeModules/FindOpus.cmake
@@ -0,0 +1,15 @@
1# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4find_package(PkgConfig QUIET)
5pkg_search_module(OPUS QUIET IMPORTED_TARGET opus)
6
7include(FindPackageHandleStandardArgs)
8find_package_handle_standard_args(Opus
9 REQUIRED_VARS OPUS_LINK_LIBRARIES
10 VERSION_VAR OPUS_VERSION
11)
12
13if (Opus_FOUND AND NOT TARGET Opus::opus)
14 add_library(Opus::opus ALIAS PkgConfig::OPUS)
15endif()
diff --git a/CMakeModules/Findenet.cmake b/CMakeModules/Findenet.cmake
new file mode 100644
index 000000000..859a6f386
--- /dev/null
+++ b/CMakeModules/Findenet.cmake
@@ -0,0 +1,16 @@
1# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4
5find_package(PkgConfig QUIET)
6pkg_search_module(ENET QUIET IMPORTED_TARGET libenet)
7
8include(FindPackageHandleStandardArgs)
9find_package_handle_standard_args(enet
10 REQUIRED_VARS ENET_LINK_LIBRARIES
11 VERSION_VAR ENET_VERSION
12)
13
14if (enet_FOUND AND NOT TARGET enet::enet)
15 add_library(enet::enet ALIAS PkgConfig::ENET)
16endif()
diff --git a/CMakeModules/Findhttplib.cmake b/CMakeModules/Findhttplib.cmake
new file mode 100644
index 000000000..861207eb5
--- /dev/null
+++ b/CMakeModules/Findhttplib.cmake
@@ -0,0 +1,21 @@
1# SPDX-FileCopyrightText: 2022 Andrea Pappacoda <andrea@pappacoda.it>
2#
3# SPDX-License-Identifier: GPL-2.0-or-later
4
5include(FindPackageHandleStandardArgs)
6
7find_package(httplib QUIET CONFIG)
8if (httplib_CONSIDERED_CONFIGS)
9 find_package_handle_standard_args(httplib CONFIG_MODE)
10else()
11 find_package(PkgConfig QUIET)
12 pkg_search_module(HTTPLIB QUIET IMPORTED_TARGET cpp-httplib)
13 find_package_handle_standard_args(httplib
14 REQUIRED_VARS HTTPLIB_INCLUDEDIR
15 VERSION_VAR HTTPLIB_VERSION
16 )
17endif()
18
19if (httplib_FOUND AND NOT TARGET httplib::httplib)
20 add_library(httplib::httplib ALIAS PkgConfig::HTTPLIB)
21endif()
diff --git a/CMakeModules/Findinih.cmake b/CMakeModules/Findinih.cmake
new file mode 100644
index 000000000..b8d38dcff
--- /dev/null
+++ b/CMakeModules/Findinih.cmake
@@ -0,0 +1,16 @@
1# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4
5find_package(PkgConfig QUIET)
6pkg_search_module(INIREADER QUIET IMPORTED_TARGET INIReader)
7
8include(FindPackageHandleStandardArgs)
9find_package_handle_standard_args(inih
10 REQUIRED_VARS INIREADER_LINK_LIBRARIES
11 VERSION_VAR INIREADER_VERSION
12)
13
14if (inih_FOUND AND NOT TARGET inih::INIReader)
15 add_library(inih::INIReader ALIAS PkgConfig::INIREADER)
16endif()
diff --git a/CMakeModules/Findlibusb.cmake b/CMakeModules/Findlibusb.cmake
new file mode 100644
index 000000000..0eadce957
--- /dev/null
+++ b/CMakeModules/Findlibusb.cmake
@@ -0,0 +1,16 @@
1# SPDX-FileCopyrightText: 2022 Alexandre Bouvier <contact@amb.tf>
2#
3# SPDX-License-Identifier: GPL-3.0-or-later
4
5find_package(PkgConfig QUIET)
6pkg_search_module(LIBUSB QUIET IMPORTED_TARGET libusb-1.0)
7
8include(FindPackageHandleStandardArgs)
9find_package_handle_standard_args(libusb
10 REQUIRED_VARS LIBUSB_LINK_LIBRARIES
11 VERSION_VAR LIBUSB_VERSION
12)
13
14if (libusb_FOUND AND NOT TARGET libusb::usb)
15 add_library(libusb::usb ALIAS PkgConfig::LIBUSB)
16endif()
diff --git a/CMakeModules/Findlz4.cmake b/CMakeModules/Findlz4.cmake
new file mode 100644
index 000000000..7a9a02d4e
--- /dev/null
+++ b/CMakeModules/Findlz4.cmake
@@ -0,0 +1,26 @@
1# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4include(FindPackageHandleStandardArgs)
5
6find_package(lz4 QUIET CONFIG)
7if (lz4_CONSIDERED_CONFIGS)
8 find_package_handle_standard_args(lz4 CONFIG_MODE)
9else()
10 find_package(PkgConfig QUIET)
11 pkg_search_module(LZ4 QUIET IMPORTED_TARGET liblz4)
12 find_package_handle_standard_args(lz4
13 REQUIRED_VARS LZ4_LINK_LIBRARIES
14 VERSION_VAR LZ4_VERSION
15 )
16endif()
17
18if (lz4_FOUND AND NOT TARGET lz4::lz4)
19 if (TARGET LZ4::lz4_shared)
20 add_library(lz4::lz4 ALIAS LZ4::lz4_shared)
21 elseif (TARGET LZ4::lz4_static)
22 add_library(lz4::lz4 ALIAS LZ4::lz4_static)
23 else()
24 add_library(lz4::lz4 ALIAS PkgConfig::LZ4)
25 endif()
26endif()
diff --git a/CMakeModules/Findzstd.cmake b/CMakeModules/Findzstd.cmake
new file mode 100644
index 000000000..ae3ea0865
--- /dev/null
+++ b/CMakeModules/Findzstd.cmake
@@ -0,0 +1,26 @@
1# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4include(FindPackageHandleStandardArgs)
5
6find_package(zstd QUIET CONFIG)
7if (zstd_CONSIDERED_CONFIGS)
8 find_package_handle_standard_args(zstd CONFIG_MODE)
9else()
10 find_package(PkgConfig QUIET)
11 pkg_search_module(ZSTD QUIET IMPORTED_TARGET libzstd)
12 find_package_handle_standard_args(zstd
13 REQUIRED_VARS ZSTD_LINK_LIBRARIES
14 VERSION_VAR ZSTD_VERSION
15 )
16endif()
17
18if (zstd_FOUND AND NOT TARGET zstd::zstd)
19 if (TARGET zstd::libzstd_shared)
20 add_library(zstd::zstd ALIAS zstd::libzstd_shared)
21 elseif (TARGET zstd::libzstd_static)
22 add_library(zstd::zstd ALIAS zstd::libzstd_static)
23 else()
24 add_library(zstd::zstd ALIAS PkgConfig::ZSTD)
25 endif()
26endif()
diff --git a/CMakeModules/WindowsCopyFiles.cmake b/CMakeModules/WindowsCopyFiles.cmake
new file mode 100644
index 000000000..08b598365
--- /dev/null
+++ b/CMakeModules/WindowsCopyFiles.cmake
@@ -0,0 +1,27 @@
1# SPDX-FileCopyrightText: 2018 yuzu Emulator Project
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4# This file provides the function windows_copy_files.
5# This is only valid on Windows.
6
7# Include guard
8if(__windows_copy_files)
9 return()
10endif()
11set(__windows_copy_files YES)
12
13# Any number of files to copy from SOURCE_DIR to DEST_DIR can be specified after DEST_DIR.
14# This copying happens post-build.
15function(windows_copy_files TARGET SOURCE_DIR DEST_DIR)
16 # windows commandline expects the / to be \ so switch them
17 string(REPLACE "/" "\\\\" SOURCE_DIR ${SOURCE_DIR})
18 string(REPLACE "/" "\\\\" DEST_DIR ${DEST_DIR})
19
20 # /NJH /NJS /NDL /NFL /NC /NS /NP - Silence any output
21 # cmake adds an extra check for command success which doesn't work too well with robocopy
22 # so trick it into thinking the command was successful with the || cmd /c "exit /b 0"
23 add_custom_command(TARGET ${TARGET} POST_BUILD
24 COMMAND ${CMAKE_COMMAND} -E make_directory ${DEST_DIR}
25 COMMAND robocopy ${SOURCE_DIR} ${DEST_DIR} ${ARGN} /NJH /NJS /NDL /NFL /NC /NS /NP || cmd /c "exit /b 0"
26 )
27endfunction()