summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt178
1 files changed, 32 insertions, 146 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 80a8d4ed8..40ca8b149 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,16 @@ option(YUZU_USE_BUNDLED_OPUS "Compile bundled opus" ON)
35 35
36option(YUZU_TESTS "Compile tests" ON) 36option(YUZU_TESTS "Compile tests" ON)
37 37
38option(YUZU_USE_BUNDLED_VCPKG "Use vcpkg for yuzu dependencies" OFF)
39
40if (YUZU_USE_BUNDLED_VCPKG)
41 include(${CMAKE_SOURCE_DIR}/externals/vcpkg/scripts/buildsystems/vcpkg.cmake)
42elseif(NOT "$ENV{VCPKG_TOOLCHAIN_FILE}" STREQUAL "")
43 # Disable manifest mode (use vcpkg classic mode) when using a custom vcpkg installation
44 option(VCPKG_MANIFEST_MODE "")
45 include("$ENV{VCPKG_TOOLCHAIN_FILE}")
46endif()
47
38# Default to a Release build 48# Default to a Release build
39get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 49get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
40if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) 50if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
@@ -144,82 +154,34 @@ endif()
144set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) 154set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
145 155
146# System imported libraries 156# System imported libraries
147# If not found, download any missing through Conan
148# ======================================================================= 157# =======================================================================
149set(CONAN_CMAKE_SILENT_OUTPUT TRUE)
150set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
151if (YUZU_CONAN_INSTALLED)
152 if (IS_MULTI_CONFIG)
153 include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
154 else()
155 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
156 endif()
157 list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
158 list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
159 conan_basic_setup()
160 message(STATUS "Adding conan installed libraries to the search path")
161endif()
162 158
163macro(yuzu_find_packages) 159find_package(fmt 8.0.1 REQUIRED CONFIG)
164 set(options FORCE_REQUIRED) 160find_package(lz4 1.8 REQUIRED)
165 cmake_parse_arguments(FN "${options}" "" "" ${ARGN}) 161find_package(nlohmann_json 3.8 REQUIRED CONFIG)
166 162find_package(ZLIB 1.2 REQUIRED)
167 # Cmake has a *serious* lack of 2D array or associative array...
168 # Capitalization matters here. We need the naming to match the generated paths from Conan
169 set(REQUIRED_LIBS
170 # Cmake Pkg Prefix Version Conan Pkg
171 "fmt 8.0.1 fmt/8.1.1"
172 "lz4 1.8 lz4/1.9.2"
173 "nlohmann_json 3.8 nlohmann_json/3.8.0"
174 "ZLIB 1.2 zlib/1.2.11"
175 "zstd 1.5 zstd/1.5.0"
176 # can't use opus until AVX check is fixed: https://github.com/yuzu-emu/yuzu/pull/4068
177 #"opus 1.3 opus/1.3.1"
178 )
179 if (YUZU_TESTS)
180 list(APPEND REQUIRED_LIBS
181 "Catch2 2.13.7 catch2/2.13.7"
182 )
183 endif()
184 163
185 foreach(PACKAGE ${REQUIRED_LIBS}) 164# Search for config-only package first (for vcpkg), then try non-config
186 string(REGEX REPLACE "[ \t\r\n]+" ";" PACKAGE_SPLIT ${PACKAGE}) 165find_package(zstd 1.5 CONFIG)
187 list(GET PACKAGE_SPLIT 0 PACKAGE_PREFIX) 166if (NOT zstd_FOUND)
188 list(GET PACKAGE_SPLIT 1 PACKAGE_VERSION) 167 find_package(zstd 1.5 REQUIRED)
189 list(GET PACKAGE_SPLIT 2 PACKAGE_CONAN) 168endif()
190 # This function is called twice, once to check if the packages exist on the system already 169
191 # and a second time to check if conan installed them properly. The second check passes in FORCE_REQUIRED 170if (YUZU_TESTS)
192 if (NOT ${PACKAGE_PREFIX}_FOUND) 171 find_package(Catch2 2.13.7 REQUIRED CONFIG)
193 if (FN_FORCE_REQUIRED) 172endif()
194 find_package(${PACKAGE_PREFIX} ${PACKAGE_VERSION} REQUIRED)
195 else()
196 find_package(${PACKAGE_PREFIX} ${PACKAGE_VERSION})
197 endif()
198 endif()
199 if (NOT ${PACKAGE_PREFIX}_FOUND)
200 list(APPEND CONAN_REQUIRED_LIBS ${PACKAGE_CONAN})
201 else()
202 # Set a legacy findPackage.cmake style PACKAGE_LIBRARIES variable for subprojects that rely on this
203 set(${PACKAGE_PREFIX}_LIBRARIES "${PACKAGE_PREFIX}::${PACKAGE_PREFIX}")
204 endif()
205 endforeach()
206 unset(FN_FORCE_REQUIRED)
207endmacro()
208 173
209find_package(Boost 1.73.0 COMPONENTS context headers) 174find_package(Boost 1.73.0 COMPONENTS context)
210if (Boost_FOUND) 175if (Boost_FOUND)
211 set(Boost_LIBRARIES Boost::boost) 176 set(Boost_LIBRARIES Boost::boost)
212 # Conditionally add Boost::context only if the active version of the Conan or system Boost package provides it 177 # Conditionally add Boost::context only if the found Boost package provides it
213 # The old version is missing Boost::context, so we want to avoid adding in that case 178 # The old version is missing Boost::context, so we want to avoid adding in that case
214 # The new version requires adding Boost::context to prevent linking issues 179 # The new version requires adding Boost::context to prevent linking issues
215 #
216 # This one is used by Conan on subsequent CMake configures, not the first configure.
217 if (TARGET Boost::context) 180 if (TARGET Boost::context)
218 list(APPEND Boost_LIBRARIES Boost::context) 181 list(APPEND Boost_LIBRARIES Boost::context)
219 endif() 182 endif()
220else() 183else()
221 message(STATUS "Boost 1.79.0 or newer not found, falling back to Conan") 184 message(FATAL_ERROR "Boost 1.73.0 or newer not found")
222 list(APPEND CONAN_REQUIRED_LIBS "boost/1.79.0")
223endif() 185endif()
224 186
225# boost:asio has functions that require AcceptEx et al 187# boost:asio has functions that require AcceptEx et al
@@ -227,24 +189,14 @@ if (MINGW)
227 find_library(MSWSOCK_LIBRARY mswsock REQUIRED) 189 find_library(MSWSOCK_LIBRARY mswsock REQUIRED)
228endif() 190endif()
229 191
230# Attempt to locate any packages that are required and report the missing ones in CONAN_REQUIRED_LIBS
231yuzu_find_packages()
232
233# Qt5 requires that we find components, so it doesn't fit our pretty little find package function 192# Qt5 requires that we find components, so it doesn't fit our pretty little find package function
234if(ENABLE_QT) 193if(ENABLE_QT)
235 set(QT_VERSION 5.15) 194 set(QT_VERSION 5.15)
236 # We want to load the generated conan qt config so that we get the QT_ROOT var so that we can use the official
237 # Qt5Config inside the root folder instead of the conan generated one.
238 if(EXISTS ${CMAKE_BINARY_DIR}/qtConfig.cmake)
239 include(${CMAKE_BINARY_DIR}/qtConfig.cmake)
240 list(APPEND CMAKE_MODULE_PATH "${CONAN_QT_ROOT_RELEASE}")
241 list(APPEND CMAKE_PREFIX_PATH "${CONAN_QT_ROOT_RELEASE}")
242 endif()
243 195
244 # Check for system Qt on Linux, fallback to bundled Qt 196 # Check for system Qt on Linux, fallback to bundled Qt
245 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 197 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
246 if (NOT YUZU_USE_BUNDLED_QT) 198 if (NOT YUZU_USE_BUNDLED_QT)
247 find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets DBus) 199 find_package(Qt5 ${QT_VERSION} COMPONENTS Widgets DBus Multimedia)
248 endif() 200 endif()
249 if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT) 201 if (NOT Qt5_FOUND OR YUZU_USE_BUNDLED_QT)
250 # Check for dependencies, then enable bundled Qt download 202 # Check for dependencies, then enable bundled Qt download
@@ -330,9 +282,6 @@ if(ENABLE_QT)
330 282
331 set(YUZU_QT_NO_CMAKE_SYSTEM_PATH) 283 set(YUZU_QT_NO_CMAKE_SYSTEM_PATH)
332 284
333 # Workaround for an issue where conan tries to build Qt from scratch instead of download prebuilt binaries
334 set(QT_PREFIX_HINT)
335
336 if(YUZU_USE_BUNDLED_QT) 285 if(YUZU_USE_BUNDLED_QT)
337 if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64) 286 if ((MSVC_VERSION GREATER_EQUAL 1920 AND MSVC_VERSION LESS 1940) AND ARCHITECTURE_x86_64)
338 set(QT_BUILD qt-5.15.2-msvc2019_64) 287 set(QT_BUILD qt-5.15.2-msvc2019_64)
@@ -351,12 +300,12 @@ if(ENABLE_QT)
351 set(YUZU_QT_NO_CMAKE_SYSTEM_PATH "NO_CMAKE_SYSTEM_PATH") 300 set(YUZU_QT_NO_CMAKE_SYSTEM_PATH "NO_CMAKE_SYSTEM_PATH")
352 endif() 301 endif()
353 if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND YUZU_USE_BUNDLED_QT) 302 if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux") AND YUZU_USE_BUNDLED_QT)
354 find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets DBus ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH}) 303 find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent Multimedia DBus ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
355 else() 304 else()
356 find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH}) 305 find_package(Qt5 ${QT_VERSION} REQUIRED COMPONENTS Widgets Concurrent Multimedia ${QT_PREFIX_HINT} ${YUZU_QT_NO_CMAKE_SYSTEM_PATH})
357 endif() 306 endif()
358 if (YUZU_USE_QT_WEB_ENGINE) 307 if (YUZU_USE_QT_WEB_ENGINE)
359 find_package(Qt5 COMPONENTS WebEngineCore WebEngineWidgets) 308 find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets)
360 endif() 309 endif()
361 310
362 if (ENABLE_QT_TRANSLATION) 311 if (ENABLE_QT_TRANSLATION)
@@ -403,71 +352,8 @@ if (ENABLE_SDL2)
403 endif() 352 endif()
404endif() 353endif()
405 354
406# Install any missing dependencies with conan install 355# TODO(lat9nq): Determine what if any of this we still need
407if (CONAN_REQUIRED_LIBS) 356#
408 message(STATUS "Packages ${CONAN_REQUIRED_LIBS} not found!")
409 # Use Conan to fetch the libraries that aren't found
410 # Download conan.cmake automatically, you can also just copy the conan.cmake file
411 if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
412 message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
413 file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/release/0.18/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
414 endif()
415 include(${CMAKE_BINARY_DIR}/conan.cmake)
416
417 conan_check(VERSION 1.45.0 REQUIRED)
418
419 # Manually add iconv to fix a dep conflict between qt and sdl2
420 # We don't need to add it through find_package or anything since the other two can find it just fine
421 if ("${CONAN_REQUIRED_LIBS}" MATCHES "qt" AND "${CONAN_REQUIRED_LIBS}" MATCHES "sdl")
422 list(APPEND CONAN_REQUIRED_LIBS "libiconv/1.16")
423 endif()
424 if (IS_MULTI_CONFIG)
425 conan_cmake_run(REQUIRES ${CONAN_REQUIRED_LIBS}
426 OPTIONS ${CONAN_LIB_OPTIONS}
427 BUILD missing
428 CONFIGURATION_TYPES "Release;Debug"
429 GENERATORS cmake_multi cmake_find_package_multi)
430 include(${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake)
431 else()
432 conan_cmake_run(REQUIRES ${CONAN_REQUIRED_LIBS}
433 OPTIONS ${CONAN_LIB_OPTIONS}
434 BUILD missing
435 GENERATORS cmake cmake_find_package_multi)
436 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
437 endif()
438 list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
439 list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
440 conan_basic_setup()
441
442 set(YUZU_CONAN_INSTALLED TRUE CACHE BOOL "If true, the following builds will add conan to the lib search path" FORCE)
443
444 # Now that we've installed what we are missing, try to locate them again,
445 # this time with required, so we bail if its not found.
446 yuzu_find_packages(FORCE_REQUIRED)
447
448 if (NOT Boost_FOUND)
449 find_package(Boost 1.73.0 REQUIRED COMPONENTS context headers)
450 set(Boost_LIBRARIES Boost::boost)
451 # Conditionally add Boost::context only if the active version of the Conan Boost package provides it
452 # The old version is missing Boost::context, so we want to avoid adding in that case
453 # The new version requires adding Boost::context to prevent linking issues
454 if (TARGET Boost::context)
455 list(APPEND Boost_LIBRARIES Boost::context)
456 endif()
457 endif()
458
459 # Due to issues with variable scopes in functions, we need to also find_package(qt5) outside of the function
460 if(ENABLE_QT)
461 list(APPEND CMAKE_MODULE_PATH "${CONAN_QT_ROOT_RELEASE}")
462 list(APPEND CMAKE_PREFIX_PATH "${CONAN_QT_ROOT_RELEASE}")
463 find_package(Qt5 5.15 REQUIRED COMPONENTS Widgets)
464 if (YUZU_USE_QT_WEB_ENGINE)
465 find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets)
466 endif()
467 endif()
468
469endif()
470
471# Reexport some targets that are named differently when using the upstream CmakeConfig vs the generated Conan config 357# Reexport some targets that are named differently when using the upstream CmakeConfig vs the generated Conan config
472# In order to ALIAS targets to a new name, they first need to be IMPORTED_GLOBAL 358# In order to ALIAS targets to a new name, they first need to be IMPORTED_GLOBAL
473# Dynarmic checks for target `boost` and so we want to make sure it can find it through our system instead of using their external 359# Dynarmic checks for target `boost` and so we want to make sure it can find it through our system instead of using their external