all repos — mgba @ 48a6bd47ceff7be7152cce427b91fde2f257e0af

mGBA Game Boy Advance Emulator

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

 1find_package(PythonLibs ${USE_PYTHON_VERSION})
 2find_package(PythonInterp ${USE_PYTHON_VERSION})
 3list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
 4include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
 5
 6get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
 7set(INCLUDE_FLAGS)
 8foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
 9	list(APPEND INCLUDE_FLAGS "-I${DIR}")
10endforeach()
11
12file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
13
14if(NOT GIT_TAG)
15	if(GIT_BRANCH STREQUAL "master" OR NOT GIT_BRANCH)
16		set(PYLIB_VERSION -b -${GIT_REV}-${GIT_COMMIT_SHORT})
17	else()
18		set(PYLIB_VERSION -b -${GIT_BRANCH}-${GIT_REV}-${GIT_COMMIT_SHORT})
19	endif()
20endif()
21configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
22
23add_custom_command(OUTPUT lib.c
24                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
25                  DEPENDS ${PYTHON_HEADERS}
26                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
27
28set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/lib.c PROPERTIES GENERATED ON)
29
30file(GLOB PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
31add_library(${BINARY_NAME}-pylib STATIC ${CMAKE_CURRENT_BINARY_DIR}/lib.c ${PYTHON_SRC})
32set_target_properties(${BINARY_NAME}-pylib PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR};${INCLUDE_DIRECTORIES}")
33set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
34set(PYTHON_LIBRARY ${BINARY_NAME}-pylib PARENT_SCOPE)
35
36add_custom_target(${BINARY_NAME}-py ALL
37                  COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py egg_info -e ${CMAKE_CURRENT_BINARY_DIR} ${PYLIB_VERSION}
38                  COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build -b ${CMAKE_CURRENT_BINARY_DIR}
39                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
40                  DEPENDS ${BINARY_NAME}
41                  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py
42                  DEPENDS ${PYTHON_HEADERS}
43                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
44                  DEPENDS ${BINARY_NAME}-pylib)
45
46file(GLOB BASE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/test_*.py)
47file(GLOB SUBTESTS ${CMAKE_CURRENT_SOURCE_DIR}/tests/*/test_*.py)
48foreach(TEST IN LISTS BASE_TESTS SUBTESTS)
49	if(APPLE)
50		set(PATH DYLD_LIBRARY_PATH)
51	elseif(WIN32)
52		set(PATH PATH)
53	else()
54		set(PATH LD_LIBRARY_PATH)
55	endif()
56	string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/(tests/.*/)?test_" "" TEST_NAME "${TEST}")
57	string(REPLACE ".py" "" TEST_NAME "${TEST_NAME}")
58	add_test(python-${TEST_NAME} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build -b ${CMAKE_CURRENT_BINARY_DIR} pytest --extras --addopts ${TEST})
59	set_tests_properties(python-${TEST_NAME} PROPERTIES ENVIRONMENT "${PATH}=${CMAKE_CURRENT_BINARY_DIR}/..")
60endforeach()