Skip to content

Commit

Permalink
Merge pull request #11 from rhaschke/master
Browse files Browse the repository at this point in the history
Cleanup cmake files
  • Loading branch information
wxmerkt authored Dec 23, 2019
2 parents 2990cee + ed27e50 commit 2f601aa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
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})
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>

0 comments on commit 2f601aa

Please sign in to comment.