crogine icon indicating copy to clipboard operation
crogine copied to clipboard

Building on macOS?

Open gingerbeardman opened this issue 2 years ago • 32 comments

  • Maybe I need to adjust my path or symlink something?
  • After this I can provide the macOS Apple silicon build :)
❯ cmake .
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
<FindSDL2.cmake>
</FindSDL2.cmake>
-- Found SDL2: /Users/matt/Library/Frameworks/SDL2.framework;-framework Cocoa  
-- Found Freetype: /Library/Frameworks/freetype.framework (found version "2.12.1") 
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework   
-- Found OpenAL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenAL.framework  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/matt/Downloads/2023-02-23/crogine-golf-v1.10.0
❯ make
[  0%] Building CXX object crogine/CMakeFiles/crogine.dir/src/audio/AudioBuffer.cpp.o
[  1%] Building CXX object crogine/CMakeFiles/crogine.dir/src/audio/AudioMixer.cpp.o
In file included from /Users/matt/Downloads/2023-02-23/crogine-golf-v1.10.0/crogine/src/audio/AudioMixer.cpp:30:
In file included from /Users/matt/Downloads/2023-02-23/crogine-golf-v1.10.0/crogine/include/crogine/core/App.hpp:34:
/Users/matt/Downloads/2023-02-23/crogine-golf-v1.10.0/crogine/include/crogine/core/Window.hpp:39:10: fatal error: 'SDL_atomic.h' file not found
#include <SDL_atomic.h>
         ^~~~~~~~~~~~~~
1 error generated.
make[2]: *** [crogine/CMakeFiles/crogine.dir/src/audio/AudioMixer.cpp.o] Error 1
make[1]: *** [crogine/CMakeFiles/crogine.dir/all] Error 2
make: *** [all] Error 2

gingerbeardman avatar Feb 23 '23 18:02 gingerbeardman

Solved!

  • I had old SDL2 in ~/Library/Frameworks
  • Deleting those
  • Now cmake found the up-to-date SDL2 at /Library/Frameworks
  • Progress!

gingerbeardman avatar Feb 23 '23 18:02 gingerbeardman

Next

❯ make
[  1%] Linking CXX shared library libcrogine.dylib
ld: warning: ignoring file /Library/Frameworks/freetype.framework/freetype, file is universal (x86_64,i386) but does not contain the arm64 architecture: /Library/Frameworks/freetype.framework/freetype

gingerbeardman avatar Feb 23 '23 18:02 gingerbeardman

Thanks for attempting this - macOS isn't really my area. Hitherto I've always installed all the external libs with brew and it's worked OK, but I've never attempted Apple Silicon or a universal binary. I'm led to believe brew installs are not universal.

fallahn avatar Feb 23 '23 18:02 fallahn

I checked and freetype is universal, so... did some more digging.

Found an old file at /Library/Frameworks/freetype.framework (why do I have all these ancient versions of frameworks!?)

And I've built it successfully!

[100%] Built target crogine

🥳

gingerbeardman avatar Feb 23 '23 18:02 gingerbeardman

Fantastic! 😁

fallahn avatar Feb 23 '23 18:02 fallahn

So, now I've built libcrogine.dylib, how do I "build" the rest of macOS app?

I figure I can save time by just asking 👍

gingerbeardman avatar Feb 23 '23 19:02 gingerbeardman

Have you seen macOS.md in the samples/golf folder? That has a run-down of building a bundle with cmake

fallahn avatar Feb 23 '23 19:02 fallahn

No, I had not 🔰

On it...

gingerbeardman avatar Feb 23 '23 19:02 gingerbeardman

It basically contains the full extent of my knowledge of building on macOS - I actually started writing it to remind myself how to do the existing builds each release... 😅

fallahn avatar Feb 23 '23 19:02 fallahn

So close!

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

note: Run script build phase 'Generate CMakeFiles/ALL_BUILD' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ALL_BUILD' from project 'golf')
note: Run script build phase 'CMake PostBuild Rules' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'install' from project 'golf')
** BUILD FAILED **


The following build commands failed:
	Ld /Users/matt/Downloads/2023-02-23/crogine-golf-v1.10.0/samples/golf/build/build/golf.build/Release/Objects-normal/x86_64/Binary/golf normal x86_64 (in target 'golf' from project 'golf')
(1 failure)

gingerbeardman avatar Feb 23 '23 19:02 gingerbeardman

Just to make sure, I'm doing:

cmake .. \
-D MACOS_BUNDLE=true \
-G Xcode \
-D CMAKE_C_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" \
-D CMAKE_CXX_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" \
-D CMAKE_OSX_ARCHITECTURES="arm64;x86_64"

and

sudo cmake --build . --config Release --target install

gingerbeardman avatar Feb 23 '23 20:02 gingerbeardman

I've never used

-D CMAKE_C_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" 
-D CMAKE_CXX_COMPILER="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" 

personally, I let cmake find the compiler itself. These lines were added by someone else working on a mac build.

symbol(s) not found for architecture x86_64

Sounds like it's building the arm version, but not the x86_64 version so it fails when linking. I've never tried this before, so there may be a missing step when telling xcode/clang to build. If you omit the architecture define from cmake it'll probably compile but you'll have an arm-only version (or it might fail trying to link to universal libraries 😅)

fallahn avatar Feb 23 '23 20:02 fallahn

Yeah, the feeling I get is that -D CMAKE_OSX_ARCHITECTURES="arm64;x86_64" is not enough for universal build.

I have just built Apple silicon only version using cmake .. -D MACOS_BUNDLE=true -G Xcode

I've run out of time but I'll circle back soon to try again for a Universal build. If your other Mac builder has any ideas, I'm all ears.

Also, it's possible to build these in the cloud (maybe even through GitHub actions) which may be something to look into once we have this all nailed down.

gingerbeardman avatar Feb 23 '23 20:02 gingerbeardman

Just added a quick change to macOS build doc, as #66

gingerbeardman avatar Feb 23 '23 21:02 gingerbeardman

For build script/instructions see https://github.com/fallahn/crogine/issues/68#issuecomment-1468782756

gingerbeardman avatar Mar 14 '23 22:03 gingerbeardman

Building 1.12.1 fails with the following error regarding MenuAvatars.cpp

Is this the llvm/clang issue you were referring to on Twitter?

** BUILD FAILED **


The following build commands failed:
	CompileC /Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/build/build/golf.build/Release/Objects-normal/arm64/MenuAvatars.o /Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'golf' from project 'golf')
(1 failure)

other possible errors from subsequent attempts

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: no LC_RPATH load command with path: /Library/Frameworks found in: /usr/local/lib/libcrogine.dylib (for architecture arm64), required for specified option "-delete_rpath /Library/Frameworks"

gingerbeardman avatar Apr 26 '23 14:04 gingerbeardman

My error was the lack of std::filesystem support - the actual error appears just before the ** BUILD FAILED ** line (and is missing from your post).

In hindsight this line in the CMake file is probably not helping (at least on newer versions of macOS). Increasing the value or outright omitting it may help with missing features.

fallahn avatar Apr 26 '23 14:04 fallahn

Sadly still the same "BUILD FAILED" error.

gingerbeardman avatar Apr 26 '23 21:04 gingerbeardman

You still haven't included the error message though 😁 The actual error will be further up the build output like this:

image

(this isn't the actual error, just one I, er, had laying around so to speak, as an example)

fallahn avatar Apr 27 '23 08:04 fallahn

LOL, sorry.

/Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:1650:26: error: 
      'remove_all' is unavailable: introduced in macOS 10.15
        std::filesystem::remove_all(path, ec);
                         ^
In file included from /Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:50:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/filesystem:2246:44: note: 
      'remove_all' has been explicitly marked unavailable here
inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
                                           ^
/Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:1650:37: error: 
      'path' is unavailable: introduced in macOS 10.15
        std::filesystem::remove_all(path, ec);
                                    ^
In file included from /Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:50:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/filesystem:948:3: note: 
      'path' has been explicitly marked unavailable here
  path(const _Source& __src, format = format::auto_format) {
  ^
/Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:1650:37: error: 
      '~path' is unavailable: introduced in macOS 10.15
        std::filesystem::remove_all(path, ec);
                                    ^
In file included from /Users/matt/Downloads/2023-04-26/crogine/crogine-golf-v1.12.1/samples/golf/src/golf/MenuAvatars.cpp:50:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/filesystem:968:3: note: 
      '~path' has been explicitly marked unavailable here
  ~path() = default;
  ^
3 warnings and 3 errors generated.

gingerbeardman avatar Apr 27 '23 10:04 gingerbeardman

Aha! Well that does explain what's going on - and is in fact the same lack of std::filesystem I suffer. Or rather, it has been suppressed because it wasn't introduced until 10.15, and we're apparently still trying to target below that.

This makes sense for me, because I'm still on 10.14 - however I'm not sure what's going on your end. If you modified the CMake file to target a higher version, it ought to work...

My best suggestion is: Check the CMake file for the crogine library, it may also have the 10.14 target line - and comment it out Double check the CMake file for golf and make sure the target line is commented out Do a complete clean - delete the build directories for both the library and golf, and create new ones Double check the XCode target - I think this was part of the configuration in macOS.md ? Make sure it's using a newer (or newest) version. Try rebuilding.

fallahn avatar Apr 27 '23 10:04 fallahn

D'oh! I had unzipped a fresh source and forgot to edit the CMake file again. Bumping it to 10.15 and it builds! I have updated my build script to automatically make that change.

BUT

I get a black screen rather than any 3D?

I'm using assets from from the latest Windows build.

Screen shot 2023-04-27 at 13 14 24

Screen shot 2023-04-27 at 13 15 26

gingerbeardman avatar Apr 27 '23 12:04 gingerbeardman

Well. This is progress I guess? :)

Looks like a shader failed to compile - are there any errors in the console window?

fallahn avatar Apr 27 '23 12:04 fallahn

image

gingerbeardman avatar Apr 27 '23 14:04 gingerbeardman

Hm, well that's a different (mac specific, but thankfully trivial) error, and shouldn't be causing this. You can try a debug build to increase verbosity, but the game itself will probably run like toffee :)

Although I do have a bit of a sinking feeling... could you try changing this line from

cro::RenderTarget::Context ctx(static_cast<std::uint32_t>(texSize.x), static_cast<std::uint32_t>(texSize.y), true, true, false, samples);

to

cro::RenderTarget::Context ctx(static_cast<std::uint32_t>(texSize.x), static_cast<std::uint32_t>(texSize.y), true, false, false, samples);

(the second true to false)?

fallahn avatar Apr 27 '23 14:04 fallahn

I can see!

So... what's going on?

Screen shot 2023-04-27 at 16 33 05

BUT

Screen shot 2023-04-27 at 16 34 25

gingerbeardman avatar Apr 27 '23 15:04 gingerbeardman

It's some groundwork I was doing for a future update involving weather - so not currently strictly necessary. To fix the latter you'll need to do the same thing on this line. (ie set it to false).

No idea how I'll debug this without a mac :(

fallahn avatar Apr 27 '23 15:04 fallahn

Changing that second line got things going in-game.

The only things I can suggest are macOS in a VM (if your Mac is capable of running newer but you're holding back, just install newer in a VM) or cloud renting a Mac for short periods (monthly?) or pick up a cheap old Mac (even 10 year old old laptops can run Catalina). Of course this is easy for me to suggest :)

gingerbeardman avatar Apr 27 '23 15:04 gingerbeardman

Hm. I've tried VMs on windows and they were slow as feh. It never occurred to me I could run a VM on the mac :)

I don't really like to mess with mine because actually it's just there to run the software for my DJ equipment. Building software on it was a kind of experiment which has since spiralled out of scope 🤦‍♀️

And there's no such thing as a cheap mac :P

fallahn avatar Apr 27 '23 18:04 fallahn

OK the build is working now on Sonoma (? whatever the latest is) with mac hardware. Except when built as a bundle it won't run with some codesigning error. Maybe you'll have some luck - use the 1.14.1 tag 👍

fallahn avatar Oct 07 '23 13:10 fallahn