Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup cmake files #11

Merged
merged 9 commits into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ find_package(catkin REQUIRED)
include(ExternalProject)

ExternalProject_Add(pybind11_src
URL "https://github.com/pybind/pybind11/archive/v2.2.4.zip"
URL_MD5 "06f0bbf25dc9c4fe15092e9e03a8fc01"
URL "https://github.com/pybind/pybind11/archive/v2.4.3.zip"
UPDATE_COMMAND ""
CMAKE_ARGS -DPYBIND11_TEST:BOOL=OFF -DPYBIND11_INSTALL:BOOL=ON -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/install
CMAKE_ARGS -DPYBIND11_PYTHON_VERSION=${PYTHON_VERSION_STRING}
-DPYBIND11_TEST:BOOL=OFF -DPYBIND11_INSTALL:BOOL=ON
-DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/install
)
ExternalProject_Add_Step(pybind11_src CopyToDevel
COMMENT "Copying to devel"
Expand All @@ -18,28 +19,19 @@ ExternalProject_Add_Step(pybind11_src CopyToDevel
DEPENDEES install
)

if(IS_DIRECTORY ${CMAKE_INSTALL_PREFIX})
message(WARNING "Compiling for install workspace (${CMAKE_INSTALL_PREFIX})")
catkin_package(
INCLUDE_DIRS include/${PROJECT_NAME}
LIBRARIES ${PYTHON_LIBRARIES}
CFG_EXTRAS pybind11_catkin.cmake
)
else()
message(WARNING "Compiling for devel workspace")
file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME})
catkin_package(
INCLUDE_DIRS ${CATKIN_DEVEL_PREFIX}/include ${EIGEN3_INCLUDE_DIR}
LIBRARIES ${PYTHON_LIBRARIES}
CFG_EXTRAS pybind11_catkin.cmake
)
endif()
file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME})
wxmerkt marked this conversation as resolved.
Show resolved Hide resolved
catkin_package(
INCLUDE_DIRS ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME}
CFG_EXTRAS pybind11_catkin.cmake
)

install(
DIRECTORY ${CATKIN_DEVEL_PREFIX}/include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
install(
FILES ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/FindPythonLibsNew.cmake ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/FindPythonLibsNew.cmake ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/pybind11Tools.cmake
FILES
${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/FindPythonLibsNew.cmake
${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/cmake/pybind11Tools.cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake
)
30 changes: 10 additions & 20 deletions cmake/pybind11_catkin.cmake.in
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
cmake_minimum_required(VERSION 2.8.3)

# Configure pybind11 using the cmake file provided by the upstream package.
# This finds python includes and libs and defines pybind11_add_module()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

set(TEMP_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
if(DEFINED PYBIND_PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE ${PYBIND_PYTHON_EXECUTABLE} CACHE INTERNAL "")
endif()

set(PYBIND11_PYTHON_VERSION ${PYTHON_VERSION_STRING})
include(pybind11Tools)

# Cache variables so pybind11_add_module can be used in parent projects
set(PYBIND11_INCLUDE_DIR ${PYBIND11_INCLUDE_DIR} CACHE INTERNAL "")
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE INTERNAL "")

set(PYTHON_EXECUTABLE ${TEMP_PYTHON_EXECUTABLE} CACHE INTERNAL "")
# set variables used by pybind11_add_module()
if(@INSTALLSPACE@)
set(pybind11_catkin_INCLUDE_DIRS "${pybind11_catkin_INCLUDE_DIRS}/@PROJECT_NAME@")
endif()
set(PYBIND11_INCLUDE_DIR "${pybind11_catkin_INCLUDE_DIRS}")
list(APPEND pybind11_catkin_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")

macro(pybind_add_module target_name other)
include_directories(${pybind11_catkin_INCLUDE_DIRS}/pybind11_catkin) # Such that libraries are locally available as pybind11/pybind11, without exporting.
pybind11_add_module(${ARGV})
target_link_libraries(${target_name} PRIVATE ${PYTHON_LIBRARIES} ${catkin_LIBRARIES})
set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_GLOBAL_PYTHON_DESTINATION})
set(PYTHON_LIB_DIR ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
add_custom_command(TARGET ${target_name}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_LIB_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target_name}> ${PYTHON_LIB_DIR}/${target_name}.so
WORKING_DIRECTORY ${CATKIN_DEVEL_PREFIX}
COMMENT "Copying library files to python directory")
set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
endmacro(pybind_add_module)
10 changes: 4 additions & 6 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<package format="2">
<name>pybind11_catkin</name>
<version>2.2.4</version>
<version>2.4.3</version>
<description>The pybind11 package</description>
<maintainer email="[email protected]">Vladimir Ivan</maintainer>
<maintainer email="[email protected]">Wolfgang Merkt</maintainer>
<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>
<!-- <build_depend>git</build_depend> -->
<depend>python</depend>
<depend>python-numpy</depend>
<depend>rospy</depend>
<depend>eigen</depend>

<build_export_depend>python</build_export_depend>
<build_export_depend>python-numpy</build_export_depend>
<build_export_depend>eigen</build_export_depend>
</package>