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

Add support for macOS #16

Open
aaronfranke opened this issue Jul 7, 2022 · 3 comments
Open

Add support for macOS #16

aaronfranke opened this issue Jul 7, 2022 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@aaronfranke
Copy link

When I try to compile GodotPckTool using make on macOS, I get this output:

% make
cd build && cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/aaronfranke/workspace/GodotPckTool/build
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C build
Consolidate compiler generated dependencies of target pck
[ 16%] Building CXX object src/CMakeFiles/pck.dir/PckTool.cpp.o
[ 33%] Building CXX object src/CMakeFiles/pck.dir/FileFilter.cpp.o
[ 50%] Linking CXX static library libpck.a
[ 66%] Built target pck
[ 83%] Building CXX object src/CMakeFiles/godotpcktool.dir/main.cpp.o
[100%] Linking CXX executable godotpcktool
clang: error: invalid linker name in argument '-fuse-ld=gold'
clang: error: unsupported option '-static-libgcc'
make[3]: *** [src/godotpcktool] Error 1
make[2]: *** [src/CMakeFiles/godotpcktool.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [compile] Error 2

I'm not familiar with CMake, so I'm not sure how to add support for macOS. But I would greatly appreciate it, it would be useful to have when trying to debug a Mac build of my Godot project.

@hhyyrylainen hhyyrylainen added the enhancement New feature or request label Jul 7, 2022
@hhyyrylainen
Copy link
Owner

Getting things compiling should be relatively easy by detecting apple platform in cmake and then not using the Linux specific flags.
Just saying if someone wants to give this a go, as I have currently no need myself to get this working on mac.

@april
Copy link

april commented Aug 5, 2022

You can use -fuse-ld=ld and drop the two static arguments and it builds fine for me on macOS.

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,7 +20,7 @@ add_executable(godotpcktool main.cpp)
 target_link_libraries(godotpcktool PRIVATE pck)

 # Static standard lib
-target_link_libraries(godotpcktool PRIVATE -static-libgcc -static-libstdc++)
+target_link_libraries(godotpcktool PRIVATE)

 # Fully static executable
 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
@@ -28,7 +28,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
 endif()

 if(NOT WIN32)
-  set_target_properties(godotpcktool PROPERTIES LINK_FLAGS_RELEASE "-s -fuse-ld=gold")
+  set_target_properties(godotpcktool PROPERTIES LINK_FLAGS_RELEASE "-s -fuse-ld=ld")
 else()
   set_target_properties(godotpcktool PROPERTIES LINK_FLAGS_RELEASE "-s")
 endif()

@chrismessina
Copy link

chrismessina commented Sep 19, 2024

For anyone on Mac coming later, I was able to compile on macOS Sequoia by following these steps:

  1. Download the repo archive.
  2. Download and unzip the dependencies into the corresponding ./third_party directories (MD5, JSON, cxxopts).
  3. Edit the ./src/CMakeLists.txt file to contain this text (I used @april's changes above, but it was a little tricky to read)
include(CheckIPOSupported)

add_library(pck
  pck/PckFile.h pck/PckFile.cpp
  PckTool.h PckTool.cpp
  FileFilter.h FileFilter.cpp
  "${PROJECT_BINARY_DIR}/Include.h" Define.h
  )

target_link_libraries(pck PUBLIC)
target_link_libraries(pck PRIVATE md5)

set_target_properties(pck PROPERTIES
  CXX_STANDARD 17
  CXX_EXTENSIONS OFF
  )


add_executable(godotpcktool main.cpp)

target_link_libraries(godotpcktool PRIVATE pck)

# Static standard lib
target_link_libraries(godotpcktool PRIVATE)

# Fully static executable
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  target_link_libraries(godotpcktool PRIVATE -static)
endif()

if(NOT WIN32)
  set_target_properties(godotpcktool PROPERTIES LINK_FLAGS_RELEASE "-s -fuse-ld=ld")
else()
  set_target_properties(godotpcktool PROPERTIES LINK_FLAGS_RELEASE "-s")
endif()

set_target_properties(godotpcktool PROPERTIES
  CXX_STANDARD 17
  CXX_EXTENSIONS OFF
  )

check_ipo_supported(RESULT result)
if(result)
  set_target_properties(godotpcktool PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

install(TARGETS godotpcktool)
  1. Open the directory in terminal and run make

This process ended up working for me (after hours of struggling!):

-- The C compiler identification is AppleClang 16.0.0.16000026
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/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: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/messina/Downloads/GodotPckTool/build
[ 12%] Building CXX object third_party/CMakeFiles/md5.dir/MD5/src/md5.cpp.o
[ 25%] Linking CXX static library libmd5.a
[ 25%] Built target md5
[ 37%] Building CXX object src/CMakeFiles/pck.dir/pck/PckFile.cpp.o
[ 50%] Building CXX object src/CMakeFiles/pck.dir/PckTool.cpp.o
[ 62%] Building CXX object src/CMakeFiles/pck.dir/FileFilter.cpp.o
[ 75%] Linking CXX static library libpck.a
[ 75%] Built target pck
[ 87%] Building CXX object src/CMakeFiles/godotpcktool.dir/main.cpp.o
[100%] Linking CXX executable godotpcktool
ld: warning: -s is obsolete
[100%] Built target godotpcktool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants