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

Support ament_cmake_python for pkg create #904

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 24 additions & 0 deletions ros2pkg/ros2pkg/api/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,27 @@ def populate_cpp_library(package, source_directory, include_directory, cpp_libra
include_directory,
'visibility_control.h',
visibility_config)


def populate_ament_cmake_python(package, package_directory, cpp_node_name, cpp_library_name):
cmakelists_config = {
'project_name': package.name,
'dependencies': [str(dep) for dep in package.build_depends],
'cpp_node_name': cpp_node_name,
'cpp_library_name': cpp_library_name,
}
_create_template_file(
'ament_cmake_python',
'CMakeLists.txt.em',
package_directory,
'CMakeLists.txt',
cmakelists_config)

_create_folder(package.name, package_directory)
_create_template_file('ament_cmake_python',
'init.py.em',
package_directory + os.sep + package.name,
'__init__.py',
{})

_ = _create_folder('test', package_directory)
118 changes: 118 additions & 0 deletions ros2pkg/ros2pkg/resource/ament_cmake_python/CMakeLists.txt.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
cmake_minimum_required(VERSION 3.8)
project(@(project_name))

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
@[if cpp_library_name]@
find_package(ament_cmake_ros REQUIRED)
@[end if]@
@[if dependencies]@
@[ for dep in dependencies]@
find_package(@dep REQUIRED)
@[ end for]@
@[else]@
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
@[end if]@

@[if cpp_library_name]@
add_library(@(cpp_library_name) src/@(cpp_library_name).cpp)
add_library(@(project_name)::@(cpp_library_name) ALIAS @(cpp_library_name))
target_compile_features(@(cpp_library_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_include_directories(@(cpp_library_name) PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
@[ if dependencies]@
ament_target_dependencies(
@(cpp_library_name)
@[ for dep in dependencies]@
"@(dep)"
@[ end for]@
)
@[ end if]@

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(@(cpp_library_name) PRIVATE "@(project_name.upper())_BUILDING_LIBRARY")

install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
)
install(
TARGETS @(cpp_library_name)
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
@[end if]@
@[if cpp_node_name]@

add_executable(@(cpp_node_name) src/@(cpp_node_name).cpp)
target_include_directories(@(cpp_node_name) PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
@[ if cpp_library_name]@
target_link_libraries(@(cpp_node_name) @(cpp_library_name))
@[ else]@
target_compile_features(@(cpp_node_name) PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
@[ if dependencies]@
ament_target_dependencies(
@(cpp_node_name)
@[ for dep in dependencies]@
"@(dep)"
@[ end for]@
)
@[ end if]@
@[ end if]@

install(TARGETS @(cpp_node_name)
DESTINATION lib/${PROJECT_NAME})
@[end if]@

ament_python_install_package(${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(ament_cmake_pytest REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
set(_pytest_tests
# Add test files here
)
foreach(_test_path ${_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 60
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
endif()
@[if cpp_library_name]@

ament_export_include_directories(
"include/${PROJECT_NAME}"
)
ament_export_libraries(
@(cpp_library_name)
)
ament_export_targets(
export_${PROJECT_NAME}
)
@[end if]@

ament_package()
Empty file.
Empty file.
29 changes: 28 additions & 1 deletion ros2pkg/ros2pkg/verb/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from ros2pkg.api.create import create_package_environment
from ros2pkg.api.create import populate_ament_cmake
from ros2pkg.api.create import populate_ament_cmake_python
from ros2pkg.api.create import populate_ament_python
from ros2pkg.api.create import populate_cmake
from ros2pkg.api.create import populate_cpp_library
Expand Down Expand Up @@ -87,6 +88,10 @@ def add_arguments(self, parser, cli_name):
parser.add_argument(
'--library-name',
help='name of the empty library')
parser.add_argument(
'--template-name',
help='name of template for package create'
"(pass '?' to get a list)")

def main(self, *, args):
available_licenses = {}
Expand All @@ -97,6 +102,20 @@ def main(self, *, args):
print('Supported licenses:\n%s' % ('\n'.join(available_licenses)))
sys.exit(0)

available_template = {
'cmake': ['cmake'],
'ament_cmake': ['ament_cmake', 'ament_cmake_python'],
'ament_python': ['ament_python']
}
if args.template_name == '?':
print('Supported template:\n%s' % ('\n'.join(available_template[args.build_type])))
sys.exit(0)

template_name = args.template_name or args.build_type
if template_name not in available_template[args.build_type]:
return "Abort since template '{}' is not supported for given build-type '{}'" \
.format(template_name, args.build_type)

maintainer = Person(args.maintainer_name)

if args.maintainer_email:
Expand Down Expand Up @@ -133,9 +152,14 @@ def main(self, *, args):
else:
buildtool_depends = ['ament_cmake']

if template_name == 'ament_cmake_python':
buildtool_depends.append('ament_cmake_python')

test_dependencies = []
if args.build_type == 'ament_cmake':
test_dependencies = ['ament_lint_auto', 'ament_lint_common']
if template_name == 'ament_cmake_python':
test_dependencies.append('ament_cmake_pytest')
if args.build_type == 'ament_python':
test_dependencies = ['ament_copyright', 'ament_flake8', 'ament_pep257',
'python3-pytest']
Expand Down Expand Up @@ -189,7 +213,10 @@ def main(self, *, args):
populate_cmake(package, package_directory, node_name, library_name)

if args.build_type == 'ament_cmake':
populate_ament_cmake(package, package_directory, node_name, library_name)
if template_name == 'ament_cmake':
populate_ament_cmake(package, package_directory, node_name, library_name)
elif template_name == 'ament_cmake_python':
populate_ament_cmake_python(package, package_directory, node_name, library_name)

if args.build_type == 'ament_python':
if not source_directory:
Expand Down