mirror of https://github.com/mgba-emu/mgba.git
Python: Better approach to finding libs
This commit is contained in:
parent
d68e12c354
commit
3f94175189
|
@ -615,8 +615,7 @@ if(ENABLE_SCRIPTING)
|
|||
list(APPEND ENABLES SCRIPTING)
|
||||
|
||||
if(BUILD_PYTHON)
|
||||
find_program(PYTHON python)
|
||||
include(FindPythonLibs)
|
||||
find_package(PythonLibs ${USE_PYTHON_VERSION})
|
||||
list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
|
||||
include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
|
||||
list(APPEND ENABLES PYTHON)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
find_program(PYTHON python)
|
||||
find_package(PythonLibs ${USE_PYTHON_VERSION})
|
||||
find_package(PythonInterp ${USE_PYTHON_VERSION})
|
||||
list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
|
||||
include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
get_property(INCLUDE_DIRECTORIES DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
|
||||
set(INCLUDE_FLAGS)
|
||||
|
@ -6,15 +9,11 @@ foreach(DIR IN LISTS INCLUDE_DIRECTORIES)
|
|||
list(APPEND INCLUDE_FLAGS "-I${DIR}")
|
||||
endforeach()
|
||||
|
||||
include(FindPythonLibs)
|
||||
list(APPEND DEPENDENCY_LIB ${PYTHON_LIBRARIES})
|
||||
include_directories(AFTER ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
file(GLOB PYTHON_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||
add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py
|
||||
COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS ${BINARY_NAME}
|
||||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py
|
||||
|
@ -22,7 +21,7 @@ add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py
|
|||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
|
||||
|
||||
add_custom_command(OUTPUT lib.c
|
||||
COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
|
||||
COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. CPPFLAGS="${INCLUDE_FLAGS}" ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
|
||||
DEPENDS ${PYTHON_HEADERS}
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py)
|
||||
|
||||
|
@ -35,7 +34,7 @@ set_target_properties(${BINARY_NAME}-pylib PROPERTIES COMPILE_DEFINITIONS "${OS_
|
|||
set(PYTHON_LIBRARY ${BINARY_NAME}-pylib PARENT_SCOPE)
|
||||
|
||||
add_custom_target(${BINARY_NAME}-py ALL
|
||||
COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build
|
||||
DEPENDS ${BINARY_NAME}-pylib ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py)
|
||||
|
||||
file(GLOB TESTS ${CMAKE_CURRENT_SOURCE_DIR}/test_*.py)
|
||||
|
@ -49,6 +48,6 @@ foreach(TEST IN LISTS TESTS)
|
|||
endif()
|
||||
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/test_" "" TEST_NAME "${TEST}")
|
||||
string(REPLACE ".py" "" TEST_NAME "${TEST_NAME}")
|
||||
add_test(python-${TEST_NAME} ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py pytest --addopts ${TEST})
|
||||
add_test(python-${TEST_NAME} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py pytest --addopts ${TEST})
|
||||
set_tests_properties(python-${TEST_NAME} PROPERTIES ENVIRONMENT "${PATH}=${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||
endforeach()
|
||||
|
|
Loading…
Reference in New Issue