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

Enable jrl-cmakemodules workspace compatiblity #36

Merged
merged 6 commits into from
Jul 24, 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
49 changes: 43 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ SET(PROJECT_DESCRIPTION "Python bindings for CppAD and CppADCodeGen using Boost.
SET(PROJECT_URL "https://github.com/simple-robotics/pycppad")
SET(PROJECT_CUSTOM_HEADER_EXTENSION "hpp")
SET(PROJECT_USE_CMAKE_EXPORT TRUE)
# To enable jrl-cmakemodules compatibility with workspace we must define the two
# following lines
SET(PROJECT_AUTO_RUN_FINALIZE FALSE)
SET(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})


# Project configuration
Expand All @@ -17,15 +21,44 @@ SET(CMAKE_VERBOSE_MAKEFILE TRUE)
SET(CXX_DISABLE_WERROR TRUE)

# Check if the submodule cmake have been initialized
IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/base.cmake")
SET(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake")
IF(NOT EXISTS "${JRL_CMAKE_MODULES}/base.cmake")
MESSAGE(FATAL_ERROR "\nPlease run the following command first:\ngit submodule update --init\n")
ENDIF()

INCLUDE(cmake/base.cmake)
INCLUDE(cmake/boost.cmake)
INCLUDE(cmake/ide.cmake)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/find-external/CppAD/" ${CMAKE_MODULE_PATH})
if(EXISTS "${JRL_CMAKE_MODULES}/base.cmake")
message(STATUS "JRL cmakemodules found in 'cmake/' git submodule")
else()
find_package(jrl-cmakemodules QUIET CONFIG)
if(jrl-cmakemodules_FOUND)
get_property(
JRL_CMAKE_MODULES
TARGET jrl-cmakemodules::jrl-cmakemodules
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "JRL cmakemodules found on system at ${JRL_CMAKE_MODULES}")
elseif(${CMAKE_VERSION} VERSION_LESS "3.14.0")
message(
FATAL_ERROR
"\nCan't find jrl-cmakemodules. Please either:\n"
" - use git submodule: 'git submodule update --init'\n"
" - or install https://github.com/jrl-umi3218/jrl-cmakemodules\n"
" - or upgrade your CMake version to >= 3.14 to allow automatic fetching\n")
else()
message(STATUS "JRL cmakemodules not found. Let's fetch it.")
include(FetchContent)
FetchContent_Declare("jrl-cmakemodules"
GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git")
FetchContent_MakeAvailable("jrl-cmakemodules")
FetchContent_GetProperties("jrl-cmakemodules" SOURCE_DIR JRL_CMAKE_MODULES)
endif()
endif()

INCLUDE(${JRL_CMAKE_MODULES}/base.cmake)
INCLUDE(${JRL_CMAKE_MODULES}/boost.cmake)
INCLUDE(${JRL_CMAKE_MODULES}/ide.cmake)
INCLUDE(${JRL_CMAKE_MODULES}/python.cmake)

SET(CMAKE_MODULE_PATH "${JRL_CMAKE_MODULES}/find-external/CppAD/" ${CMAKE_MODULE_PATH})

# Project definition
COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX)
Expand All @@ -47,6 +80,8 @@ ENDIF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)

ADD_PROJECT_DEPENDENCY(cppad 20180000.0 REQUIRED PKG_CONFIG_REQUIRES "cppad >= 20180000.0")
ADD_PROJECT_DEPENDENCY(Eigen3 REQUIRED PKG_CONFIG_REQUIRES "eigen3 >= 3.0.5")
SET(PYTHON_COMPONENTS Interpreter Development NumPy)
FINDPYTHON(REQUIRED)
ADD_PROJECT_DEPENDENCY(eigenpy 2.7.14 REQUIRED)

SET(${PROJECT_NAME}_HEADERS
Expand Down Expand Up @@ -140,3 +175,5 @@ PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_COMPONENTS})

# Install catkin package.xml
INSTALL(FILES package.xml DESTINATION share/${PROJECT_NAME})

setup_project_finalize()
6 changes: 3 additions & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ADD_PYTHON_UNIT_TEST("add_eq" "example/add_eq.py" "python")
ADD_PYTHON_UNIT_TEST("${PROJECT_NAME}-add_eq" "example/add_eq.py" "python")
IF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
ADD_PYTHON_UNIT_TEST("cppadcg_c_codegen" "example/cppadcg_c_codegen.py" "python")
ENDIF(BUILD_WITH_CPPAD_CODEGEN_BINDINGS)
ADD_PYTHON_UNIT_TEST("${PROJECT_NAME}-cppadcg_c_codegen" "example/cppadcg_c_codegen.py" "python")
ENDIF()
10 changes: 5 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ SET(PYWRAP ${PYWRAP} PARENT_SCOPE)

MAKE_DIRECTORY("${${PROJECT_NAME}_BINARY_DIR}/python/${PROJECT_NAME}")

ADD_CUSTOM_TARGET(python)
SET_TARGET_PROPERTIES(python PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD True)
ADD_CUSTOM_TARGET(${PROJECT_NAME}_python)
SET_TARGET_PROPERTIES(${PROJECT_NAME}_python PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD True)

ADD_LIBRARY(${PYWRAP} SHARED main.cpp)
ADD_DEPENDENCIES(python ${PYWRAP})
ADD_DEPENDENCIES(${PROJECT_NAME}_python ${PYWRAP})
TARGET_LINK_LIBRARIES(${PYWRAP} PUBLIC ${PROJECT_NAME})
TARGET_LINK_BOOST_PYTHON(${PYWRAP} PUBLIC)
# BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS spews conversion warnings from int to long unsigned int.
Expand All @@ -35,9 +35,9 @@ SET_TARGET_PROPERTIES(${PYWRAP}
PREFIX ""
SUFFIX ${PYTHON_EXT_SUFFIX}
OUTPUT_NAME "${PYWRAP}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/${PROJECT_NAME}"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/python/${PROJECT_NAME}"
# On Windows, shared library are treated as binary
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/python/${PROJECT_NAME}"
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/python/${PROJECT_NAME}"
)

IF(UNIX AND NOT APPLE)
Expand Down
Loading