Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of adding cmake toolchain support #268

Open
raphaelthegreat opened this issue Dec 31, 2024 · 4 comments
Open

Possibility of adding cmake toolchain support #268

raphaelthegreat opened this issue Dec 31, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@raphaelthegreat
Copy link

At the moment building the toolchain is not simple for average developer, or at least doesn't seem to be. On linux specifically the build.sh script doesn't seem to work correctly, a lot of paths are not local to the build directory and some files appear to be missing. Following the github workflow file is a little more promising, tho more modern linux distributions have issues with the pre-compiled PkgTool binaries.

This made me interested in the possibility of adding a proper cmake script for building entire toolchain and dependencies in a single go. It should also make prototyping sample projects simpler compared to current solution. I wonder if there would be any interest in this

@raphaelthegreat
Copy link
Author

Pinging @kiwidoggie

@kiwidoggie
Copy link
Contributor

There isn't much interest in updating the current toolchain with cmake support. There is a new replacement in the works that is using CMake all up. I'm very much aware (and annoyed) of the inconsistencies of the current toolchain, but I also don't feel like putting much effort into something that will be replaced. If you would want to assist on the new toolchain, there's a multitude of things that need to be done. feel free to join the discord.

That being said, here's a toolchain file that I've been using in Mira to compile OOSDK stuff

# Default cmake version
cmake_minimum_required(VERSION 3.12)

# Enable verbose makefile
set(CMAKE_VERBOSE_MAKEFILE OFF)

# Set the target configuration, credits znullptr & specter
set(CMAKE_SYSTEM_NAME FreeBSD)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_SYSTEM_VERSION 12)
set(TARGET x86_64-pc-freebsd-elf)

# Check to see if the OO_PS4_TOOLCHAIN environment variable exists
if(DEFINED ENV{OO_PS4_TOOLCHAIN})
    set(OO_PS4_TOOLCHAIN $ENV{OO_PS4_TOOLCHAIN})
else()
    message(FATAL "OO_PS4_TOOLCHAIN environment variable not found")
endif()

LIST(APPEND CMAKE_PROGRAM_PATH ${OO_PS4_TOOLCHAIN})

# Specify the cross compiler
# The target triple needs to match the prefix of the binutils exactly
# (e.g. CMake looks for arm-none-eabi-ar)
set(CLANG_TARGET_TRIPLE x86_64-pc-freebsd-elf)

# C Compiler
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})


# C++ Compiler
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})

# ASM Compiler
set(CMAKE_ASM_COMPILER /usr/bin/clang)
set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})

set(CMAKE_CXX_COMPILER_AR /usr/bin/llvm-ar)

# Don't run the linker on compiler check
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# Specify compiler flags
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(ARCH_FLAGS "-funwind-tables -fPIC -fvisibility=default -fshort-wchar")
set(CMAKE_C_FLAGS "-Wall -std=c11 ${ARCH_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wall -std=c++17  ${ARCH_FLAGS}")
set(CMAKE_ASM_FLAGS "-Wall ${ARCH_FLAGS} -x assembler-with-cpp")

# Specify linker flags
#add_link_options(-T ${OO_PS4_TOOLCHAIN}/link.x)
#add_link_options(-L${OO_PS4_TOOLCHAIN}/lib)
#add_link_options(--eh-frame-hdr)

set(CMAKE_EXE_LINKER_FLAGS "-m elf_x86_64 -pie --script ${OO_PS4_TOOLCHAIN}/link.x --eh-frame-hdr -L${OO_PS4_TOOLCHAIN}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "-m elf_x86_64 -shared --script ${OO_PS4_TOOLCHAIN}/link.x --eh-frame-hdr -L${OO_PS4_TOOLCHAIN}/lib")
#set(CMAKE_STATIC_LINKER_FLAGS "-m elf_x86_64 -pie --script ${OO_PS4_TOOLCHAIN}/link.x --eh-frame-hdr -L${OO_PS4_TOOLCHAIN}/lib")
set(CMAKE_MODULE_LINKER_FLAGS "-m elf_x86_64 -pie --script ${OO_PS4_TOOLCHAIN}/link.x --eh-frame-hdr -L${OO_PS4_TOOLCHAIN}/lib")
set(CMAKE_CXX_LINK_EXECUTABLE "ld.lld <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE "ld.lld <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "ld.lld <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_C_CREATE_SHARED_LIBRARY "ld.lld <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")

# C/C++ toolchain
set(CMAKE_SYSROOT "${OO_PS4_TOOLCHAIN}")
set(CMAKE_FIND_ROOT_PATH ${GCC_ARM_SYSROOT})

# Set default include directories
include_directories(SYSTEM ${OO_PS4_TOOLCHAIN}/include ${OO_PS4_TOOLCHAIN}/include/c++/v1)

# Set default library directories
# NOTE: We do not use this, because it passes the clang/clang++ -Wl,rpath=/lib instead of just plain -L/lib
# it is taken care of above in the CMAKE_EXE_LINKER_FLAGS
#link_directories(${OO_PS4_TOOLCHAIN}/lib)

# Add C compiler definitions
add_compile_definitions(PS4=1 __BSD_VISIBLE=1 _BSD_SOURCE=1)

# If we are compiling for debug mode enable the flag
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_definitions(_DEBUG=1)
endif()

# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)

# For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

@kiwidoggie kiwidoggie added the enhancement New feature or request label Jan 2, 2025
@raphaelthegreat
Copy link
Author

raphaelthegreat commented Jan 2, 2025

Thanks for the response, do you have a link to the discord? (nvm found it) I would be interested in following the development and helping out

@kiwidoggie
Copy link
Contributor

Word send me a dm when you get there and I'll explain what all needs doing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants