henricj / dunelegacy

GNU General Public License v2.0
27 stars 4 forks source link

Compiling on OSX #3

Open philippkeller opened 3 years ago

philippkeller commented 3 years ago

I tried to compile on OSX. in IDE/VC/vcpkg/build_vcpkg.sh I replacedtriplet with x64-osx, then the build_vcpkg.sh ran through successfully.

After installing ninja with brew install ninja this step also worked:

cmake -G Ninja -DCMAKE_BUILD_TYPE:STRING=Release -DVCPKG_TARGET_TRIPLET:STRING=x64-linux ../../..

But now I'm stuck at cmake --build . with this error:

../../../src/main.cpp:75:14: fatal error: 'MacFunctions.h' file not found

I did cp IDE/xCode/MacFunctions.* src/ in order to provide the header file and replaced

    #include <MacFunctions.h>

With

    #include "MacFunctions.h"

There might be a smarter way to solve this…? Anyway: this made this error go away, but now I'm stuck at these errors:

philipp:..d/x64-Release% cmake --build .
[1/176] Building CXX object src/CMakeFiles/dune.dir/Bullet.cpp.o
FAILED: src/CMakeFiles/dune.dir/Bullet.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DFMT_LOCALE -DNEED_DOUBLE_FROM_CHARS -DNEED_DOUBLE_TO_CHARS -DNEED_FLOAT_FROM_CHARS -DNEED_FLOAT_TO_CHARS -I../../../src/../include -I../../../src/../external/enet/include -I../../../external/digestpp/. -Iexternal/rectpack2D/include -isystem ../../../IDE/VC/vcpkg/vcpkg/installed/x64-osx/include -isystem ../../../IDE/VC/vcpkg/vcpkg/installed/x64-osx/include/SDL2 -O3 -DNDEBUG -flto=thin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -Winvalid-pch -Xclang -include-pch -Xclang /var/tmp/dunelegacy/out/build/x64-Release/src/CMakeFiles/dune.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /var/tmp/dunelegacy/out/build/x64-Release/src/CMakeFiles/dune.dir/cmake_pch.hxx -MD -MT src/CMakeFiles/dune.dir/Bullet.cpp.o -MF src/CMakeFiles/dune.dir/Bullet.cpp.o.d -o src/CMakeFiles/dune.dir/Bullet.cpp.o -c ../../../src/Bullet.cpp
../../../src/Bullet.cpp:299:32: error: non-constant-expression cannot be narrowed from type 'long' to 'int' in initializer list [-Wc++11-narrowing]
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                               ^~~~~~~~~~~~~~~~~~~~~~~~~
../../../src/Bullet.cpp:299:32: note: insert an explicit cast to silence this issue
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                               ^~~~~~~~~~~~~~~~~~~~~~~~~
                               static_cast<int>(        )
../../../src/Bullet.cpp:299:59: error: non-constant-expression cannot be narrowed from type 'long' to 'int' in initializer list [-Wc++11-narrowing]
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~
../../../src/Bullet.cpp:299:59: note: insert an explicit cast to silence this issue
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~
                                                          static_cast<int>(        )
../../../src/Bullet.cpp:299:86: error: non-constant-expression cannot be narrowed from type 'long' to 'int' in initializer list [-Wc++11-narrowing]
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                                                     ^~~~~~~~~~~~~~~~~~
../../../src/Bullet.cpp:299:86: note: insert an explicit cast to silence this issue
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                                                     ^~~~~~~~~~~~~~~~~~
                                                                                     static_cast<int>( )
../../../src/Bullet.cpp:299:106: error: non-constant-expression cannot be narrowed from type 'long' to 'int' in initializer list [-Wc++11-narrowing]
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                                                                         ^~~~~~~~~~~~~~~~~~
../../../src/Bullet.cpp:299:106: note: insert an explicit cast to silence this issue
        SDL_Rect scaled_source{lround(source.x * scaleX), lround(source.y * scaleY), lround(w * scaleX), lround(h * scaleY)};
                                                                                                         ^~~~~~~~~~~~~~~~~~
                                                                                                         static_cast<int>( )
4 errors generated.
[6/176] Building CXX object src/CMakeFiles/dunelegacy.dir/main.cpp.o
ninja: build stopped: subcommand failed.

Any idea what might be wrong? This is my c++ version:

philipp:..d/x64-Release% /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
henricj commented 3 years ago

I don't have a mac handy for testing, so I'm not surprised there are build issues. Those narrowing issues should be safe to silence with casts.

That said, one may want to omit the target triplet from the cmake command line. Alternately, "-DVCPKG_TARGET_TRIPLET:STRING=x64-osx" should be better than "x64-linux" (or, even "arm64-osx" if on an ARM64 mac).

henricj commented 6 months ago

The code now compiles on macOS, but it crashes during startup.