Skip to content

Commit 9214267

Browse files
committed
add PS4 cmake toolchain
1 parent 4df9d00 commit 9214267

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

cmake/PS4.toolchain.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
set(triple "x86_64-scei-ps4")
2+
3+
set(CMAKE_C_COMPILER "clang")
4+
set(CMAKE_CXX_COMPILER "clang++")
5+
set(CMAKE_C_COMPILER_AR "ar")
6+
set(CMAKE_LINKER "clang")
7+
set(CMAKE_ASM_COMPILER "clang")
8+
set(CMAKE_FIND_ROOT_PATH "$ENV{PS4SDK}")
9+
set(CMAKE_SYSROOT "$ENV{PS4SDK}/usr")
10+
11+
set(CMAKE_C_COMPILER_TARGET "${triple}")
12+
set(CMAKE_CXX_COMPILER_TARGET "${triple}")
13+
14+
# only search for libraries and includes in the PS4SDK directory
15+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
16+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
17+
set(CMAKE_SKIP_RPATH true)
18+
19+
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <LINK_FLAGS> $ENV{PS4SDK}/crt0.s <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" CACHE STRING "")
20+
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" CACHE STRING "")
21+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -pedantic -m64 -mcmodel=large -ffreestanding -fPIE -fno-builtin -fno-stack-protector -D__PS4__" CACHE STRING "")
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -m64 -mcmodel=large -ffreestanding -fPIE -fno-stack-protector -D__PS4__" CACHE STRING "")
23+
set(CMAKE_EXE_LINKER_FLAGS "-O3 -Wall -m64 -pie -nostartfiles -nostdlib" CACHE STRING "")
24+
25+
link_directories("$ENV{PS4SDK}/lib")
26+
27+
set(TOOLCHAIN_PS4SDK_LIBS)
28+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_extension_kernel_execute_dynlib_prepare_dlclose Ps4_extension_kernel_call_standard)
29+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_common_kernel Ps4_common_user Ps4_common_generic)
30+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_common_generic)
31+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4LibCInternalAdaptive_stub Ps4LibKernelAdaptive_stub)
32+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS SceLibcInternal_stub kernel_stub)
33+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS ps4Kernel_stub)
34+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_base_stub_resolve_minimal)
35+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_base_kernel_dlsym_standard Ps4_base_kernel_seek_elf_address_standard)
36+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_base_assembler_register_parameter_standard)
37+
LIST(APPEND TOOLCHAIN_PS4SDK_LIBS Ps4_base_assembler_system_call_rop_0x93a4FFFF8)
38+
39+
40+
# this is a work around to avoid duplicate library warning,
41+
# as the toolchain file can be proccessed multiple times
42+
# people over cmake IRC suggest I move this to a find module
43+
# instead of messing with policies as they might be removed in time AKA TODO
44+
cmake_policy(SET CMP0002 OLD)
45+
46+
add_library(PS4LIBS INTERFACE)
47+
add_library(PS4::LIBS ALIAS PS4LIBS)
48+
target_link_libraries(PS4LIBS INTERFACE ${TOOLCHAIN_PS4SDK_LIBS})
49+
50+
add_library(PS4HEADERS INTERFACE)
51+
add_library(PS4::HEADERS ALIAS PS4HEADERS)
52+
target_include_directories(PS4HEADERS INTERFACE "$ENV{PS4SDK}/include/c++/v1/" "$ENV{PS4SDK}/include/" "$ENV{PS4SDK}/include/sce/" "$ENV{PS4SDK}/include/ps4/")
53+
unset(TOOLCHAIN_PS4SDK_LIBS)
54+
55+
cmake_policy(SET CMP0002 NEW)

0 commit comments

Comments
 (0)