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

Make Python a configurable build option. #2422

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,29 @@ target_include_directories(squirrel PRIVATE ${SQUIRREL_DIR}/sqstdlib)
# pocketpy (Python)
################################

add_subdirectory(${THIRDPARTY_DIR}/pocketpy)
target_compile_definitions(pocketpy PRIVATE PK_ENABLE_OS=0)
include_directories(${THIRDPARTY_DIR}/pocketpy/include)
set(BUILD_WITH_PYTHON_DEFAULT TRUE)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(pocketpy PRIVATE -Wno-psabi)
endif()
option(BUILD_WITH_PYTHON "Python Enabled" ${BUILD_WITH_PYTHON_DEFAULT})
message("BUILD_WITH_PYTHON: ${BUILD_WITH_PYTHON}")

if(BUILD_WITH_PYTHON)

add_subdirectory(${THIRDPARTY_DIR}/pocketpy)
target_compile_definitions(pocketpy PRIVATE PK_ENABLE_OS=0)
include_directories(${THIRDPARTY_DIR}/pocketpy/include)

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(pocketpy PRIVATE -Wno-psabi)
endif()

# alias pocketpy to python for next steps
set_target_properties(pocketpy PROPERTIES OUTPUT_NAME python)
add_library(python ALIAS pocketpy)
# alias pocketpy to python for next steps
set_target_properties(pocketpy PROPERTIES OUTPUT_NAME python)
add_library(python ALIAS pocketpy)

if(EMSCRIPTEN)
# exceptions must be enabled for emscripten
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fexceptions")
if(EMSCRIPTEN)
# exceptions must be enabled for emscripten
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fexceptions")
endif()
endif()

################################
Expand Down Expand Up @@ -583,13 +591,16 @@ macro(MACRO_CORE SCRIPT DEFINE BUILD_DEPRECATED)
lpeg
wasm
squirrel
python
scheme
quickjs
blipbuf
zlib
)

if(BUILD_WITH_PYTHON)
target_link_libraries(tic80core${SCRIPT} python)
endif()

if(BUILD_WITH_WREN)
target_link_libraries(tic80core${SCRIPT} wren)
endif()
Expand Down Expand Up @@ -629,7 +640,11 @@ if(BUILD_STUB)
endif()

MACRO_CORE(squirrel TIC_BUILD_WITH_SQUIRREL FALSE)
MACRO_CORE(python TIC_BUILD_WITH_PYTHON FALSE)

if(BUILD_WITH_WREN)
MACRO_CORE(python TIC_BUILD_WITH_PYTHON FALSE)
endif()

MACRO_CORE(scheme TIC_BUILD_WITH_SCHEME FALSE)
MACRO_CORE(wasm TIC_BUILD_WITH_WASM FALSE)

Expand All @@ -643,6 +658,10 @@ if(BUILD_STUB)

endif()

if(BUILD_WITH_PYTHON)
target_compile_definitions(tic80core PUBLIC TIC_BUILD_WITH_PYTHON=1)
endif()

if(BUILD_WITH_WREN)
target_compile_definitions(tic80core PUBLIC TIC_BUILD_WITH_WREN=1)
endif()
Expand Down Expand Up @@ -920,6 +939,11 @@ if(BUILD_DEMO_CARTS)
${CMAKE_SOURCE_DIR}/config.lua
)

if(NOT BUILD_WITH_PYTHON)
list(REMOVE_ITEM DEMO_CARTS ${DEMO_CARTS_IN}/pythondemo.py)
list(REMOVE_ITEM DEMO_CARTS ${DEMO_CARTS_IN}/bunny/pythonmark.py)
endif()

if(NOT BUILD_WITH_WREN)
list(REMOVE_ITEM DEMO_CARTS ${DEMO_CARTS_IN}/wrendemo.wren)
list(REMOVE_ITEM DEMO_CARTS ${DEMO_CARTS_IN}/bunny/wrenmark.wren)
Expand Down Expand Up @@ -1417,7 +1441,11 @@ if(BUILD_STUB)

MACRO_STUB(js)
MACRO_STUB(squirrel)
MACRO_STUB(python)

if(BUILD_WITH_PYTHON)
MACRO_STUB(python)
endif()

MACRO_STUB(scheme)

if(BUILD_WITH_JANET)
Expand Down
2 changes: 0 additions & 2 deletions include/tic80_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
!defined(TIC_BUILD_WITH_JS) && \
!defined(TIC_BUILD_WITH_SCHEME) && \
!defined(TIC_BUILD_WITH_SQUIRREL) && \
!defined(TIC_BUILD_WITH_PYTHON) && \
!defined(TIC_BUILD_WITH_WASM)

# define TIC_BUILD_WITH_LUA 1
Expand All @@ -37,7 +36,6 @@
# define TIC_BUILD_WITH_JS 1
# define TIC_BUILD_WITH_SCHEME 1
# define TIC_BUILD_WITH_SQUIRREL 1
# define TIC_BUILD_WITH_PYTHON 1
# define TIC_BUILD_WITH_WASM 1

#endif
Expand Down
Loading