Created
June 12, 2025 15:16
-
-
Save RevoluPowered/41e1fef3264722c0669bb151858a34ac to your computer and use it in GitHub Desktop.
cross compiling with osxcross, scons and cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OSXCross toolchain | |
# the name of the target operating system | |
set(CMAKE_SYSTEM_NAME Darwin) | |
set(TOOLCHAIN_PREFIX "${OSXCROSS_TARGET}") | |
set(CMAKE_C_COMPILER "${OSXCROSS_ROOT}/target/bin/${OSXCROSS_TARGET}-cc") | |
set(CMAKE_CXX_COMPILER "${OSXCROSS_ROOT}/target/bin/${OSXCROSS_TARGET}-c++") | |
# where is the target environment located | |
set(CMAKE_FIND_ROOT_PATH "${OSXCROSS_TOOLCHAIN}") | |
# adjust the default behavior of the FIND_XXX() commands: | |
# search programs in the host environment | |
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) | |
# search headers and libraries in the target environment | |
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) | |
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
osx_cross = "osxcross" in env # this is purely so later we can use this multiple times in my case I had multiple cmake builds to handle | |
if osx_cross: | |
root = os.environ.get("OSXCROSS_ROOT", "") | |
if env["arch"] == "arm64": | |
basecmd = root + "/target/bin/arm64-apple-" + env["osxcross_sdk"] + "-" | |
target_path = "arm64-apple-" + env["osxcross_sdk"] + "" | |
else: | |
basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-" | |
target_path = "x86_64-apple-" + env["osxcross_sdk"] + "" | |
toolchain_directory = root + "/target/" | |
cmake_commands += " -DCMAKE_TOOLCHAIN_FILE=/put/absolute/path/here/or/figure/out/relative/path/cross-compile-osxcross.cmake " | |
cmake_commands += " -DOSXCROSS_ROOT=" + root | |
extra_commands += " -DOSXCROSS_TARGET=" + target_path | |
extra_commands += " -DOSXCROSS_TOOLCHAIN=" + toolchain_directory | |
cmake_generate_command = "cmake -S {} -B {} -G {} {} -DCMAKE_BUILD_TYPE={} {}".format( | |
example_build, out_build_dir, cmake_generator_type, extra_commands, example_build_type, cmake_opts | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment