Skip to content

Commit

Permalink
[cmake] Don't use GLOB/GLOB_RECURSE to find sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris Vaillant committed Oct 20, 2023
1 parent 7711a31 commit fcd1896
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 122 deletions.
68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,74 @@ IF(BUILD_WITH_HPP_FCL_SUPPORT)
ENDIF(BUILD_PYTHON_INTERFACE)
ENDIF(BUILD_WITH_HPP_FCL_SUPPORT)

# Sources definition
INCLUDE(sources.cmake)

IF(BUILD_WITH_URDF_SUPPORT)
LIST(APPEND ${PROJECT_NAME}_CORE_SOURCES ${${PROJECT_NAME}_URDF_SOURCES})
LIST(APPEND ${PROJECT_NAME}_CORE_PUBLIC_HEADERS ${${PROJECT_NAME}_URDF_PUBLIC_HEADERS})
ENDIF(BUILD_WITH_URDF_SUPPORT)

IF(BUILD_WITH_LIBPYTHON)
LIST(APPEND ${PROJECT_NAME}_CORE_PUBLIC_HEADERS
${${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES
${${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_SOURCES})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS
${${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_PUBLIC_HEADERS})
ENDIF(BUILD_WITH_LIBPYTHON)

IF(BUILD_WITH_HPP_FCL_SUPPORT)
LIST(APPEND ${PROJECT_NAME}_CORE_PUBLIC_HEADERS
${${PROJECT_NAME}_HPP_FCL_PUBLIC_HEADERS})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES
${${PROJECT_NAME}_BINDINGS_PYTHON_HPP_FCL_SOURCES})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS
${${PROJECT_NAME}_BINDINGS_PYTHON_HPP_FCL_PUBLIC_HEADERS})
ENDIF(BUILD_WITH_HPP_FCL_SUPPORT)

IF(BUILD_WITH_OPENMP_SUPPORT)
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES
${${PROJECT_NAME}_BINDINGS_PYTHON_OPENMP_SOURCES})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS
${${PROJECT_NAME}_BINDINGS_PYTHON_OPENMP_PUBLIC_HEADERS})
IF(BUILD_WITH_HPP_FCL_SUPPORT)
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES
${${PROJECT_NAME}_BINDINGS_PYTHON_HPP_FCL_OPENMP_SOURCES})
LIST(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS
${${PROJECT_NAME}_BINDINGS_PYTHON_HPP_FCL_OPENMP_PUBLIC_HEADERS})
ENDIF(BUILD_WITH_HPP_FCL_SUPPORT)
ENDIF()

# List headers to install
LIST(APPEND ${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_CORE_PUBLIC_HEADERS}
)
IF(BUILD_PYTHON_INTERFACE)
LIST(APPEND ${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS}
)
ENDIF(BUILD_PYTHON_INTERFACE)

# Macros to update souces path in subdirs
FUNCTION(REMOVE_PATH_FROM_LIST list_name path_name dest_list)
SET(list_name_)
FOREACH(header ${${list_name}})
STRING(REGEX REPLACE "^${path_name}" "" header ${header})
LIST(APPEND list_name_ ${header})
ENDFOREACH(header ${list_name_})
SET(${dest_list} ${list_name_} PARENT_SCOPE)
ENDFUNCTION(REMOVE_PATH_FROM_LIST)

FUNCTION(PREPEND_PATH_FROM_LIST list_name path_name dest_list)
SET(list_name_)
FOREACH(header ${${list_name}})
SET(header "${path_name}/${header}")
LIST(APPEND list_name_ ${header})
ENDFOREACH(header ${list_name_})
SET(${dest_list} ${list_name_} PARENT_SCOPE)
ENDFUNCTION(PREPEND_PATH_FROM_LIST)

# Enforce the preprocessed version of boost::list and boost::vector
# This information is redundant with the content of include/pinocchio/container/boost-container-limits.hpp
# but it avoids any compilation issue.
Expand Down
73 changes: 11 additions & 62 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,16 @@ include(${JRL_CMAKE_MODULES}/python-helpers.cmake)
SET(PYWRAP ${PROJECT_NAME}_pywrap)
SET(PYWRAP ${PYWRAP} PARENT_SCOPE)

FILE(GLOB_RECURSE ${PROJECT_NAME}_PYTHON_HEADERS
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/bindings/*.hpp
${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/bindings/*.hxx
)

FILE(GLOB_RECURSE ${PROJECT_NAME}_PYTHON_SOURCES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)

SET(SOURCE_HEADERS_ROOT "../../include/${PROJECT_NAME}/bindings/python")

# Parser for Python model
IF(NOT BUILD_WITH_LIBPYTHON)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_HEADERS
${SOURCE_HEADERS_ROOT}/parsers/python.hpp
)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_SOURCES
parsers/python/model.cpp
)
ENDIF(NOT BUILD_WITH_LIBPYTHON)

# Python exposition of FCL
IF(NOT BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_HEADERS
${SOURCE_HEADERS_ROOT}/multibody/fcl/transform.hpp
)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_SOURCES
multibody/fcl/expose-fcl.cpp
)
ENDIF(NOT BUILD_WITH_HPP_FCL_PYTHON_BINDINGS)

IF(NOT BUILD_WITH_OPENMP_SUPPORT)
LIST(FILTER ${PROJECT_NAME}_PYTHON_HEADERS EXCLUDE REGEX "^${SOURCE_HEADERS_ROOT}/multibody/pool")
LIST(FILTER ${PROJECT_NAME}_PYTHON_SOURCES EXCLUDE REGEX "^multibody/pool")
LIST(FILTER ${PROJECT_NAME}_PYTHON_HEADERS EXCLUDE REGEX "^${SOURCE_HEADERS_ROOT}/algorithm/parallel")
LIST(FILTER ${PROJECT_NAME}_PYTHON_SOURCES EXCLUDE REGEX "^algorithm/parallel")
ELSE(NOT BUILD_WITH_OPENMP_SUPPORT)
IF(NOT BUILD_WITH_HPP_FCL_SUPPORT)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_HEADERS
${SOURCE_HEADERS_ROOT}/multibody/pool/geometry.hpp
)
LIST(REMOVE_ITEM ${PROJECT_NAME}_PYTHON_SOURCES
algorithm/parallel/geometry.cpp
)
ENDIF(NOT BUILD_WITH_HPP_FCL_SUPPORT)
ENDIF(NOT BUILD_WITH_OPENMP_SUPPORT)

# --- COMPILE WRAPPER
REMOVE_PATH_FROM_LIST(${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES
"bindings/python/"
${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES)
PREPEND_PATH_FROM_LIST(${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS
"../../"
${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS)
MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/bindings/python/${PROJECT_NAME}")
SET(${PYWRAP}_SOURCES ${${PROJECT_NAME}_PYTHON_SOURCES})
SET(${PYWRAP}_HEADERS ${${PROJECT_NAME}_PYTHON_HEADERS})
SET(${PYWRAP}_SOURCES ${${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES})
SET(${PYWRAP}_HEADERS ${${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS})

IF(BUILD_PYTHON_INTERFACE)
ADD_CUSTOM_TARGET(python)
Expand Down Expand Up @@ -140,15 +97,6 @@ IF(BUILD_PYTHON_INTERFACE)
DESTINATION ${${PYWRAP}_INSTALL_DIR}
)

FOREACH(header ${${PYWRAP}_HEADERS})
GET_FILENAME_COMPONENT(header_path ${header} PATH)
STRING(REPLACE "../../" "" non_relative_header_path ${header_path})
INSTALL(FILES ${header}
DESTINATION ${CMAKE_INSTALL_PREFIX}/${non_relative_header_path}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE)
ENDFOREACH(header)


# --- INSTALL SCRIPTS
SET(PYTHON_FILES
__init__.py
Expand Down Expand Up @@ -222,9 +170,10 @@ IF(BUILD_PYTHON_INTERFACE)
SET(DOXYGEN_GENERATE_HTML YES)
SET(DOXYGEN_GENERATE_LATEX NO)
SET(DOXYGEN_PROJECT_NAME "Pinocchio PyBind11 helpers.")
SET(_source_headers_root "../../include/${PROJECT_NAME}/bindings/python")
DOXYGEN_ADD_DOCS(doc_pybind11
${SOURCE_HEADERS_ROOT}/pybind11.hpp
${SOURCE_HEADERS_ROOT}/pybind11-all.hpp
${_source_headers_root}/pybind11.hpp
${_source_headers_root}/pybind11-all.hpp
USE_STAMP_FILE
COMMENT "Generating documentation of the PyBind11 helpers.")
ENDIF()
Expand Down
Loading

0 comments on commit fcd1896

Please sign in to comment.