From 4fcda4bd56081f0f04f05bdec59710a586b11e32 Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 22 Jan 2022 16:23:25 +0100 Subject: [PATCH] Move CMake machinery to devkitPro CMake --- .github/workflows/ci.yml | 4 +- README.md | 64 ++++----- samples/cmake/CMakeLists.txt | 2 - .../cmake/custom_default_heap/CMakeLists.txt | 1 - samples/cmake/erreula/CMakeLists.txt | 1 - samples/cmake/gx2_triangle/CMakeLists.txt | 1 - samples/cmake/helloworld/CMakeLists.txt | 1 - samples/cmake/helloworld_cpp/CMakeLists.txt | 1 - samples/cmake/my_first_rpl/CMakeLists.txt | 1 - samples/cmake/swkbd/CMakeLists.txt | 1 - share/wut.cmake | 66 +-------- share/wut.toolchain.cmake | 128 +----------------- tests/CMakeLists.txt | 1 - .../CMakeLists.txt | 1 - .../CMakeLists.txt | 1 - .../CMakeLists.txt | 1 - 16 files changed, 40 insertions(+), 235 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f428d4f..922bdb97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: run: | cd tests mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/wut/share/wut.toolchain.cmake ../ + /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake ../ make -j2 - name: Build Samples (Make) @@ -39,5 +39,5 @@ jobs: run: | cd samples/cmake mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/wut/share/wut.toolchain.cmake ../ + /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake ../ make -j2 diff --git a/README.md b/README.md index b24dd85c..9e7325b1 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,63 @@ [![Build status](https://github.com/devkitPro/wut/workflows/C%2FC%2B%2B%20CI/badge.svg)](https://github.com/devkitPro/wut/actions?workflow=C%2FC%2B%2B+CI) # wut -Let's try make a Wii U Toolchain / SDK for creating rpx/rpl. +Let's try to make a Wii U Toolchain / SDK for creating rpx/rpl. Licensed under the terms of the GNU General Public License, version 2 or later (GPLv2+). ## Install -It is recommended to install wut by using the [devkitPro package manager](https://devkitpro.org/wiki/devkitPro_pacman) +It is recommended to follow [devkitPro's Getting Started guide](https://devkitpro.org/wiki/Getting_Started), +which will guide you through setting up a suitable homebrew development environment. +[devkitPro Pacman](https://devkitpro.org/wiki/devkitPro_pacman) is exclusively used to manage installed +homebrew development components. -For example you might do: +The following command installs all necessary packages for Wii U homebrew development, including wut: ``` -sudo dkp-pacman -Syu devkitPPC wut-tools wut +(sudo) (dkp-)pacman -Syu --needed wiiu-dev ``` ## Usage See [samples](samples) for examples of how to use wut. -The [share/wut.cmake](share/wut.cmake) file provides some helpers for your build: +devkitPro CMake provides some helpers for your build: - `wut_create_rpx(target)` - Will create an .rpx file from your CMake target generated by `add_executable` - `wut_create_rpl(target)` - Will create an .rpl file from your CMake target generated by `add_executable` - `wut_add_exports(target exports.def)` - Will add exports specified in exports.def for the given target -## Building from source -Requires: -- [devkitPPC](https://devkitpro.org/wiki/Getting_Started) -- [wut-tools](https://github.com/devkitPro/wut-tools) - -### Building with devkitPPC -Ensure you have the devkitPPC and wut-tools packages provided by [devkitPro](https://devkitpro.org/wiki/Getting_Started): -``` -sudo dkp-pacman -Syu devkitPPC wut-tools -export DEVKITPRO=/opt/devkitpro -export DEVKITPPC=/opt/devkitpro/devkitPPC -``` - -Then it's as simple as running make or make install: -``` -make -make install -``` - -### Building with a locally built wut-tools -If you have locally built wut-tools then just add the directory containing the built binaries to PATH and they should be used instead: -``` -export PATH=/path/to/wut-tools/bin:$PATH -make -``` - ## Building wut projects ### Building wut projects with make -Simply export the required variables and call make. +You can easily build any devkitPro Makefile based wut project with the following commands: ``` -export DEVKITPRO=/opt/devkitpro -export DEVKITPPC=/opt/devkitpro/devkitPPC +cd samples/make/helloworld make ``` ### Building wut projects with CMake -For any wut project you want to build with CMake you must use the wut.toolchain.cmake toolchain file: +You can easily build any devkitPro CMake based wut project with the following commands: ``` -export DEVKITPRO=/opt/devkitpro cd samples/cmake/helloworld mkdir build && cd build -cmake -DCMAKE_TOOLCHAIN_FILE=$DEVKITPRO/wut/share/wut.toolchain.cmake ../ +/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake ../ make ``` A minimal CMakeLists.txt file for a C++ project might look like: ``` -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.7) project(helloworld_cpp CXX) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(helloworld_cpp main.cpp) -wut_create_rpx(helloworld_cpp.rpx helloworld_cpp) +wut_create_rpx(helloworld_cpp) +``` + +## Building from source + +**It is strongly recommended to stick to stable released packages installed with devkitPro Pacman.** + +Building wut is simple as running the following commands: +``` +make +(sudo -E) make install ``` diff --git a/samples/cmake/CMakeLists.txt b/samples/cmake/CMakeLists.txt index 9b95e633..f308442a 100644 --- a/samples/cmake/CMakeLists.txt +++ b/samples/cmake/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.2) -set(CMAKE_TOOLCHAIN_FILE $ENV{DEVKITPRO}/wut/share/wut.toolchain.cmake) project(samples) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_subdirectory(custom_default_heap) add_subdirectory(erreula) diff --git a/samples/cmake/custom_default_heap/CMakeLists.txt b/samples/cmake/custom_default_heap/CMakeLists.txt index d4c2c5c6..c55e6d01 100644 --- a/samples/cmake/custom_default_heap/CMakeLists.txt +++ b/samples/cmake/custom_default_heap/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(custom_default_heap C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(custom_default_heap main.c) diff --git a/samples/cmake/erreula/CMakeLists.txt b/samples/cmake/erreula/CMakeLists.txt index 07186db7..27cd19ac 100644 --- a/samples/cmake/erreula/CMakeLists.txt +++ b/samples/cmake/erreula/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(erreula CXX) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(erreula main.cpp) diff --git a/samples/cmake/gx2_triangle/CMakeLists.txt b/samples/cmake/gx2_triangle/CMakeLists.txt index af2763c7..710a8c66 100644 --- a/samples/cmake/gx2_triangle/CMakeLists.txt +++ b/samples/cmake/gx2_triangle/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(gx2_triangle C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(gx2_triangle main.c) diff --git a/samples/cmake/helloworld/CMakeLists.txt b/samples/cmake/helloworld/CMakeLists.txt index 3040aeb0..2cb576e5 100644 --- a/samples/cmake/helloworld/CMakeLists.txt +++ b/samples/cmake/helloworld/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(helloworld C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(helloworld main.c) diff --git a/samples/cmake/helloworld_cpp/CMakeLists.txt b/samples/cmake/helloworld_cpp/CMakeLists.txt index e774ad96..805106e0 100644 --- a/samples/cmake/helloworld_cpp/CMakeLists.txt +++ b/samples/cmake/helloworld_cpp/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(helloworld_cpp CXX) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(helloworld_cpp main.cpp) diff --git a/samples/cmake/my_first_rpl/CMakeLists.txt b/samples/cmake/my_first_rpl/CMakeLists.txt index dc3f4479..dc205c86 100644 --- a/samples/cmake/my_first_rpl/CMakeLists.txt +++ b/samples/cmake/my_first_rpl/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(my_first_rpl C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(my_first_rpl my_first_rpl.c) wut_add_exports(my_first_rpl exports.def) diff --git a/samples/cmake/swkbd/CMakeLists.txt b/samples/cmake/swkbd/CMakeLists.txt index 4541ebe3..af619359 100644 --- a/samples/cmake/swkbd/CMakeLists.txt +++ b/samples/cmake/swkbd/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(swkbd CXX) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(swkbd main.cpp) diff --git a/share/wut.cmake b/share/wut.cmake index 7f1619a2..bb702e46 100644 --- a/share/wut.cmake +++ b/share/wut.cmake @@ -1,59 +1,7 @@ -cmake_minimum_required(VERSION 3.2) - -# Generates ${target}_exports.s from an exports file and adds it to the build -function(wut_add_exports target exports_file) - set(RPL_EXPORTS_FILE ${exports_file}) - if(NOT IS_ABSOLUTE ${exports_file}) - set(RPL_EXPORTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${exports_file}") - endif() - - set(RPL_EXPORT_GEN_OUTPUT ${target}_exports.s) - add_custom_command( - OUTPUT ${RPL_EXPORT_GEN_OUTPUT} - COMMAND ${WUT_RPLEXPORTGEN} ${RPL_EXPORTS_FILE} ${RPL_EXPORT_GEN_OUTPUT} - DEPENDS ${RPL_EXPORTS_FILE}) - target_sources(${target} PRIVATE ${RPL_EXPORT_GEN_OUTPUT}) - set_source_files_properties(${RPL_EXPORT_GEN_OUTPUT} PROPERTIES LANGUAGE C) - - set(RPL_IMPORT_GEN_OUTPUT ${target}_imports.s) - set(RPL_IMPORT_GEN_LD ${target}_imports.ld) - add_custom_command( - OUTPUT ${RPL_IMPORT_GEN_OUTPUT} ${RPL_IMPORT_GEN_LD} - COMMAND ${WUT_RPLIMPORTGEN} ${RPL_EXPORTS_FILE} ${RPL_IMPORT_GEN_OUTPUT} ${RPL_IMPORT_GEN_LD} - DEPENDS ${RPL_EXPORTS_FILE}) - set_source_files_properties(${RPL_IMPORT_GEN_OUTPUT} PROPERTIES LANGUAGE C) - add_library(${target}_imports STATIC ${RPL_IMPORT_GEN_OUTPUT}) - set_target_properties(${target}_imports PROPERTIES PREFIX "") - get_filename_component(RPL_IMPORT_LINKER_SCRIPT ${target}_imports.ld REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries(${target}_imports INTERFACE "-T${RPL_IMPORT_LINKER_SCRIPT}") -endfunction() - -function(wut_link_rpl target source) - target_link_libraries(${target} ${source}_imports) -endfunction() - -function(wut_create_rpl target) - set(RPL_OPTIONS IS_RPX) - set(RPL_SINGLE_ARGS "") - set(RPL_MULTI_ARGS "") - cmake_parse_arguments(RPL "${RPL_OPTIONS}" "${RPL_SINGLE_ARGS}" "${RPL_MULTI_ARGS}" "${ARGN}") - - if(RPL_IS_RPX) - # Do nothing - the defaults are good for RPX - set(RPL_SUFFIX "rpx") - else() - set(ELF2RPL_FLAGS ${ELF2RPL_FLAGS} --rpl) - set_property(TARGET ${target} APPEND_STRING PROPERTY - LINK_FLAGS "-specs=${WUT_ROOT}/share/rpl.specs") - set(RPL_SUFFIX "rpl") - endif() - - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_STRIP} -g $ - COMMAND ${WUT_ELF2RPL} ${ELF2RPL_FLAGS} $ $/${target}.${RPL_SUFFIX} - COMMENT "Creating ${target}.${RPL_SUFFIX}") -endfunction() - -function(wut_create_rpx) - wut_create_rpl(${ARGV} IS_RPX) -endfunction() +message(DEPRECATION + "The functionality provided by wut.cmake has moved to devkitPro CMake. " + "Please remove the corresponding include() in your CMakeLists.txt. " + "devkitPro CMake for Wii U can be invoked with the following wrapper script:\n" + "" + "/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake" +) diff --git a/share/wut.toolchain.cmake b/share/wut.toolchain.cmake index f2a9045c..5362dc4f 100644 --- a/share/wut.toolchain.cmake +++ b/share/wut.toolchain.cmake @@ -1,122 +1,8 @@ -cmake_minimum_required(VERSION 3.2) +message(DEPRECATION + "This toolchain file has been superseded by devkitPro CMake. " + "devkitPro CMake for Wii U can be invoked with the following wrapper script:\n" + "" + "/opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake" +) -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR "ppc") -set(CMAKE_CROSSCOMPILING 1) - -# Find DEVKITPRO -if(NOT DEFINED ENV{DEVKITPRO}) - message(FATAL_ERROR "You must have defined DEVKITPRO before calling cmake.") -endif() - -set(DEVKITPRO $ENV{DEVKITPRO}) - -if(NOT DEFINED ENV{DEVKITPPC}) - set(DEVKITPPC $ENV{DEVKITPRO}/devkitPPC) -else() - set(DEVKITPPC $ENV{DEVKITPPC}) -endif() - -if(NOT DEFINED ENV{WUT_ROOT}) - set(WUT_ROOT $ENV{DEVKITPRO}/wut) -else() - set(WUT_ROOT $ENV{WUT_ROOT}) -endif() - -# Setup root to exclude host system headers + libraries -set(CMAKE_FIND_ROOT_PATH - "${DEVKITPPC}" - "${DEVKITPPC}/powerpc-eabi" - "${DEVKITPRO}/tools" - "${DEVKITPRO}/portlibs/wiiu" - "${DEVKITPRO}/portlibs/ppc" - "${WUT_ROOT}/share") -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -# Set pkg-config for the same -find_program(PKG_CONFIG_EXECUTABLE NAMES powerpc-eabi-pkg-config HINTS "${DEVKITPRO}/portlibs/wiiu/bin") -if (NOT PKG_CONFIG_EXECUTABLE) - message(WARNING "Could not find powerpc-eabi-pkg-config: try installing wiiu-pkg-config") -endif() - -# Find compilers -find_program(DEVKITPPC_GCC NAMES powerpc-eabi-gcc HINTS "${DEVKITPPC}/bin") -if(NOT DEVKITPPC_GCC) - message(FATAL_ERROR "Could not find powerpc-eabi-gcc") -endif() - -find_program(DEVKITPPC_GPP NAMES powerpc-eabi-g++ HINTS "${DEVKITPPC}/bin") -if(NOT DEVKITPPC_GPP) - message(FATAL_ERROR "Could not find powerpc-eabi-g++") -endif() - -find_program(DEVKITPPC_LD NAMES powerpc-eabi-ld HINTS "${DEVKITPPC}/bin") -if(NOT DEVKITPPC_LD) - message(FATAL_ERROR "Could not find powerpc-eabi-ld") -endif() - -find_program(DEVKITPPC_AR NAMES powerpc-eabi-ar HINTS "${DEVKITPPC}/bin") -if(NOT DEVKITPPC_AR) - message(FATAL_ERROR "Could not find powerpc-eabi-ar") -endif() - -find_program(DEVKITPPC_STRIP NAMES powerpc-eabi-strip HINTS "${DEVKITPPC}/bin") -if(NOT DEVKITPPC_STRIP) - message(FATAL_ERROR "Could not find powerpc-eabi-strip") -endif() - -set(CMAKE_ASM_COMPILER "${DEVKITPPC_GCC}" CACHE PATH "") -set(CMAKE_C_COMPILER "${DEVKITPPC_GCC}" CACHE PATH "") -set(CMAKE_CXX_COMPILER "${DEVKITPPC_GPP}" CACHE PATH "") -set(CMAKE_LINKER "${DEVKITPPC_LD}" CACHE PATH "") -set(CMAKE_AR "${DEVKITPPC_AR}" CACHE PATH "") -set(CMAKE_STRIP "${DEVKITPPC_STRIP}" CACHE PATH "") - -set(WUT_C_FLAGS "-mcpu=750 -meabi -mhard-float -Wl,-q -D__WIIU__ -D__WUT__") -set(CMAKE_C_FLAGS "${WUT_C_FLAGS}" CACHE STRING "") -set(CMAKE_CXX_FLAGS "${WUT_C_FLAGS}" CACHE STRING "") -set(CMAKE_ASM_FLAGS "${WUT_C_FLAGS}" CACHE STRING "") -set(CMAKE_EXE_LINKER_FLAGS "\"-L${WUT_ROOT}/lib/stubs\" -specs=${WUT_ROOT}/share/wut.specs" CACHE STRING "") - -set(WUT_STANDARD_LIBRARIES "\"${WUT_ROOT}/lib/libwut.a\"") -set(CMAKE_C_STANDARD_LIBRARIES "${WUT_STANDARD_LIBRARIES}" CACHE STRING "") -set(CMAKE_CXX_STANDARD_LIBRARIES "${WUT_STANDARD_LIBRARIES}" CACHE STRING "") -set(CMAKE_ASM_STANDARD_LIBRARIES "${WUT_STANDARD_LIBRARIES}" CACHE STRING "") - -#for some reason cmake (3.14.3) doesn't appreciate having \" here -set(WUT_STANDARD_INCLUDE_DIRECTORIES "${WUT_ROOT}/include") -set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${WUT_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "") -set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "${WUT_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "") -set(CMAKE_ASM_STANDARD_INCLUDE_DIRECTORIES "${WUT_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "") - -# Find tools -find_program(ELF2RPL_BIN NAMES elf2rpl HINTS "${DEVKITPRO}/tools/bin") -if(NOT ELF2RPL_BIN) - message(FATAL_ERROR "Could not find elf2rpl") -endif() - -find_program(RPLEXPORTGEN_BIN NAMES rplexportgen HINTS "${DEVKITPRO}/tools/bin") -if(NOT RPLEXPORTGEN_BIN) - message(FATAL_ERROR "Could not find rplexportgen") -endif() - -find_program(RPLIMPORTGEN_BIN NAMES rplimportgen HINTS "${DEVKITPRO}/tools/bin") -if(NOT RPLIMPORTGEN_BIN) - message(FATAL_ERROR "Could not find rplimportgen") -endif() - -# Tools -set(WUT_ELF2RPL "${ELF2RPL_BIN}" CACHE PATH "") -set(WUT_RPLEXPORTGEN "${RPLEXPORTGEN_BIN}" CACHE PATH "") -set(WUT_RPLIMPORTGEN "${RPLIMPORTGEN_BIN}" CACHE PATH "") - -# Flags -set(WUT TRUE) -set(WIIU TRUE) - -# There is no shared lib support in devkitPPC -set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available") +include(/opt/devkitpro/cmake/WiiU.cmake) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2fbdef7d..b2e1f3f3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(tests) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) include_directories("test_compile_headers_common") add_subdirectory(test_compile_headers_as_c11) diff --git a/tests/test_compile_headers_as_c11/CMakeLists.txt b/tests/test_compile_headers_as_c11/CMakeLists.txt index dcd8acc9..92848d5a 100644 --- a/tests/test_compile_headers_as_c11/CMakeLists.txt +++ b/tests/test_compile_headers_as_c11/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(test_compile_headers_as_c11 C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) set(CMAKE_C_STANDARD 11) diff --git a/tests/test_compile_headers_as_c99/CMakeLists.txt b/tests/test_compile_headers_as_c99/CMakeLists.txt index 25cf08bb..1182228b 100644 --- a/tests/test_compile_headers_as_c99/CMakeLists.txt +++ b/tests/test_compile_headers_as_c99/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(test_compile_headers_as_c99 C) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) set(CMAKE_C_STANDARD 99) diff --git a/tests/test_compile_headers_as_cpp/CMakeLists.txt b/tests/test_compile_headers_as_cpp/CMakeLists.txt index 9131c846..72d3770e 100644 --- a/tests/test_compile_headers_as_cpp/CMakeLists.txt +++ b/tests/test_compile_headers_as_cpp/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.2) project(test_compile_headers_as_cpp CXX) -include("${DEVKITPRO}/wut/share/wut.cmake" REQUIRED) add_executable(test_compile_headers_as_cpp main.cpp)