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

Fix CMake for installing package #3

Merged
merged 18 commits into from
Nov 10, 2024
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
21 changes: 18 additions & 3 deletions .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,34 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install urdf-parser-py jinja2 numpy
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=ON -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --target install

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

- name: Configure CMake For Fetch Content
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build_fetch -S ${{github.workspace}}/test/fetch_content_test -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build For Fetch Content
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build_fetch --config ${{env.BUILD_TYPE}}
58 changes: 49 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
cmake_minimum_required(VERSION 3.22)
project(fast_forward_kinematics)

# Set C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(FFK_VERSION_MAJOR 0)
set(FFK_VERSION_MINOR 1)
set(FFK_VERSION ${FFK_VERSION_MAJOR}.${FFK_VERSION_MINOR})

# Generate the module for the python
include(cmake/fast_forward_kinematics-extras.cmake)
option(BUILD_TESTING "Build fast_forward_kinematics tests" OFF)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/fast_forward_kinematics-extras.cmake
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/fast_forward_kinematics-extras.cmake" @ONLY
# Include GNUInstallDirs to get canonical paths
include(GNUInstallDirs)
include(CTest)

# Add cmake macro to project
include(fast_forward_kinematics.cmake)

add_library(fast_forward_kinematics_header INTERFACE)
target_include_directories(fast_forward_kinematics_header INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if (BUILD_TESTING)
add_subdirectory(test)
endif ()


include(CMakePackageConfigHelpers)

install(DIRECTORY include DESTINATION include/)
configure_package_config_file(fast_forward_kinematics-config.cmake.in fast_forward_kinematics-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/fast_forward_kinematics"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

add_subdirectory(test)
write_basic_package_version_file(fast_forward_kinematics-config-version.cmake
VERSION ${FFK_VERSION} COMPATIBILITY AnyNewerVersion)

install(FILES
"${CMAKE_BINARY_DIR}/fast_forward_kinematics-config.cmake"
"${CMAKE_BINARY_DIR}/fast_forward_kinematics-config-version.cmake"
"${CMAKE_SOURCE_DIR}/fast_forward_kinematics.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")

install(DIRECTORY "${CMAKE_SOURCE_DIR}/code_generation" DESTINATION "${CMAKE_INSTALL_DATADIR}/fast_forward_kinematics/cmake")
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/fast_forward_kinematics")

# Create an export set
install(TARGETS fast_forward_kinematics_header EXPORT fast_forward_kinematicsTargets)
# Targets files
export(
EXPORT fast_forward_kinematicsTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/fast_forward_kinematics-targets.cmake
)
install(
EXPORT fast_forward_kinematicsTargets
FILE fast_forward_kinematics-targets.cmake
DESTINATION lib/cmake/fast_forward_kinematics
)
67 changes: 0 additions & 67 deletions cmake/fast_forward_kinematics-extras.cmake

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace fast_fk::internal {
}

#ifdef FAST_FK_USE_IK
#include "fast_inverse_kinematics.hpp"
#include "fast_inverse_kinematics/fast_inverse_kinematics.hpp"

namespace fast_fk::internal {
constexpr float axis_scale = 1;
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions fast_forward_kinematics-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@PACKAGE_INIT@

set(FFK_VERSION_MAJOR @FFK_VERSION_MAJOR@)
set(FFK_VERSION_MINOR @FFK_VERSION_MINOR@)
set(FFK_VERSION @FFK_VERSION@)

set(fast_forward_kinematics_FOUND ON)
set_and_check(fast_forward_kinematics_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")

include("${CMAKE_CURRENT_LIST_DIR}/fast_forward_kinematics-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/fast_forward_kinematics.cmake")
114 changes: 114 additions & 0 deletions fast_forward_kinematics.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
include(CMakeParseArguments)
function(generate_fast_forward_kinematics_library_common target_name)
cmake_parse_arguments(ARG "" "URDF_FILE;ROOT_LINK;TIP_LINK;EXT" "" ${ARGN})
if (ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "generate_fast_forward_kinematics_library_common() called with invalid arguments.")
endif ()

# Set cmake build type to Release if not specified
if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
endif ()

find_package(Python REQUIRED COMPONENTS Interpreter)
if (Python_Interpreter_FOUND)
message(STATUS "Python executable: ${Python_EXECUTABLE}")
else ()
message(FATAL_ERROR "Python interpreter not found.")
endif ()

execute_process(
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/get_num_joints.py ${ARG_URDF_FILE} ${ARG_ROOT_LINK} ${ARG_TIP_LINK}
OUTPUT_VARIABLE FAST_FK_NUMBER_OF_JOINTS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ECHO STDOUT
)

add_custom_command(
OUTPUT forward_kinematics_lib.${ARG_EXT}
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/robot_gen.py ${ARG_URDF_FILE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/robot_config.${ARG_EXT}.template
${CMAKE_CURRENT_BINARY_DIR}/forward_kinematics_lib.${ARG_EXT} ${ARG_ROOT_LINK} ${ARG_TIP_LINK}
DEPENDS ${ARG_URDF_FILE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/robot_config.${ARG_EXT}.template
COMMENT
"Running `${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/robot_gen.py
${ARG_URDF_FILE}
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/code_generation/robot_config.cpp.template
${CMAKE_CURRENT_BINARY_DIR}/forward_kinematics_test.cpp
${ROOT_LINK}
${TIP_LINK}`"
VERBATIM
)
add_custom_target(code_generation DEPENDS forward_kinematics_lib.${ARG_EXT})
add_library(${target_name} SHARED forward_kinematics_lib.${ARG_EXT})
add_dependencies(${target_name} code_generation)

target_link_libraries(${target_name} PUBLIC fast_forward_kinematics_header)
target_compile_definitions(${target_name} PUBLIC "${FAST_FK_NUMBER_OF_JOINTS}")


endfunction()


macro(ffk_failed_arg_parse)
message(FATAL_ERROR "generate_fast_forward_kinematics_library() called with unused arguments: ${ARG_UNPARSED_ARGUMENTS}. "
"Expected arguments: generate_fast_forward_kinematics_library(target_name URDF_FILE val1 ROOT_LINK val2 TIP_LINK val3)")
endmacro()

function(generate_fast_forward_kinematics_library target_name)
cmake_parse_arguments(ARG "" "URDF_FILE;ROOT_LINK;TIP_LINK" "" ${ARGN})
if (ARG_UNPARSED_ARGUMENTS)
ffk_failed_arg_parse()
endif ()

include(ExternalProject)
ExternalProject_Add(
LBFGSpp
PREFIX ${CMAKE_BINARY_DIR}/LBFGSpp
GIT_REPOSITORY https://github.com/yixuan/LBFGSpp.git
GIT_TAG v0.3.0
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DBUILD_TESTING=OFF
)
ExternalProject_Get_Property(LBFGSpp source_dir)
set(LBFGSppIncludeDir ${source_dir}/include)

generate_fast_forward_kinematics_library_common(fast_forward_kinematics_library
URDF_FILE "${ARG_URDF_FILE}"
ROOT_LINK "${ARG_ROOT_LINK}"
TIP_LINK "${ARG_TIP_LINK}"
EXT "cpp")

add_dependencies(fast_forward_kinematics_library LBFGSpp)
target_compile_definitions(fast_forward_kinematics_library PUBLIC FAST_FK_USE_IK)
target_include_directories(fast_forward_kinematics_library PUBLIC ${LBFGSppIncludeDir})
find_package(Eigen3 3.3 NO_MODULE)
if(NOT Eigen3_FOUND)
include(FetchContent)
set(PROJECT_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
)
FetchContent_MakeAvailable(eigen)
set(BUILD_TESTING ${PROJECT_BUILD_TESTING})

endif ()
target_link_libraries(fast_forward_kinematics_library PUBLIC Eigen3::Eigen)

target_compile_options(fast_forward_kinematics_library PUBLIC -Ofast -march=native)

endfunction()

function(generate_fast_forward_kinematics_library_cuda target_name)
cmake_parse_arguments(ARG "" "URDF_FILE;ROOT_LINK;TIP_LINK" "" ${ARGN})
if (ARG_UNPARSED_ARGUMENTS)
ffk_failed_arg_parse()
endif ()
enable_language(CUDA)
generate_fast_forward_kinematics_library_common(fast_forward_kinematics_library
URDF_FILE "${ARG_URDF_FILE}"
ROOT_LINK "${ARG_ROOT_LINK}"
TIP_LINK "${ARG_TIP_LINK}"
EXT "cu")
endfunction()
46 changes: 0 additions & 46 deletions include/fast_inverse_kinematics.hpp

This file was deleted.

Loading
Loading