Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on macOS? #65

Open
gingerbeardman opened this issue Feb 23, 2023 · 32 comments
Open

Building on macOS? #65

gingerbeardman opened this issue Feb 23, 2023 · 32 comments

Comments

@gingerbeardman
Copy link
Contributor

  • 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 gingerbeardman changed the title Building on macOS Building on macOS? Feb 23, 2023
@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

Solved!

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

@gingerbeardman
Copy link
Contributor Author

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

@fallahn
Copy link
Owner

fallahn commented Feb 23, 2023

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.

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

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

🥳

@fallahn
Copy link
Owner

fallahn commented Feb 23, 2023

Fantastic! 😁

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

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 👍

@fallahn
Copy link
Owner

fallahn commented Feb 23, 2023

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

@gingerbeardman
Copy link
Contributor Author

No, I had not 🔰

On it...

@fallahn
Copy link
Owner

fallahn commented Feb 23, 2023

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... 😅

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

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
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

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

@fallahn
Copy link
Owner

fallahn commented Feb 23, 2023

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 😅)

@gingerbeardman
Copy link
Contributor Author

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
Copy link
Contributor Author

gingerbeardman commented Feb 23, 2023

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

@gingerbeardman
Copy link
Contributor Author

For build script/instructions see #68 (comment)

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Apr 26, 2023

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"

@fallahn
Copy link
Owner

fallahn commented Apr 26, 2023

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.

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Apr 26, 2023

Sadly still the same "BUILD FAILED" error.

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

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)

@gingerbeardman
Copy link
Contributor Author

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.

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

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.

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Apr 27, 2023

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

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

Well. This is progress I guess? :)

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

@gingerbeardman
Copy link
Contributor Author

image

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

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)?

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Apr 27, 2023

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

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

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 :(

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Apr 27, 2023

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 :)

@fallahn
Copy link
Owner

fallahn commented Apr 27, 2023

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
Copy link
Owner

fallahn commented Oct 7, 2023

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 👍

@gingerbeardman
Copy link
Contributor Author

gingerbeardman commented Oct 7, 2023

I can only see 1.14 tag and it doesn't build

edit: ah i was looking at branches, will look into tags

[ 96%] Building CXX object CMakeFiles/crogine.dir/src/audio/OpenALImpl.cpp.o
error: error opening 'CMakeFiles/crogine.dir/src/audio/OpenALImpl.cpp.o.d': No such file or directory
1 error generated.
make[2]: *** [CMakeFiles/crogine.dir/src/audio/OpenALImpl.cpp.o] Error 1
make[1]: *** [CMakeFiles/crogine.dir/all] Error 2
make: *** [all] Error 2

@gingerbeardman
Copy link
Contributor Author

Hurrah!

Screen shot 2023-10-07 at 16 13 09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants