Skip to content

Commit

Permalink
Python working on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
JBBee committed Feb 27, 2020
1 parent c6b2f09 commit a55f031
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,21 @@ elseif(NOT SKIP_PYTHON)
set(SKIP_PYTHON OFF)
endif()

if (NOT SKIP_PYTHON)
if (SKIP_PYTHON)
message(STATUS "Building without Python")
else()
ExternalProject_Add(
py-protobufs-external
DEPENDS ${protobuf_depends}
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/py-protobuf
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DProtobufs_SRC_DIR=${CMAKE_CURRENT_BINARY_DIR}/protobuf
)
endif()

ExternalProject_Add(
Expand Down
23 changes: 23 additions & 0 deletions py-protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.11)

project(py-protobuf)

find_package(protobuf REQUIRED PATHS "${CMAKE_INSTALL_PREFIX}/deps/protobuf/cmake" "${CMAKE_INSTALL_PREFIX}/deps/protobuf/lib/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake")

get_target_property(PROTOC_EXE protobuf::protoc LOCATION)

file(COPY "${PROTOC_EXE}" DESTINATION "${Protobufs_SRC_DIR}/src/")

find_package(Python REQUIRED COMPONENTS Interpreter Development)

get_target_property(PYTHON_EXE Python::Interpreter LOCATION)
message(STATUS "PYTHON_EXE = ${PYTHON_EXE}")
file(MAKE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin/")
if (NOT WIN32)
add_custom_target(${PROJECT_NAME} ALL
COMMAND ${CMAKE_COMMAND} -E chdir "${Protobufs_SRC_DIR}/python" "${PYTHON_EXE}" setup.py build
COMMAND
${CMAKE_COMMAND} -E copy_directory ${Protobufs_SRC_DIR}/python/build/`ls ${Protobufs_SRC_DIR}/python/build/`/google/ "${CMAKE_INSTALL_PREFIX}/bin/google")
endif()

4 changes: 3 additions & 1 deletion src/api/python/src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/gravity_wrap.cpp" "${CMAK
add_library(${LIB_NAME} SHARED ${SRCS})
if (WIN32)
set_target_properties(${LIB_NAME} PROPERTIES SUFFIX .pyd)
else()
set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
endif()
target_link_libraries(${LIB_NAME} gravity Python::Python)
gravity_add_dependency(${LIB_NAME})
install(TARGETS ${LIB_NAME} RUNTIME DESTINATION bin/gravity)
install(TARGETS ${LIB_NAME} LIBRARY DESTINATION bin/gravity RUNTIME DESTINATION bin/gravity)

0 comments on commit a55f031

Please sign in to comment.