Need help building with CMake

Post Reply
User avatar
Whirvis
Posts: 3
Joined: Sun Dec 05, 2021 9:59 pm
Contact:

Need help building with CMake

Post by Whirvis » Tue Aug 16, 2022 3:10 am

Hey all! I'm new to developing using devkitPro. I'm trying to use CMake when building the triangle example found on GitHub. When using the Makefile which comes with the example, everything compiles normally. When trying to use CMake in the same environment with this script:

Code: Select all

cmake_minimum_required(VERSION 3.20)
include("$ENV{DEVKITPRO}/cmake/Wii.cmake")
project (WiiTest VERSION 1.0)
add_executable(WiiTest triangle.c)
I get the following error:

Code: Select all

$ cmake -S . -B build
-- The C compiler identification is GNU 12.1.0
-- The CXX compiler identification is GNU 12.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc.exe
-- Check for working C compiler: /opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc.exe - broken
CMake Error at /usr/share/cmake-3.23.2/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make.exe -f Makefile cmTC_c5e69/fast && /usr/bin/make  -f CMakeFiles/cmTC_c5e69.dir/build.make CMakeFiles/cmTC_c5e69.dir/build
    make[1]: Entering directory '/home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_c5e69.dir/testCCompiler.o
    /opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc.exe    -o CMakeFiles/cmTC_c5e69.dir/testCCompiler.o -c /home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_c5e69.exe
    /usr/bin/cmake.exe -E cmake_link_script CMakeFiles/cmTC_c5e69.dir/link.txt --verbose=1
    /opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc.exe CMakeFiles/cmTC_c5e69.dir/testCCompiler.o -o cmTC_c5e69.exe -Wl,--out-implib,libcmTC_c5e69.dll.a -Wl,--major-image-version,0,--minor-image-version,0
    c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/12.1.0/../../../../powerpc-eabi/bin/ld.exe: unrecognized option '--major-image-version'
    c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/12.1.0/../../../../powerpc-eabi/bin/ld.exe: use the --help option for usage information
    collect2.exe: error: ld returned 1 exit status
    make[1]: *** [CMakeFiles/cmTC_c5e69.dir/build.make:99: cmTC_c5e69.exe] Error 1
    make[1]: Leaving directory '/home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:127: cmTC_c5e69/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)


-- Configuring incomplete, errors occurred!
See also "/home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeOutput.log".
See also "/home/Trent/Desktop/wii-cmake/build/CMakeFiles/CMakeError.log".
My folder structure is the following:

Code: Select all

wii-cmake
 | -> build
 | -> CMakeLists.txt
 | -> triangle.c
I'm sure that I'm making a simple mistake here, but I haven't been able to figure it out after hours of troubleshooting. I've been searching the internet as well as the devkitPro files on my hard drive for clues. Any help on this issue I'm having would be greatly appreciated. Thank you!
Whirvis at your service!

User avatar
fincs
( ͡° ͜ʖ ͡°)
Posts: 94
Joined: Mon Jul 12, 2010 9:45 pm
Location: Seville, Spain
Contact:

Re: Need help building with CMake

Post by fincs » Sun Aug 21, 2022 2:02 pm

CMake toolchain files can't be used with include(), instead they should be passed from the command line as a special argument. We offer a wrapper script around cmake that automatically does this: /opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake.

After removing the extraneous include line, and adding the command to convert the raw elf file into a dol executable that can actually be loaded by the console, here's what the minimal CMakeLists.txt file looks like: (I also moved the source code file back into the source folder)

Code: Select all

cmake_minimum_required(VERSION 3.13)
project (WiiTest VERSION 1.0)

add_executable(WiiTest source/triangle.c)
ogc_create_dol(WiiTest)
Donate to devkitPro - help us stay alive!

User avatar
Whirvis
Posts: 3
Joined: Sun Dec 05, 2021 9:59 pm
Contact:

Re: Need help building with CMake

Post by Whirvis » Sat Aug 27, 2022 6:48 pm

fincs wrote: Sun Aug 21, 2022 2:02 pm CMake toolchain files can't be used with include(), instead they should be passed from the command line as a special argument. We offer a wrapper script around cmake that automatically does this: /opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake.

After removing the extraneous include line, and adding the command to convert the raw elf file into a dol executable that can actually be loaded by the console, here's what the minimal CMakeLists.txt file looks like: (I also moved the source code file back into the source folder)

Code: Select all

cmake_minimum_required(VERSION 3.13)
project (WiiTest VERSION 1.0)

add_executable(WiiTest source/triangle.c)
ogc_create_dol(WiiTest)
Hey fincs, thank you so much for the reply! This makes sense, however I'm unsure of how to pass the script as an argument like you say. Would I just run something like this?:

Code: Select all

cmake /opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S . -B build
Thank you!
Whirvis at your service!

User avatar
fincs
( ͡° ͜ʖ ͡°)
Posts: 94
Joined: Mon Jul 12, 2010 9:45 pm
Location: Seville, Spain
Contact:

Re: Need help building with CMake

Post by fincs » Sun Aug 28, 2022 11:35 am

You just need to execute it directly, like this, within the msys2 shell:

Code: Select all

/opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S . -B build
Donate to devkitPro - help us stay alive!

User avatar
Whirvis
Posts: 3
Joined: Sun Dec 05, 2021 9:59 pm
Contact:

Re: Need help building with CMake

Post by Whirvis » Wed Aug 31, 2022 1:19 am

fincs wrote: Sun Aug 28, 2022 11:35 am You just need to execute it directly, like this, within the msys2 shell:

Code: Select all

/opt/devkitpro/portlibs/wii/bin/powerpc-eabi-cmake -S . -B build
Ah! I understand now. Thank you for the help! :D
Whirvis at your service!

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests