Skip to content

Commit e647e6a

Browse files
committed
Deps: allow building dependencies using cmake
1 parent 6db638d commit e647e6a

6 files changed

Lines changed: 785 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Setting it to a range tells it that it supports the features on the newer
22
# versions as well, avoiding setting policies.
3-
cmake_minimum_required(VERSION 3.16...3.25)
3+
cmake_minimum_required(VERSION 3.5)
44

55
# Enabling this cmake policy gets rid of warnings regarding LTO.
66
cmake_policy(SET CMP0069 NEW)
77
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
88

9+
cmake_policy(SET CMP0083 NEW)
10+
set(CMAKE_POLICY_DEFAULT_CMP0083 NEW)
11+
912
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
1013
message(FATAL_ERROR "PCSX2 does not support in-tree builds. Please make a build directory that is not the PCSX2 source directory and generate your CMake project there using either `cmake -B build_directory` or by running cmake from the build directory.")
1114
endif()
@@ -36,6 +39,12 @@ detect_compiler()
3639
#-------------------------------------------------------------------------------
3740
# Include specific module
3841
include(BuildParameters)
42+
43+
# Build third-party dependencies
44+
if (BUILD_DEPENDENCIES)
45+
include(BuildDependencies)
46+
endif()
47+
3948
include(SearchForStuff)
4049

4150
# Must be done after SearchForStuff

cmake/BuildDependencies.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Build PCSX2 dependencies during the configure step.
2+
#
3+
# This is intentionally executed during CMake configure because
4+
# SearchForStuff.cmake uses find_package() during configure.
5+
6+
set(PCSX2_DEPS_PREFIX "${CMAKE_BINARY_DIR}/deps" CACHE PATH
7+
"Where PCSX2 dependencies are installed")
8+
9+
set(PCSX2_DEPS_JOBS "" CACHE STRING
10+
"Parallel jobs for dependency builds")
11+
12+
set(_deps_build "${CMAKE_BINARY_DIR}/deps-build")
13+
14+
set(_deps_args
15+
-DCMAKE_INSTALL_PREFIX=${PCSX2_DEPS_PREFIX}
16+
)
17+
18+
if(PCSX2_DEPS_JOBS)
19+
list(APPEND _deps_args -DNPROCS=${PCSX2_DEPS_JOBS})
20+
endif()
21+
22+
# Pass the parent toolchain/compiler configuration to the dependency build.
23+
foreach(_var
24+
CMAKE_TOOLCHAIN_FILE
25+
CMAKE_C_COMPILER
26+
CMAKE_CXX_COMPILER
27+
CMAKE_C_COMPILER_LAUNCHER
28+
CMAKE_CXX_COMPILER_LAUNCHER
29+
CMAKE_SYSROOT
30+
CMAKE_OSX_DEPLOYMENT_TARGET
31+
CMAKE_OSX_ARCHITECTURES
32+
ANDROID_ABI
33+
ANDROID_PLATFORM
34+
)
35+
if(DEFINED ${_var})
36+
list(APPEND _deps_args -D${_var}=${${_var}})
37+
endif()
38+
endforeach()
39+
40+
message(STATUS "")
41+
message(STATUS "Building PCSX2 dependencies into:")
42+
message(STATUS " ${PCSX2_DEPS_PREFIX}")
43+
message(STATUS "")
44+
45+
execute_process(
46+
COMMAND ${CMAKE_COMMAND}
47+
-S "${CMAKE_SOURCE_DIR}/pcsx2-deps"
48+
-B "${_deps_build}"
49+
-G "${CMAKE_GENERATOR}"
50+
${_deps_args}
51+
RESULT_VARIABLE _deps_result
52+
)
53+
54+
if(NOT _deps_result EQUAL 0)
55+
message(FATAL_ERROR
56+
"Configuring the PCSX2 dependency build failed (${_deps_result})")
57+
endif()
58+
59+
execute_process(
60+
COMMAND ${CMAKE_COMMAND}
61+
--build "${_deps_build}"
62+
--parallel
63+
RESULT_VARIABLE _deps_result
64+
)
65+
66+
if(NOT _deps_result EQUAL 0)
67+
message(FATAL_ERROR
68+
"Building the PCSX2 dependencies failed (${_deps_result})")
69+
endif()
70+
71+
# Make the freshly installed packages visible to SearchForStuff.cmake.
72+
list(PREPEND CMAKE_PREFIX_PATH "${PCSX2_DEPS_PREFIX}")
73+
74+
if(CMAKE_FIND_ROOT_PATH)
75+
list(PREPEND CMAKE_FIND_ROOT_PATH "${PCSX2_DEPS_PREFIX}")
76+
endif()

cmake/BuildParameters.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ option(USE_VTUNE "Plug VTUNE to profile GS JIT.")
1414
option(PACKAGE_MODE "Use this option to ease packaging of PCSX2 (developer/distribution option)")
1515
option(BUNDLE_EMOJI_FONT "Bundles Noto Color Emoji for systems whose system emoji font isn't usable by freetype" ON)
1616
option(POSITION_INDEPENDENT_CODE "Generate position-independent code. It is recommended that you leave this on." ON)
17+
option(BUILD_DEPENDENCIES "Enables building dependencies" OFF)
18+
19+
if(BUILD_DEPENDENCIES)
20+
option(BUILD_DEPENDENCIES_AS_SHARED_LIBS "Build dependencies as shared libraries" ON)
21+
else()
22+
set(BUILD_DEPENDENCIES_AS_SHARED_LIBS OFF)
23+
endif()
1724

1825
#-------------------------------------------------------------------------------
1926
# Graphical option

cmake/SearchForStuff.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ find_package(ZLIB REQUIRED) # v1.3, but Mac uses the SDK version.
1717
find_package(Zstd 1.5.5 REQUIRED)
1818
find_package(LZ4 REQUIRED)
1919
find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config.
20+
if((WIN32 AND NOT MSVC) OR ANDROID)
21+
find_library(SHARPYUV_LIBRARY NAMES sharpyuv REQUIRED)
22+
else()
23+
find_library(SHARPYUV_LIBRARY NAMES libsharpyuv.a sharpyuv.lib)
24+
if(NOT SHARPYUV_LIBRARY AND EXISTS "${CMAKE_BINARY_DIR}/deps/lib/libsharpyuv.a")
25+
set(SHARPYUV_LIBRARY "${CMAKE_BINARY_DIR}/deps/lib/libsharpyuv.a")
26+
endif()
27+
endif()
2028
find_package(SDL3 3.2.6 REQUIRED)
2129
find_package(Freetype 2.10 REQUIRED) # 2.10 is the first with COLRv0 support, which we need for rendering emoji
2230
find_package(plutovg 1.1.0 REQUIRED)

common/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ target_link_libraries(common PUBLIC
214214
ryml::ryml
215215
)
216216

217+
if(TARGET WebP::libwebp AND SHARPYUV_LIBRARY)
218+
target_link_libraries(common PRIVATE ${SHARPYUV_LIBRARY})
219+
endif()
220+
217221
fixup_file_properties(common)
218222
target_compile_features(common PUBLIC cxx_std_17)
219223
target_include_directories(common PUBLIC ../3rdparty/include ../)

0 commit comments

Comments
 (0)