|
1 | 1 | cmake_minimum_required(VERSION 3.21) |
2 | 2 |
|
3 | | -# Set C++ standard to 20 for compatibility with Geode's {fmt} |
| 3 | +# Standard C++20 for compatibility with modern Geode and {fmt} |
4 | 4 | set(CMAKE_CXX_STANDARD 20) |
5 | 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
6 | | - |
7 | 6 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) |
8 | 7 |
|
9 | | -if (Python3_ROOT_DIR) |
10 | | - set(Python3_FIND_STRATEGY LOCATION) |
11 | | -endif() |
| 8 | +# --- Python Discovery --- |
| 9 | +# We need to find the Python development headers and libraries. |
| 10 | +# On mobile (Android/iOS), we often rely on prebuilt versions. |
12 | 11 |
|
13 | 12 | if (ANDROID) |
14 | | - if (NOT DEFINED PREBUILT_PYTHON_PATH) |
15 | | - if (Python3_ROOT_DIR) |
16 | | - set(PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR}) |
17 | | - else() |
18 | | - message(WARNING "PREBUILT_PYTHON_PATH and Python3_ROOT_DIR not set for Android!") |
19 | | - endif() |
| 13 | + message(STATUS "Configuring Python for Android...") |
| 14 | + |
| 15 | + # I literally spent all of yesterday fighting with Android's find_library. |
| 16 | + # Why is it so inconsistent with the NDK? If this pathing logic |
| 17 | + # ever breaks again, I'm quitting. |
| 18 | + if (NOT DEFINED PREBUILT_PYTHON_PATH AND Python3_ROOT_DIR) |
| 19 | + set(PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR}) |
20 | 20 | endif() |
21 | 21 |
|
22 | 22 | if (PREBUILT_PYTHON_PATH) |
| 23 | + message(STATUS "Using prebuilt Python from: ${PREBUILT_PYTHON_PATH}") |
23 | 24 | add_library(Python3_Mobile INTERFACE) |
24 | | - target_include_directories(Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH}/include) |
| 25 | + target_include_directories(Python3_Mobile INTERFACE "${PREBUILT_PYTHON_PATH}/include") |
25 | 26 |
|
26 | | - find_library(PYTHON_LIB python3.11 PATHS ${PREBUILT_PYTHON_PATH}/lib NO_DEFAULT_PATH) |
| 27 | + # We try to find the specific library version |
| 28 | + find_library(PYTHON_LIB NAMES python3.11 python3 PATHS "${PREBUILT_PYTHON_PATH}/lib" NO_DEFAULT_PATH) |
27 | 29 | if (NOT PYTHON_LIB) |
28 | | - find_library(PYTHON_LIB python3 PATHS ${PREBUILT_PYTHON_PATH}/lib NO_DEFAULT_PATH) |
| 30 | + message(FATAL_ERROR "Could not find Python library in ${PREBUILT_PYTHON_PATH}/lib") |
29 | 31 | endif() |
30 | | - target_link_libraries(Python3_Mobile INTERFACE ${PYTHON_LIB}) |
31 | 32 |
|
| 33 | + target_link_libraries(Python3_Mobile INTERFACE ${PYTHON_LIB}) |
32 | 34 | set(PYTHON_TARGET Python3_Mobile) |
33 | 35 | else() |
34 | | - message(STATUS "Python Runtime will attempt to find Python despite no PREBUILT_PYTHON_PATH provided.") |
| 36 | + message(WARNING "Neither PREBUILT_PYTHON_PATH nor Python3_ROOT_DIR is set for Android. Build might fail.") |
35 | 37 | find_package(Python3 REQUIRED COMPONENTS Development.Embed) |
36 | 38 | set(PYTHON_TARGET Python3::Python) |
37 | 39 | endif() |
38 | 40 | else() |
| 41 | + # On desktop platforms, standard discovery is usually fine. |
39 | 42 | find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Embed) |
40 | 43 | set(PYTHON_TARGET Python3::Python) |
| 44 | + message(STATUS "Found Python: ${Python3_VERSION} at ${Python3_EXECUTABLE}") |
41 | 45 | endif() |
42 | 46 |
|
| 47 | +# --- Project Setup --- |
43 | 48 | project(PythonRuntime VERSION 1.0.0) |
44 | 49 |
|
| 50 | +# Automatically pick up any .cpp files in the src/ directory |
45 | 51 | file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp) |
| 52 | + |
46 | 53 | add_library(${PROJECT_NAME} SHARED ${SOURCES}) |
47 | 54 |
|
48 | | -# Use plain linking to match Geode's internal style |
| 55 | +# --- Linking & Includes --- |
49 | 56 | target_link_libraries(${PROJECT_NAME} ${PYTHON_TARGET}) |
50 | 57 |
|
51 | | -if (NOT ANDROID) |
52 | | - target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS}) |
53 | | -endif() |
54 | | - |
| 58 | +# Ensure we have access to our own public headers |
55 | 59 | target_include_directories(${PROJECT_NAME} INTERFACE include) |
| 60 | + |
| 61 | +# This define is used in PythonRuntime.hpp to handle DLL exports |
56 | 62 | target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHON_RUNTIME_EXPORT) |
57 | 63 |
|
| 64 | +# Desktop-specific includes if find_package was used |
| 65 | +if (NOT ANDROID AND Python3_INCLUDE_DIRS) |
| 66 | + target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS}) |
| 67 | +endif() |
| 68 | + |
| 69 | +# --- Geode Integration --- |
| 70 | +# Geode is required for this mod to function. |
58 | 71 | if (NOT DEFINED ENV{GEODE_SDK}) |
59 | | - message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode") |
| 72 | + message(FATAL_ERROR "GEODE_SDK environment variable is not set! Please point it to your Geode SDK directory.") |
60 | 73 | endif() |
61 | 74 |
|
| 75 | +message(STATUS "Geode SDK found at: $ENV{GEODE_SDK}") |
62 | 76 | add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode) |
63 | 77 |
|
| 78 | +# Finalize the Geode mod setup |
64 | 79 | setup_geode_mod(${PROJECT_NAME} VERSION 4.0.0) |
0 commit comments