From 32234609eaef2463be98e8fa7a41eaaa82a09987 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 3 Dec 2020 18:11:55 +0100 Subject: [PATCH 1/7] cmake: no indentation for closing cmake command parenthesis --- CMakeLists.txt | 6 +++--- skeleton/CMakeLists.txt | 14 +++++++------- skeleton/imgui/CMakeLists.txt | 10 +++++----- src/CMakeLists.txt | 34 ++++++++++++++++----------------- tools/dumprwtree/CMakeLists.txt | 8 ++++---- tools/imguitest/CMakeLists.txt | 6 +++--- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e4a246..3dd3a10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,15 +54,15 @@ if(LIBRW_INSTALL) include(CMakePackageConfigHelpers) configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}" - ) + ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/librw-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) + ) install( EXPORT librw-targets NAMESPACE librw:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) + ) set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics") set(CPACK_PACKAGE_VENDOR "aap") diff --git a/skeleton/CMakeLists.txt b/skeleton/CMakeLists.txt index 3c7aa16..98970bc 100644 --- a/skeleton/CMakeLists.txt +++ b/skeleton/CMakeLists.txt @@ -4,22 +4,22 @@ add_library(librw_skeleton skeleton.cpp skeleton.h win.cpp - ) +) set_target_properties(librw_skeleton PROPERTIES PREFIX "" - ) +) target_link_libraries(librw_skeleton PUBLIC librw - ) +) target_include_directories(librw_skeleton INTERFACE $ - ) +) if(NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL) add_subdirectory(imgui) @@ -29,13 +29,13 @@ if(LIBRW_INSTALL) target_include_directories(librw_skeleton INTERFACE $ - ) + ) install( FILES skeleton.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton" - ) + ) install( TARGETS librw_skeleton @@ -43,5 +43,5 @@ if(LIBRW_INSTALL) RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) + ) endif() diff --git a/skeleton/imgui/CMakeLists.txt b/skeleton/imgui/CMakeLists.txt index e61a7db..cb65dee 100644 --- a/skeleton/imgui/CMakeLists.txt +++ b/skeleton/imgui/CMakeLists.txt @@ -12,17 +12,17 @@ add_library(librw_skeleton_imgui stb_rect_pack.h stb_textedit.h stb_truetype.h - ) +) set_target_properties(librw_skeleton_imgui PROPERTIES PREFIX "" - ) +) target_link_libraries(librw_skeleton_imgui PUBLIC librw_skeleton - ) +) if(LIBRW_INSTALL) install( @@ -34,7 +34,7 @@ if(LIBRW_INSTALL) ImGuizmo.h stb_textedit.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/skeleton/imgui" - ) + ) install( TARGETS librw_skeleton_imgui @@ -42,5 +42,5 @@ if(LIBRW_INSTALL) RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) + ) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eff3469..f51c309 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,39 +91,39 @@ add_library(librw ps2/rwps2.h ps2/rwps2impl.h ps2/rwps2plg.h - ) +) add_library(librw::librw ALIAS librw) target_include_directories(librw INTERFACE $ - ) +) target_compile_definitions(librw PRIVATE "$,DEBUG,NDEBUG>" PUBLIC "RW_${LIBRW_PLATFORM}" - ) +) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") target_compile_options(librw PRIVATE "-Wall" - ) + ) if (NOT LIBRW_PLATFORM_PS2) target_compile_options(librw PRIVATE "-Wextra" "-Wdouble-promotion" "-Wpedantic" - ) + ) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(librw PUBLIC /wd4996 /wd4244 - ) + ) endif() set_target_properties(librw @@ -135,7 +135,7 @@ set_target_properties(librw CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON PREFIX "" - ) +) if(LIBRW_PLATFORM_GL3) @@ -149,7 +149,7 @@ if(LIBRW_PLATFORM_GL3) PUBLIC OpenGL::GL GLEW::GLEW - ) + ) if (LIBRW_GL3_GFXLIB STREQUAL "GLFW") find_package(glfw3 REQUIRED) target_link_libraries(librw @@ -162,7 +162,7 @@ if(LIBRW_PLATFORM_GL3) target_link_libraries(librw PUBLIC SDL2::SDL2 - ) + ) endif() endif() elseif(LIBRW_PLATFORM_D3D9) @@ -170,21 +170,21 @@ elseif(LIBRW_PLATFORM_D3D9) PUBLIC d3d9 xinput - ) + ) endif() if(LIBRW_INSTALL) target_include_directories(librw INTERFACE $ - ) + ) install( FILES "${PROJECT_SOURCE_DIR}/args.h" "${PROJECT_SOURCE_DIR}/rw.h" DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}" - ) + ) install( FILES base.err @@ -200,7 +200,7 @@ if(LIBRW_INSTALL) rwplugins.h rwuserdata.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src" - ) + ) install( FILES d3d/rwxbox.h @@ -208,20 +208,20 @@ if(LIBRW_INSTALL) d3d/rwd3d8.h d3d/rwd3d9.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/d3d" - ) + ) install( FILES ps2/rwps2.h ps2/rwps2plg.h DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/ps2" - ) + ) install( FILES gl/rwwdgl.h gl/rwgl3.h gl/rwgl3plg.h gl/rwgl3shader.h - DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/gl" + DESTINATION "${LIBRW_INSTALL_INCLUDEDIR}/src/gl" ) install( @@ -230,5 +230,5 @@ if(LIBRW_INSTALL) RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) + ) endif() diff --git a/tools/dumprwtree/CMakeLists.txt b/tools/dumprwtree/CMakeLists.txt index fffb737..b2c35bc 100644 --- a/tools/dumprwtree/CMakeLists.txt +++ b/tools/dumprwtree/CMakeLists.txt @@ -1,14 +1,14 @@ add_executable(dumprwtree - dumprwtree.cpp - ) + dumprwtree.cpp +) target_link_libraries(dumprwtree PUBLIC librw - ) +) if(LIBRW_INSTALL) install(TARGETS dumprwtree RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ) + ) endif() diff --git a/tools/imguitest/CMakeLists.txt b/tools/imguitest/CMakeLists.txt index 0cf413a..7cd5ed0 100644 --- a/tools/imguitest/CMakeLists.txt +++ b/tools/imguitest/CMakeLists.txt @@ -1,15 +1,15 @@ add_executable(imguitest WIN32 main.cpp - ) +) target_link_libraries(imguitest PUBLIC librw librw_skeleton_imgui - ) +) if(LIBRW_INSTALL) install(TARGETS imguitest RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ) + ) endif() From a5d31ade077c184d6f59de1f9e68cf023c2ff668 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Fri, 4 Dec 2020 02:02:06 +0100 Subject: [PATCH 2/7] librw+cmake: compile lodepng as pure C --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f51c309..2449599 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,6 +101,7 @@ target_include_directories(librw target_compile_definitions(librw PRIVATE + LODEPNG_NO_COMPILE_CPP "$,DEBUG,NDEBUG>" PUBLIC "RW_${LIBRW_PLATFORM}" From 7f0b98f9605282306e0ceea07bceba993976ed5e Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:35:23 +0100 Subject: [PATCH 3/7] cmake: remove double check for GL3 --- src/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2449599..7a05d6a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -138,9 +138,6 @@ set_target_properties(librw PREFIX "" ) -if(LIBRW_PLATFORM_GL3) - - if(LIBRW_PLATFORM_GL3) set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) @@ -165,7 +162,6 @@ if(LIBRW_PLATFORM_GL3) SDL2::SDL2 ) endif() -endif() elseif(LIBRW_PLATFORM_D3D9) target_link_libraries(librw PUBLIC From 4d260a631b515b468e6b8ea6e254fe495ef7b2e7 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:37:11 +0100 Subject: [PATCH 4/7] cmake: need SDL2main on Windows (and other platforms) + link to m on GNU/clang --- cmake/FindSDL2.cmake | 21 ++++++++++++++++----- src/CMakeLists.txt | 12 ++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake index cabb2d6..24288b4 100644 --- a/cmake/FindSDL2.cmake +++ b/cmake/FindSDL2.cmake @@ -1,16 +1,19 @@ find_package(PkgConfig QUIET) if(PKG_CONFIG_FOUND) pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2") - if(TARGET PkgConfig::SDL2 AND NOT TARGET sdl2::sdl2) - add_library(_sdl2 INTERFACE) - target_link_libraries(_sdl2 INTERFACE PkgConfig::SDL2) - add_library(SDL2::SDL2 ALIAS _sdl2) + if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 INTERFACE IMPORTED) + set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2) endif() endif() +find_library(SDL2main_LIBRARY SDL2main) + if(NOT SDL2_FOUND) find_path(SDL2_INCLUDE_DIR sdl2.h) - find_library(SDL2_LIBRARY sdl2) + find_library(SDL2_LIBRARY SDL2 SDL2d) + + find_library(SDL2main_LIBRARY SDL2main) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(libuv @@ -25,3 +28,11 @@ if(NOT SDL2_FOUND) ) endif() endif() + +if(SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main) + add_library(SDL2::SDL2main UNKNOWN IMPORTED) + set_target_properties(SDL2::SDL2main PROPERTIES + IMPORTED_LOCATION "${SDL2main_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a05d6a..aea9087 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -107,6 +107,12 @@ target_compile_definitions(librw "RW_${LIBRW_PLATFORM}" ) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_link_libraries(librw + PRIVATE + m + ) +endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") target_compile_options(librw PRIVATE @@ -161,6 +167,12 @@ if(LIBRW_PLATFORM_GL3) PUBLIC SDL2::SDL2 ) + if(TARGET SDL2::SDL2main) + target_link_libraries(librw + PUBLIC + SDL2::SDL2main + ) + endif() endif() elseif(LIBRW_PLATFORM_D3D9) target_link_libraries(librw From 1275b70e9dabe9bb329bcea547d5c9b4539b183b Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:40:59 +0100 Subject: [PATCH 5/7] cmake: add playstation2 support --- CMakeLists.txt | 4 -- cmake/ee.cmake | 2 - cmake/librw-config.cmake.in | 4 +- .../CMakeDSMCompiler.cmake.in | 0 .../CMakeDSMInformation.cmake | 0 .../CMakeDetermineDSMCompiler.cmake | 0 .../CMakeTestDSMCompiler.cmake | 0 .../ps2toolchain/Platform/PlayStation2.cmake | 1 + cmake/ps2toolchain/cmaketoolchain.cmake | 68 +++++++++++++++++++ cmake/ps2toolchain/conanfile.py | 21 ++++++ .../{ => ps2toolchain}/toolchain_ps2_ee.cmake | 48 ++++++------- conan/playstation2 | 12 ++++ tools/ps2test/CMakeLists.txt | 25 +++++++ 13 files changed, 151 insertions(+), 34 deletions(-) delete mode 100644 cmake/ee.cmake rename cmake/{ => ps2toolchain}/CMakeDSMCompiler.cmake.in (100%) rename cmake/{ => ps2toolchain}/CMakeDSMInformation.cmake (100%) rename cmake/{ => ps2toolchain}/CMakeDetermineDSMCompiler.cmake (100%) rename cmake/{ => ps2toolchain}/CMakeTestDSMCompiler.cmake (100%) create mode 100644 cmake/ps2toolchain/Platform/PlayStation2.cmake create mode 100644 cmake/ps2toolchain/cmaketoolchain.cmake create mode 100644 cmake/ps2toolchain/conanfile.py rename cmake/{ => ps2toolchain}/toolchain_ps2_ee.cmake (51%) create mode 100644 conan/playstation2 create mode 100644 tools/ps2test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd3a10..9985d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,6 @@ project(librw C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -if(PS2DEV AND EE) - include("${CMAKE_CURRENT_LIST_DIR}/cmake/ee.cmake") -endif() - if(WIN32) set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9") else() diff --git a/cmake/ee.cmake b/cmake/ee.cmake deleted file mode 100644 index 4a75ab2..0000000 --- a/cmake/ee.cmake +++ /dev/null @@ -1,2 +0,0 @@ -include_directories(SYSTEM "${PS2SDK}/common/include") -include_directories(SYSTEM "${PS2SDK}/ee/include") diff --git a/cmake/librw-config.cmake.in b/cmake/librw-config.cmake.in index 2cae87f..8fb8868 100644 --- a/cmake/librw-config.cmake.in +++ b/cmake/librw-config.cmake.in @@ -10,10 +10,10 @@ if(LIBRW_PLATFORM_GL3) set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) + find_package(GLEW REQUIRED) if(LIBRW_GL3_GFXLIB STREQUAL "GLFW") - find_package(GLEW REQUIRED) find_package(glfw3 REQUIRED) - elseif(LIBRW_GL3_GFXLIB STREQUAL "GLFW") + elseif(LIBRW_GL3_GFXLIB STREQUAL "SDL2") find_package(SDL2 REQUIRED) endif() endif() diff --git a/cmake/CMakeDSMCompiler.cmake.in b/cmake/ps2toolchain/CMakeDSMCompiler.cmake.in similarity index 100% rename from cmake/CMakeDSMCompiler.cmake.in rename to cmake/ps2toolchain/CMakeDSMCompiler.cmake.in diff --git a/cmake/CMakeDSMInformation.cmake b/cmake/ps2toolchain/CMakeDSMInformation.cmake similarity index 100% rename from cmake/CMakeDSMInformation.cmake rename to cmake/ps2toolchain/CMakeDSMInformation.cmake diff --git a/cmake/CMakeDetermineDSMCompiler.cmake b/cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake similarity index 100% rename from cmake/CMakeDetermineDSMCompiler.cmake rename to cmake/ps2toolchain/CMakeDetermineDSMCompiler.cmake diff --git a/cmake/CMakeTestDSMCompiler.cmake b/cmake/ps2toolchain/CMakeTestDSMCompiler.cmake similarity index 100% rename from cmake/CMakeTestDSMCompiler.cmake rename to cmake/ps2toolchain/CMakeTestDSMCompiler.cmake diff --git a/cmake/ps2toolchain/Platform/PlayStation2.cmake b/cmake/ps2toolchain/Platform/PlayStation2.cmake new file mode 100644 index 0000000..bd2995e --- /dev/null +++ b/cmake/ps2toolchain/Platform/PlayStation2.cmake @@ -0,0 +1 @@ +set(CMAKE_EXECUTABLE_SUFFIX ".elf") diff --git a/cmake/ps2toolchain/cmaketoolchain.cmake b/cmake/ps2toolchain/cmaketoolchain.cmake new file mode 100644 index 0000000..6f83c96 --- /dev/null +++ b/cmake/ps2toolchain/cmaketoolchain.cmake @@ -0,0 +1,68 @@ +cmake_minimum_required(VERSION 3.7) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +set(CMAKE_SYSTEM_NAME "PlayStation2") +set(CMAKE_SYSTEM_PROCESSOR "mipsel") +set(CMAKE_SYSTEM_VERSION 1) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +if(NOT DEFINED ENV{PS2DEV}) + message(FATAL_ERROR "Need environment variable PS2DEV set") +endif() +if(NOT DEFINED ENV{PS2SDK}) + message(FATAL_ERROR "Need environment variable PS2SDK set") +endif() +set(PS2DEV "$ENV{PS2DEV}") +set(PS2SDK "$ENV{PS2SDK}") + +if(NOT IS_DIRECTORY "${PS2DEV}") + message(FATAL_ERROR "PS2DEV must contain a folder path (${PS2DEV})") +endif() + +if(NOT IS_DIRECTORY "${PS2SDK}") + message(FATAL_ERROR "PS2SDK must contain a folder path (${PS2SDK})") +endif() + +set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm") + +set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc") +set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++") +set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++") +set(CMAKE_DSM_COMPILER "${PS2DEV}/dvp/bin/dvp-as") +set(CMAKE_AR "${PS2DEV}/ee/bin/ee-ar" CACHE FILEPATH "archiver") +set(CMAKE_LINKER "${PS2DEV}/ee/bin/ee-ld") +set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib") +set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip") + +set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d") + +set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee") +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(PS2 1) +set(EE 1) + +function(add_erl_executable OUTFILE TARGET) + get_property(output_dir TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY) + set(outfile "${output_dir}/${TARGET}.erl") + add_custom_command(OUTPUT "${outfile}" + COMMAND "${CMAKE_COMMAND}" -E copy "$" "${outfile}" + COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}" + DEPENDS ${TARGET} + ) + add_custom_target("${TARGET}_erl" ALL + DEPENDS "${outfile}" + ) + set("${OUTFILE}" "${outfile}" PARENT_SCOPE) +endfunction() diff --git a/cmake/ps2toolchain/conanfile.py b/cmake/ps2toolchain/conanfile.py new file mode 100644 index 0000000..11c8628 --- /dev/null +++ b/cmake/ps2toolchain/conanfile.py @@ -0,0 +1,21 @@ +from conans import ConanFile +import os +import shutil + + +class Ps2devCMakeToolchainConan(ConanFile): + name = "ps2dev-cmaketoolchain" + description = "CMake toolchain script for ps2dev" + topics = "ps2", "sdk", "library", "sony", "playstation", "ps2" + + def export_sources(self): + self.copy("*.cmake*", dst="cmake") + self.copy("Platform", dst="cmake") + + def package(self): + shutil.copytree(os.path.join(self.source_folder, "cmake"), + os.path.join(self.package_folder, "cmake")) + + def package_info(self): + self.user_info.cmake_dir = os.path.join(self.package_folder, "cmake").replace("\\", "/") + self.user_info.cmake_toolchain_file = os.path.join(self.package_folder, "cmake", "cmaketoolchain.cmake").replace("\\", "/") diff --git a/cmake/toolchain_ps2_ee.cmake b/cmake/ps2toolchain/toolchain_ps2_ee.cmake similarity index 51% rename from cmake/toolchain_ps2_ee.cmake rename to cmake/ps2toolchain/toolchain_ps2_ee.cmake index 1f28073..95517d0 100644 --- a/cmake/toolchain_ps2_ee.cmake +++ b/cmake/ps2toolchain/toolchain_ps2_ee.cmake @@ -1,7 +1,9 @@ +cmake_minimum_required(VERSION 3.7) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") -set(CMAKE_SYSTEM_NAME "Generic") -set(CMAKE_SYSTEM_PROCESSOR "ee") +set(CMAKE_SYSTEM_NAME "PlayStation2") +set(CMAKE_SYSTEM_PROCESSOR "mipsel") set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -19,13 +21,8 @@ endif() set(PS2DEV "$ENV{PS2DEV}") set(PS2SDK "$ENV{PS2SDK}") -#set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS "asm;dsm") - set(CMAKE_DSM_SOURCE_FILE_EXTENSIONS "dsm") -set(CMAKE_SHARED_LIBRARY_SUFFIX ".erl") -set(CMAKE_EXECUTABLE_SUFFIX ".elf") - set(CMAKE_C_COMPILER "${PS2DEV}/ee/bin/ee-gcc") set(CMAKE_CXX_COMPILER "${PS2DEV}/ee/bin/ee-g++") set(CMAKE_ASM_COMPILER "${PS2DEV}/ee/bin/ee-g++") @@ -35,25 +32,10 @@ set(CMAKE_LINKER "${PS2DEV}/ee/bin/ee-ld") set(CMAKE_RANLIB "${PS2DEV}/ee/bin/ee-ranlib" CACHE FILEPATH "ranlib") set(CMAKE_STRIP "${PS2DEV}/ee/bin/ee-strip" CACHE FILEPATH "strip") -set(EE_LDFLAGS "" CACHE STRING "EE linker flags") -set(EE_ASFLAGS "-G0" CACHE STRING "EE assembler flags") - -set(EE_CRT0 "${PS2SDK}/ee/startup/crt0.o" CACHE FILEPATH "EE crt0 file") -set_source_files_properties("${EE_CRT0}" PROPERTIES EXTERNAL_OBJECT ON) - -set(EE_LINKSCRIPT "${PS2SDK}/ee/startup/linkfile" CACHE FILEPATH "EE link script") - -#set(EE_CFLAGS " -nostdlib -fno-common -D_EE" CACHE STRING "EE C/CXX compiler flags") -set(EE_CFLAGS "-D_EE") -set(CMAKE_C_FLAGS_INIT "${EE_CFLAGS}") -set(CMAKE_CXX_FLAGS_INIT "${EE_CFLAGS}") -#set(CMAKE_ASM_FLAGS_INIT "${EE_CFLAGS}") - -set(CMAKE_C_CREATE_STATIC_LIBRARY " cru ") -set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${CMAKE_C_CREATE_STATIC_LIBRARY}") -set(CMAKE_ASM_CREATE_STATIC_LIBRARY "${CMAKE_C_CREATE_STATIC_LIBRARY}") - -set(CMAKE_EXE_LINKER_FLAGS_INIT "-mno-crt0 -T\"${PS2SDK}/ee/startup/linkfile\" \"${EE_CRT0}\" -L\"${PS2SDK}/ee/lib\"") +set(CMAKE_ASM_FLAGS_INIT "-G0 -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_C_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_CXX_FLAGS_INIT "-G0 -fno-common -I\"${PS2SDK}/ee/include\" -I\"${PS2SDK}/common/include\"") +set(CMAKE_EXE_LINKER_FLAGS_INIT "-G0 -L\"${PS2SDK}/ee/lib\" -Wl,-r -Wl,-d") set(CMAKE_FIND_ROOT_PATH "${PS2DEV}/ee;${PS2SDK}/ee") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) @@ -62,3 +44,17 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(PS2 1) set(EE 1) + +function(add_erl_executable OUTFILE TARGET) + get_property(output_dir TARGET ${TARGET} PROPERTY RUNTIME_OUTPUT_DIRECTORY) + set(outfile "${output_dir}/${TARGET}.erl") + add_custom_command(OUTPUT "${outfile}" + COMMAND "${CMAKE_COMMAND}" -E copy "$" "${outfile}" + COMMAND "${CMAKE_STRIP}" --strip-unneeded -R .mdebug.eabi64 -R .reginfo -R .comment "${outfile}" + DEPENDS ${TARGET} + ) + add_custom_target("${TARGET}_erl" ALL + DEPENDS "${outfile}" + ) + set("${OUTFILE}" "${outfile}" PARENT_SCOPE) +endfunction() diff --git a/conan/playstation2 b/conan/playstation2 new file mode 100644 index 0000000..ddad52b --- /dev/null +++ b/conan/playstation2 @@ -0,0 +1,12 @@ +[settings] +os=Playstation2 +arch=mips +compiler=gcc +compiler.version=3.2 +compiler.libcxx=libstdc++ +build_type=Release +[options] +librw:platform=ps2 +[build_requires] +ps2dev-ps2toolchain/unknown@madebr/testing +[env] diff --git a/tools/ps2test/CMakeLists.txt b/tools/ps2test/CMakeLists.txt new file mode 100644 index 0000000..9ed4260 --- /dev/null +++ b/tools/ps2test/CMakeLists.txt @@ -0,0 +1,25 @@ +add_executable(ps2test + gs.h + main.cpp + mem.h + ps2.h + vu/defaultpipe.dsm + vu/skinpipe.dsm +) + +target_link_libraries(ps2test + PUBLIC + librw + kernel +) + +add_erl_executable(PS2TEST_ERL ps2test) + +if(LIBRW_INSTALL) + install(TARGETS ps2test + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) + install(FILES "${PS2TEST_ERL}" + DESTINATION "${CMAKE_INSTALL_BINDIR}" + ) +endif() From 9c5b50536e548a31f7a25fefd2820cb481ba787b Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:43:34 +0100 Subject: [PATCH 6/7] cmake: create binary package with nice filename --- CMakeLists.txt | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9985d38..81d3a43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,54 @@ if(LIBRW_INSTALL) EXPORT librw-targets NAMESPACE librw:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) - set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}") + + string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}") + list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major) + + string(TOLOWER "${LIBRW_PLATFORM}" librw_platform) + set(compiler) + set(os) + if(NOT LIBRW_PLATFORM STREQUAL "PS2") + if(MSVC) + set(compiler "-msvc${MSVC_VERSION}") + elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(compiler "-gcc${cmake_c_compiler_version_major}") + elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(compiler "-clang${cmake_c_compiler_version_major}") + elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + set(compiler "-appleclang${cmake_c_compiler_version_major}") + else() + set(compiler "-UNK") + message(WARNING "Unknown compiler. Created cpack package will be wrong. (override using cpack -P)") + endif() + endif() + if(LIBRW_PLATFORM_NULL) + set(platform "-null") + elseif(LIBRW_PLATFORM_PS2) + set(platform "-ps2") + elseif(LIBRW_PLATFORM_GL3) + if(LIBRW_GL3_GFXLIB STREQUAL "GLFW") + set(platform "-gl3-glfw") + else() + set(platform "-gl3-sdl2") + endif() + elseif(LIBRW_PLATFORM_D3D9) + set(platform "-d3d9") + endif() + if(NOT LIBRW_PLATFORM_PS2) + if(WIN32) + set(os "-win") + elseif(APPLE) + set(os "-apple") + elseif(UNIX) + set(os "-linux") + else() + set(compiler "-UNK") + message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)") + endif() + endif() + + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${compiler}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics") set(CPACK_PACKAGE_VENDOR "aap") set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE") @@ -67,5 +114,6 @@ if(LIBRW_INSTALL) set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}") set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}") + set(CPACK_GENERATOR "TXZ") include(CPack) endif() From dd01289f38683c9f585f4bfa383dad73aa0a0ae7 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 2 Jan 2021 20:46:03 +0100 Subject: [PATCH 7/7] conan+ci: update --- .github/workflows/build-cmake-conan.yml | 59 ++++++++++++++++++++----- conanfile.py | 57 ++++++++++++++++++------ 2 files changed, 91 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build-cmake-conan.yml b/.github/workflows/build-cmake-conan.yml index a965b41..092e1a6 100644 --- a/.github/workflows/build-cmake-conan.yml +++ b/.github/workflows/build-cmake-conan.yml @@ -1,4 +1,4 @@ -name: Build using conan +name: Build using conan+cmake on: pull_request: push: @@ -10,18 +10,22 @@ jobs: matrix: os: [windows-latest, ubuntu-latest, macos-latest] platform: ['null', 'gl3', 'd3d9', 'ps2'] + gl3_gfxlib: ['glfw', 'sdl2'] exclude: - os: windows-latest platform: ps2 - os: ubuntu-latest platform: d3d9 - - os: ubuntu-latest - platform: ps2 # FIXME: add ps2toolchain conan package + ps2 profile - os: macos-latest platform: d3d9 - - os: macos-latest - platform: ps2 + - platform: 'null' + gl3_gfxlib: sdl2 + - platform: d3d9 + gl3_gfxlib: sdl2 + - platform: ps2 + gl3_gfxlib: sdl2 runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.platform == 'ps2' }} steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -30,17 +34,50 @@ jobs: - name: "Setup conan" run: | python -m pip install conan - conan user - conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan + conan config init conan config set log.print_run_commands=True - - name: "conan install (download/build dependencies)" + conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan + conan remote add madebr_ps2dev https://api.bintray.com/conan/madebr/ps2dev + - name: "Add os=Playstation2 + gcc.version=3.2 to .conan/settings.yml" + if: ${{ matrix.platform == 'ps2' }} + shell: python run: | - conan install ${{ github.workspace }} -if build -o platform=${{ matrix.platform }} --build missing + import os, yaml + settings_path = os.path.expanduser("~/.conan/settings.yml") + yml = yaml.safe_load(open(settings_path)) + yml["os"]["Playstation2"] = None + yml["compiler"]["gcc"]["version"].append("3.2") + yml["compiler"]["gcc"]["version"].sort() + yaml.safe_dump(yml, open(settings_path, "w")) + - name: "Create host profile" + shell: bash + run: | + if test "${{ matrix.platform }}" = "ps2"; then + cp conan/playstation2 host_profile + else + cp ~/.conan/profiles/default host_profile + fi + - name: "Export Playstation 2 CMake toolchain conan recipe" + run: | + conan export cmake/ps2toolchain ps2dev-cmaketoolchain/master@ + - name: "Download/build dependencies (conan install)" + run: | + conan install ${{ github.workspace }} librw/master@ -if build -o platform=${{ matrix.platform }} -o gl3_gfxlib=${{ matrix.gl3_gfxlib}} --build missing -pr:h ./host_profile -pr:b default env: CONAN_SYSREQUIRES_MODE: enabled - - name: "conan build (build librw)" + - name: "Build librw (conan build)" run: | conan build ${{ github.workspace }} -if build -bf build -pf package - - name: "conan package (package librw)" + - name: "Package librw (conan package)" run: | conan package ${{ github.workspace }} -if build -bf build -pf package + - name: "Create binary package (cpack)" + working-directory: ./build + run: | + cpack + - name: "Archive binary package (github artifacts)" + uses: actions/upload-artifact@v2 + with: + name: "${{ matrix.os }}-${{ matrix.platform }}" + path: build/*.tar.xz + if-no-files-found: error diff --git a/conanfile.py b/conanfile.py index a94167d..7279640 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,5 @@ from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration +from conans.errors import ConanException, ConanInvalidConfiguration import os import shutil import textwrap @@ -18,21 +18,39 @@ class LibrwConan(ConanFile): default_options = { "platform": "gl3", "gl3_gfxlib": "glfw", + "openal:with_external_libs": False, "sdl2:vulkan": False, "sdl2:opengl": True, - "sdl2:sdl2main": False, + "sdl2:sdl2main": True, } no_copy_source = True + @property + def _os_is_playstation2(self): + try: + return self.settings.os == "Playstation2" + except ConanException: + return False + def config_options(self): + if self._os_is_playstation2: + self.options.platform = "ps2" if self.settings.os == "Windows": self.options["sdl2"].directx = False def configure(self): if self.options.platform != "gl3": del self.options.gl3_gfxlib + + def validate(self): if self.options.platform == "d3d9" and self.settings.os != "Windows": raise ConanInvalidConfiguration("d3d9 can only be built for Windows") + if self.options.platform == "ps2": + if not self._os_is_playstation2: + raise ConanInvalidConfiguration("platform=ps2 is only valid for os=Playstation2") + else: + if self._os_is_playstation2: + raise ConanInvalidConfiguration("os=Playstation2 only supports platform=ps2") def requirements(self): if self.options.platform == "gl3": @@ -41,6 +59,10 @@ class LibrwConan(ConanFile): self.requires("glfw/3.3.2") elif self.options.gl3_gfxlib == "sdl2": self.requires("sdl2/2.0.12@bincrafters/stable") + elif self.options.platform == "ps2": + self.requires("ps2dev-ps2sdk/unknown@madebr/testing") + if self._os_is_playstation2: + self.requires("ps2dev-cmaketoolchain/{}".format(self.version)) def export_sources(self): for d in ("cmake", "skeleton", "src", "tools"): @@ -62,16 +84,17 @@ class LibrwConan(ConanFile): def build(self): if self.source_folder == self.build_folder: raise Exception("cannot build with source_folder == build_folder") - tools.save("Findglfw3.cmake", - textwrap.dedent( - """ - if(NOT TARGET glfw) - message(STATUS "Creating glfw TARGET") - add_library(glfw INTERFACE IMPORTED) - set_target_properties(glfw PROPERTIES - INTERFACE_LINK_LIBRARIES CONAN_PKG::glfw) #$) - endif() - """), append=True) + if self.options.platform == "gl3" and self.options.gl3_gfxlib == "glfw": + tools.save("Findglfw3.cmake", + textwrap.dedent( + """ + if(NOT TARGET glfw) + message(STATUS "Creating glfw TARGET") + add_library(glfw INTERFACE IMPORTED) + set_target_properties(glfw PROPERTIES + INTERFACE_LINK_LIBRARIES CONAN_PKG::glfw) + endif() + """), append=True) tools.save("CMakeLists.txt", textwrap.dedent( """ @@ -85,11 +108,17 @@ class LibrwConan(ConanFile): """).format(self.install_folder.replace("\\", "/"), self.source_folder.replace("\\", "/"))) cmake = CMake(self) + env = {} cmake.definitions["LIBRW_PLATFORM"] = self._librw_platform cmake.definitions["LIBRW_INSTALL"] = True + cmake.definitions["LIBRW_TOOLS"] = True if self.options.platform == "gl3": cmake.definitions["LIBRW_GL3_GFXLIB"] = str(self.options.gl3_gfxlib).upper() - cmake.configure(source_folder=self.build_folder) + if self._os_is_playstation2: + cmake.definitions["CMAKE_TOOLCHAIN_FILE"] = self.deps_user_info["ps2dev-cmaketoolchain"].cmake_toolchain_file + env["PS2SDK"] = self.deps_cpp_info["ps2dev-ps2sdk"].rootpath + with tools.environment_append(env): + cmake.configure(source_folder=self.build_folder) cmake.build() def package(self): @@ -98,7 +127,7 @@ class LibrwConan(ConanFile): def package_info(self): self.cpp_info.includedirs.append(os.path.join("include", "librw")) - self.cpp_info.libs = ["librw"] + self.cpp_info.libs = ["librw" if self.settings.compiler == "Visual Studio" else "rw"] if self.options.platform == "null": self.cpp_info.defines.append("RW_NULL") elif self.options.platform == "gl3":