src/platform/python/CMakeLists.txt (view raw)
1set(PY_INCLUDE_DIRS -I${CMAKE_SOURCE_DIR}/src)
2get_property(INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
3get_property(COMPILE_DEFINITIONS DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
4foreach(INCLUDE_DIR IN LISTS INCLUDE_DIRECTORIES)
5 list(APPEND PY_INCLUDE_DIRS -I${INCLUDE_DIR})
6endforeach()
7foreach(COMPILE_DEF IN LISTS COMPILE_DEFINITIONS)
8 list(APPEND PY_COMPILE_DEFS -D${COMPILE_DEF})
9endforeach()
10
11add_custom_command(OUTPUT _builder.h
12 COMMAND ${CMAKE_C_COMPILER} ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS} -fno-inline -E -P -c ${CMAKE_CURRENT_SOURCE_DIR}/_builder.h -o _builder.h
13 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.h)
14add_custom_target(_builder.h ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_builder.h)
15
16add_custom_command(OUTPUT ${BINARY_NAME}/_pylib.so
17 COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS}
18 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py
19 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_builder.h)
20add_custom_target(_pylib.so ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}/_pylib.so)