all repos — mgba @ a033f8783bc73cbe654f88a986f9ca4a9ebebf89

mGBA Game Boy Advance Emulator

src/platform/python/CMakeLists.txt (view raw)

 1find_program(PYTHON python)
 2
 3get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
 4set(INCLUDE_FLAGS)
 5foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
 6	list(APPEND INCLUDE_FLAGS "-I${DIR}")
 7endforeach()
 8
 9include(FindPythonLibs)
10list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
11include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
12
13file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
14
15configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
16add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py
17                   COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR}
18                   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
19                   DEPENDS ${BINARY_NAME}
20                   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py
21                   DEPENDS ${PYTHON_HEADERS}
22                   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
23
24add_custom_command(OUTPUT lib.c
25                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
26                  DEPENDS ${PYTHON_HEADERS}
27                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
28
29set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib.c PROPERTIES GENERATED ON)
30
31file(GLOB PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
32add_library(${BINARY_NAME}-pylib STATIC ${CMAKE_CURRENT_BINARY_DIR}/lib.c ${PYTHON_SRC})
33add_dependencies(${BINARY_NAME}-pylib ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
34set_target_properties(${BINARY_NAME}-pylib PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR};${INCLUDE_DIRECTORIES}")
35set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
36set(PYTHON_LIBRARY ${BINARY_NAME}-pylib PARENT_SCOPE)
37
38add_custom_target(${BINARY_NAME}-py ALL DEPENDS ${BINARY_NAME}-pylib ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py)