Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Setting it to a range tells it that it supports the features on the newer
# versions as well, avoiding setting policies.
cmake_minimum_required(VERSION 3.16...3.25)
cmake_minimum_required(VERSION 3.5)

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

cmake_policy(SET CMP0083 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0083 NEW)

if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
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.")
endif()
Expand Down Expand Up @@ -36,6 +39,12 @@ detect_compiler()
#-------------------------------------------------------------------------------
# Include specific module
include(BuildParameters)

# Build third-party dependencies
if (BUILD_DEPENDENCIES)
include(BuildDependencies)
endif()

include(SearchForStuff)

# Must be done after SearchForStuff
Expand Down
76 changes: 76 additions & 0 deletions cmake/BuildDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Build PCSX2 dependencies during the configure step.
#
# This is intentionally executed during CMake configure because
# SearchForStuff.cmake uses find_package() during configure.

set(PCSX2_DEPS_PREFIX "${CMAKE_BINARY_DIR}/deps" CACHE PATH
"Where PCSX2 dependencies are installed")

set(PCSX2_DEPS_JOBS "" CACHE STRING
"Parallel jobs for dependency builds")

set(_deps_build "${CMAKE_BINARY_DIR}/deps-build")

set(_deps_args
-DCMAKE_INSTALL_PREFIX=${PCSX2_DEPS_PREFIX}
)

if(PCSX2_DEPS_JOBS)
list(APPEND _deps_args -DNPROCS=${PCSX2_DEPS_JOBS})
endif()

# Pass the parent toolchain/compiler configuration to the dependency build.
foreach(_var
CMAKE_TOOLCHAIN_FILE
CMAKE_C_COMPILER
CMAKE_CXX_COMPILER
CMAKE_C_COMPILER_LAUNCHER
CMAKE_CXX_COMPILER_LAUNCHER
CMAKE_SYSROOT
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_ARCHITECTURES
ANDROID_ABI
ANDROID_PLATFORM
)
if(DEFINED ${_var})
list(APPEND _deps_args -D${_var}=${${_var}})
endif()
endforeach()

message(STATUS "")
message(STATUS "Building PCSX2 dependencies into:")
message(STATUS " ${PCSX2_DEPS_PREFIX}")
message(STATUS "")

execute_process(
COMMAND ${CMAKE_COMMAND}
-S "${CMAKE_SOURCE_DIR}/pcsx2-deps"
-B "${_deps_build}"
-G "${CMAKE_GENERATOR}"
${_deps_args}
RESULT_VARIABLE _deps_result
)

if(NOT _deps_result EQUAL 0)
message(FATAL_ERROR
"Configuring the PCSX2 dependency build failed (${_deps_result})")
endif()

execute_process(
COMMAND ${CMAKE_COMMAND}
--build "${_deps_build}"
--parallel
RESULT_VARIABLE _deps_result
)

if(NOT _deps_result EQUAL 0)
message(FATAL_ERROR
"Building the PCSX2 dependencies failed (${_deps_result})")
endif()

# Make the freshly installed packages visible to SearchForStuff.cmake.
list(PREPEND CMAKE_PREFIX_PATH "${PCSX2_DEPS_PREFIX}")

if(CMAKE_FIND_ROOT_PATH)
list(PREPEND CMAKE_FIND_ROOT_PATH "${PCSX2_DEPS_PREFIX}")
endif()
7 changes: 7 additions & 0 deletions cmake/BuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ option(USE_VTUNE "Plug VTUNE to profile GS JIT.")
option(PACKAGE_MODE "Use this option to ease packaging of PCSX2 (developer/distribution option)")
option(BUNDLE_EMOJI_FONT "Bundles Noto Color Emoji for systems whose system emoji font isn't usable by freetype" ON)
option(POSITION_INDEPENDENT_CODE "Generate position-independent code. It is recommended that you leave this on." ON)
option(BUILD_DEPENDENCIES "Enables building dependencies" OFF)

if(BUILD_DEPENDENCIES)
option(BUILD_DEPENDENCIES_AS_SHARED_LIBS "Build dependencies as shared libraries" ON)
else()
set(BUILD_DEPENDENCIES_AS_SHARED_LIBS OFF)
endif()

#-------------------------------------------------------------------------------
# Graphical option
Expand Down
8 changes: 8 additions & 0 deletions cmake/SearchForStuff.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ find_package(ZLIB REQUIRED) # v1.3, but Mac uses the SDK version.
find_package(Zstd 1.5.5 REQUIRED)
find_package(LZ4 REQUIRED)
find_package(WebP REQUIRED) # v1.3.2, spews an error on Linux because no pkg-config.
if((WIN32 AND NOT MSVC) OR ANDROID)
find_library(SHARPYUV_LIBRARY NAMES sharpyuv REQUIRED)
else()
find_library(SHARPYUV_LIBRARY NAMES libsharpyuv.a sharpyuv.lib)
if(NOT SHARPYUV_LIBRARY AND EXISTS "${CMAKE_BINARY_DIR}/deps/lib/libsharpyuv.a")
set(SHARPYUV_LIBRARY "${CMAKE_BINARY_DIR}/deps/lib/libsharpyuv.a")
endif()
endif()
find_package(SDL3 3.2.6 REQUIRED)
find_package(Freetype 2.10 REQUIRED) # 2.10 is the first with COLRv0 support, which we need for rendering emoji
find_package(plutovg 1.1.0 REQUIRED)
Expand Down
4 changes: 4 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ target_link_libraries(common PUBLIC
ryml::ryml
)

if(TARGET WebP::libwebp AND SHARPYUV_LIBRARY)
target_link_libraries(common PRIVATE ${SHARPYUV_LIBRARY})
endif()

fixup_file_properties(common)
target_compile_features(common PUBLIC cxx_std_17)
target_include_directories(common PUBLIC ../3rdparty/include ../)
Expand Down
Loading
Loading