11cmake_minimum_required (VERSION 3.21 )
2+
3+ # Set C++ standard to 20 for compatibility with Geode's {fmt}
24set (CMAKE_CXX_STANDARD 20)
35set (CMAKE_CXX_STANDARD_REQUIRED ON )
4- if ("${CMAKE_SYSTEM_NAME} " STREQUAL "iOS" OR IOS )
5- set (CMAKE_OSX_ARCHITECTURES "arm64" )
6- else ()
7- set (CMAKE_OSX_ARCHITECTURES "arm64;x86_64" )
6+
7+ if (APPLE )
8+ if (IOS )
9+ set (CMAKE_OSX_ARCHITECTURES "arm64" )
10+ else ()
11+ # On GitHub Actions macOS runners, Python is often single-arch.
12+ # We try to detect the architecture of the Python library to avoid linking errors.
13+ set (CMAKE_OSX_ARCHITECTURES "arm64;x86_64" )
14+ if (Python3_ROOT_DIR)
15+ message (STATUS "Mac: Python3_ROOT_DIR is set, checking architecture..." )
16+ # If we're on a Silicon Mac runner (arm64), and Python is arm64,
17+ # building for x86_64 will fail unless we have a universal Python.
18+ # For simplicity, if we are in CI, we'll just target the current arch.
19+ if (DEFINED ENV{GITHUB_ACTIONS})
20+ set (CMAKE_OSX_ARCHITECTURES "arm64" )
21+ message (STATUS "CI detected: Targeting arm64 only for macOS build." )
22+ endif ()
23+ endif ()
24+ endif ()
825endif ()
26+
927set (CMAKE_CXX_VISIBILITY_PRESET hidden)
1028
1129if (Python3_ROOT_DIR)
1230 set (Python3_FIND_STRATEGY LOCATION)
1331endif ()
1432
1533if (ANDROID OR IOS )
16- # Android needs prebuilt Python - we'll keep this as an option
1734 if (NOT DEFINED PREBUILT_PYTHON_PATH)
18- message (STATUS "PREBUILT_PYTHON_PATH not set, attempting to use Python3_ROOT_DIR: ${Python3_ROOT_DIR} " )
19- set (PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR} )
35+ if (Python3_ROOT_DIR)
36+ set (PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR} )
37+ else ()
38+ message (WARNING "PREBUILT_PYTHON_PATH and Python3_ROOT_DIR not set for mobile platform!" )
39+ endif ()
2040 endif ()
2141
22- add_library (Python3_Mobile INTERFACE )
23- target_include_directories (Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH} /include )
24- # This might need adjustments based on the exact structure of the Android Python lib
25- target_link_libraries (Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH} /lib/libpython3.so )
26-
27- set (PYTHON_TARGET Python3_Mobile)
42+ if (PREBUILT_PYTHON_PATH)
43+ add_library (Python3_Mobile INTERFACE )
44+ target_include_directories (Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH} /include )
45+
46+ if (ANDROID )
47+ # Use a slightly more flexible search for the .so
48+ find_library (PYTHON_LIB python3.11 PATHS ${PREBUILT_PYTHON_PATH} /lib NO_DEFAULT_PATH )
49+ if (NOT PYTHON_LIB)
50+ find_library (PYTHON_LIB python3 PATHS ${PREBUILT_PYTHON_PATH} /lib NO_DEFAULT_PATH )
51+ endif ()
52+ target_link_libraries (Python3_Mobile INTERFACE ${PYTHON_LIB} )
53+ elseif (IOS )
54+ target_link_libraries (Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH} /lib/libpython3.a )
55+ endif ()
56+ set (PYTHON_TARGET Python3_Mobile)
57+ else ()
58+ message (FATAL_ERROR "Python Runtime requires a prebuilt Python for mobile platforms. Please provide PREBUILT_PYTHON_PATH." )
59+ endif ()
2860else ()
2961 find_package (Python3 REQUIRED COMPONENTS Interpreter Development.Embed )
3062 set (PYTHON_TARGET Python3::Python)
@@ -35,17 +67,18 @@ project(PythonRuntime VERSION 1.0.0)
3567file (GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp )
3668add_library (${PROJECT_NAME} SHARED ${SOURCES} )
3769
70+ # Use plain linking to match Geode's internal style
3871target_link_libraries (${PROJECT_NAME} ${PYTHON_TARGET} )
72+
3973if (NOT ANDROID AND NOT IOS )
4074 target_include_directories (${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS} )
4175endif ()
76+
4277target_include_directories (${PROJECT_NAME} INTERFACE include )
4378target_compile_definitions (${PROJECT_NAME} PRIVATE PYTHON_RUNTIME_EXPORT )
4479
4580if (NOT DEFINED ENV{GEODE_SDK})
4681 message (FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode" )
47- else ()
48- message (STATUS "Found Geode: $ENV{GEODE_SDK} " )
4982endif ()
5083
5184add_subdirectory ($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR} /geode )
0 commit comments