all repos — mgba @ c471d03c7dfcd5048599aa5ab37b1e6e9fefae4b

mGBA Game Boy Advance Emulator

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

 1if(DEFINED ENV{VIRTUAL_ENV})
 2      find_program(PYTHON_EXECUTABLE NAMES python PATHS "$ENV{VIRTUAL_ENV}/bin")
 3endif()
 4find_package(PythonInterp ${USE_PYTHON_VERSION})
 5find_package(PythonLibs ${USE_PYTHON_VERSION})
 6list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
 7include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
 8
 9get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
10set(INCLUDE_FLAGS)
11set(INCLUDE_FLAGS_STR "")
12foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
13      list(APPEND INCLUDE_FLAGS "-I${DIR}")
14      set(INCLUDE_FLAGS_STR "${INCLUDE_FLAGS_STR} \"-I${DIR}\"")
15endforeach()
16
17file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
18
19add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib.c
20                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
21                  COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/lib.c
22                  DEPENDS ${PYTHON_HEADERS}
23                  DEPENDS ${BINARY_NAME}
24                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
25
26set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib.c PROPERTIES GENERATED ON)
27
28file(GLOB PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
29add_library(${BINARY_NAME}-pylib STATIC ${CMAKE_CURRENT_BINARY_DIR}/lib.c ${PYTHON_SRC})
30set_target_properties(${BINARY_NAME}-pylib PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR};${INCLUDE_DIRECTORIES}")
31set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
32
33add_custom_target(${BINARY_NAME}-py ALL
34                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py build -b ${CMAKE_CURRENT_BINARY_DIR}
35                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36                  DEPENDS ${BINARY_NAME}
37                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
38                  DEPENDS ${PYTHON_HEADERS}
39                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
40                  DEPENDS ${BINARY_NAME}-pylib)
41
42add_custom_target(${BINARY_NAME}-py-install
43                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py install -b ${CMAKE_CURRENT_BINARY_DIR}
44                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
45                  DEPENDS ${BINARY_NAME}-py)
46
47add_custom_target(${BINARY_NAME}-py-develop
48                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py develop -b ${CMAKE_CURRENT_BINARY_DIR}
49                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
50                  DEPENDS ${BINARY_NAME}-py)
51
52add_custom_target(${BINARY_NAME}-py-bdist
53                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} setup.py bdist_wheel -b ${CMAKE_CURRENT_BINARY_DIR}
54                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
55                  DEPENDS ${BINARY_NAME}-py)
56
57file(GLOB BASE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/test_*.py)
58file(GLOB SUBTESTS ${CMAKE_CURRENT_SOURCE_DIR}/tests/*/test_*.py)
59foreach(TEST IN LISTS BASE_TESTS SUBTESTS)
60	if(APPLE)
61		set(PATH DYLD_LIBRARY_PATH)
62	elseif(WIN32)
63		set(PATH PATH)
64	else()
65		set(PATH LD_LIBRARY_PATH)
66	endif()
67	string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/(tests/.*/)?test_" "" TEST_NAME "${TEST}")
68	string(REPLACE ".py" "" TEST_NAME "${TEST_NAME}")
69	add_test(NAME python-${TEST_NAME}
70               COMMAND ${PYTHON_EXECUTABLE} setup.py build -b ${CMAKE_CURRENT_BINARY_DIR} pytest --extras --addopts ${TEST}
71               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
72	set_tests_properties(python-${TEST_NAME} PROPERTIES ENVIRONMENT "${PATH}=${CMAKE_CURRENT_BINARY_DIR}/..;BINDIR=${CMAKE_CURRENT_BINARY_DIR}/..;LIBDIR=${CMAKE_CURRENT_BINARY_DIR}/..;CPPFLAGS=${INCLUDE_FLAGS_STR}")
73endforeach()