Skip to content

Commit

Permalink
Merge pull request #638 from Wolf3s/cmake_iop
Browse files Browse the repository at this point in the history
Add iop cmake and improve cmake system.
  • Loading branch information
fjtrujy authored Jul 1, 2024
2 parents e04f945 + dcaaf72 commit 5bdfbf9
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ $(PS2SDK)/common/include:
$(PS2SDK)/ports:
$(MKDIR) -p $(PS2SDK)/ports

$(PS2SDK)/ports_iop:
$(MKDIR) -p $(PS2SDK)/ports_iop

install: | release

release: | build
$(MAKE) release_base
$(MAKE) release-clean
$(MAKE) $(PS2SDK)/common/include
$(MAKE) $(PS2SDK)/ports
$(MAKE) $(PS2SDK)/ports_iop
$(MAKE) $(subdir_release)

release_base: | env_release_check
Expand Down
1 change: 1 addition & 0 deletions samples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ release-samples:
cp -f Makefile.eeglobal_cpp_sample $(SAMPLES_TARGET)/Makefile.eeglobal_cpp
cp -f Makefile.iopglobal_sample $(SAMPLES_TARGET)/Makefile.iopglobal
cp -f ps2dev.cmake $(SHARE_TARGET)/ps2dev.cmake
cp -f ps2dev_iop.cmake $(SHARE_TARGET)/ps2dev_iop.cmake

release-clean:
rm -f -r $(SAMPLES_TARGET)
Expand Down
43 changes: 36 additions & 7 deletions samples/ps2dev.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#
# CMake platform file for PS2 EE processor
#
# Copyright (C) 2009-2010 Mathias Lafeldt <[email protected]>
# Copyright (C) 2023 Francisco Javier Trujillo Mata <[email protected]>
# Copyright (C) 2024 André Guilherme <[email protected]>
# Copyright (C) 2024-Present PS2DEV Team
#


INCLUDE(CMakeForceCompiler)
if(DEFINED ENV{PS2SDK})
SET(PS2SDK $ENV{PS2SDK})
else()
message(FATAL_ERROR "The environment variable PS2SDK needs to be defined.")
endif()

if(DEFINED ENV{PS2DEV})
SET(PS2DEV $ENV{PS2DEV})
else()
Expand All @@ -7,20 +24,32 @@ endif()
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR mips)

SET(CMAKE_C_COMPILER mips64r5900el-ps2-elf-gcc)
SET(CMAKE_CXX_COMPILER mips64r5900el-ps2-elf-g++)
SET(CMAKE_C_FLAGS_INIT "-I$ENV{PS2SDK}/ee/include -I$ENV{PS2SDK}/common/include -I$ENV{PS2SDK}/ports/include -D_EE -DPS2 -D__PS2__ -O2 -G0")
SET(CMAKE_CXX_FLAGS_INIT "-I$ENV{PS2SDK}/ee/include -I$ENV{PS2SDK}/common/include -I$ENV{PS2SDK}/ports/include -D_EE -DPS2 -D__PS2__ -O2 -G0")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-T$ENV{PS2SDK}/ee/startup/linkfile -L$ENV{PS2SDK}/ee/lib -L$ENV{PS2DEV}/gsKit/lib -L$ENV{PS2SDK}/ports/lib -Wl,-zmax-page-size=128")
#SET(CMAKE_SHARED_LINKER_FLAGS_INIT "...")
#SET(CMAKE_STATIC_LINKER_FLAGS_CONFIG_INIT "...")
#SET(CMAKE_STATIC_LINKER_FLAGS_INIT "...")
SET(CMAKE_ASM_COMPILER mips64r5900el-ps2-elf-as)

SET(EE_CFLAGS "-I$ENV{PS2SDK}/ee/include -I$ENV{PS2SDK}/common/include -I$ENV{PS2SDK}/ports/include -D_EE -DPS2 -D__PS2__ -O2 -G0" CACHE STRING "EE C compiler flags" FORCE)
SET(EE_LDFLAGS "-L$ENV{PS2SDK}/ee/lib -L$ENV{PS2DEV}/gsKit/lib -L$ENV{PS2SDK}/ports/lib -Wl,-zmax-page-size=128 -T$ENV{PS2SDK}/ee/startup/linkfile" CACHE STRING "EE linker flags" FORCE)
SET(EE_ASFLAGS "-G0" CACHE STRING "EE assembler flags" FORCE)

SET(CMAKE_TARGET_INSTALL_PREFIX $ENV{PS2DEV}/ports)

SET(CMAKE_FIND_ROOT_PATH $ENV{PS2DEV} $ENV{PS2DEV}/ee $ENV{PS2DEV}/ee/ee $ENV{PS2SDK} $ENV{PS2SDK}/ports)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)

SET(CMAKE_C_FLAGS_INIT ${EE_CFLAGS})
SET(CMAKE_CXX_FLAGS_INIT ${EE_CFLAGS})
SET(CMAKE_EXE_LINKER_FLAGS_INIT ${EE_LDFLAGS})
SET(CMAKE_ASM_FLAGS_INIT ${EE_ASFLAGS})


SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-nostartfiles -Wl,-r -Wl,-d")

SET(PS2 TRUE)
SET(PLATFORM_PS2 TRUE)
SET(PS2 TRUE)
SET(EE TRUE)
82 changes: 82 additions & 0 deletions samples/ps2dev_iop.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#
# CMake platform file for PS2 IOP processor
#
# Copyright (C) 2009-2010 Mathias Lafeldt <[email protected]>
# Copyright (C) 2023 Francisco Javier Trujillo Mata <[email protected]>
# Copyright (C) 2024 André Guilherme <[email protected]>
# Copyright (C) 2024-Present PS2DEV Team
#

INCLUDE(CMakeForceCompiler)
if(DEFINED ENV{PS2SDK})
SET(PS2SDK $ENV{PS2SDK})
else()
message(FATAL_ERROR "The environment variable PS2SDK needs to be defined.")
endif()

if(DEFINED ENV{PS2DEV})
SET(PS2DEV $ENV{PS2DEV})
else()
message(FATAL_ERROR "The environment variable PS2DEV needs to be defined.")
endif()

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR mips)
SET(CMAKE_C_COMPILER mipsel-ps2-irx-gcc)
SET(CMAKE_CXX_COMPILER mipsel-ps2-irx-g++)
SET(CMAKE_ASM_COMPILER mipsel-ps2-irx-as)
SET(CMAKE_C_COMPILER_WORKS 1) #Hack by f0bes
SET(CMAKE_CXX_COMPILER_WORKS 1) #Hack by f0bes
SET(CMAKE_ASM_COMPILER_WORKS 1) #Hack by f0bes


#
# set arch flags depending on gcc version
#
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE IOP_CC_VERSION)

SET(IOP_ASFLAGS_TARGET "-mcpu=r3000")
INCLUDE_DIRECTORIES($ENV{PS2SDK}/iop/include $ENV{PS2SDK}/common/include $ENV{PS2SDK}/ports_iop/include)
ADD_DEFINITIONS(-D_IOP -DPS2 -D__PS2__)

SET(IOP_CFLAGS "${IOP_CFLAGS_TARGET} -O2 -G0 -fno-builtin" CACHE STRING "IOP C compiler flags" FORCE)
SET(IOP_LDFLAGS "${IOP_LDFLAGS_TARGET} -T$ENV{PS2SDK}/iop/startup/linkfile -L$ENV{PS2SDK}/iop/lib -L$ENV{PS2SDK}/ports_iop/lib -Wl,-zmax-page-size=128 -nostdlib -Os -Wall" CACHE STRING "IOP linker flags" FORCE)
SET(IOP_ASFLAGS "${IOP_ASFLAGS_TARGET} -EL -G0" CACHE STRING "IOP assembler flags" FORCE)

SET(CMAKE_C_FLAGS_INIT ${IOP_CFLAGS})
SET(CMAKE_CXX_FLAGS_INIT ${IOP_CFLAGS})
SET(CMAKE_EXE_LINKER_FLAGS_INIT ${IOP_LDFLAGS})
SET(CMAKE_ASM_FLAGS_INIT ${EE_ASFLAGS})

SET(CMAKE_TARGET_INSTALL_PREFIX $ENV{PS2DEV}/ports_iop)

SET(CMAKE_FIND_ROOT_PATH $ENV{PS2DEV} $ENV{PS2DEV}/iop $ENV{PS2DEV}/iop/iop $ENV{PS2SDK} $ENV{PS2SDK}/ports_iop)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)

FUNCTION(BUILD_IOP_IMPORTS out_f in_f)
ADD_CUSTOM_COMMAND(OUTPUT ${out_f}
COMMAND echo "#include \"irx_imports.h\"" > ${out_f}
COMMAND cat ${in_f} >> ${out_f}
DEPENDS ${in_f}
COMMENT "Creating ${out_f}" VERBATIM
)
ENDFUNCTION()

FUNCTION(BUILD_IOP_EXPORTS out_f in_f)
ADD_CUSTOM_COMMAND(OUTPUT ${out_f}
COMMAND echo "#include \"irx.h\"" > ${out_f}
COMMAND cat ${in_f} >> ${out_f}
DEPENDS ${in_f}
COMMENT "Creating ${out_f}" VERBATIM
)
ENDFUNCTION()

SET(PLATFORM_PS2 TRUE)
SET(IOP TRUE)
SET(PS2 TRUE)
19 changes: 19 additions & 0 deletions skeleton/iop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.10)

project(hello LANGUAGES C)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(IOP_BIN hello.irx)
SET(IOP_SRCS hello_exports.c hello_main.c exports.c imports.c)
SET(IOP_LIBS)

BUILD_IOP_EXPORTS(exports.c ${CMAKE_CURRENT_SOURCE_DIR}/exports.tab)
BUILD_IOP_IMPORTS(imports.c ${CMAKE_CURRENT_SOURCE_DIR}/imports.lst)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-builtin")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")

ADD_EXECUTABLE(${IOP_BIN} ${IOP_SRCS})

ADD_CUSTOM_COMMAND(TARGET ${IOP_BIN} POST_BUILD COMMAND md5sum ARGS ${IOP_BIN})

0 comments on commit 5bdfbf9

Please sign in to comment.