-
Notifications
You must be signed in to change notification settings - Fork 173
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
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
ros2pkg/ros2pkg/resource/ament_cmake_python/CMakeLists.txt.em
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are currently no instances of ROS 2 packages where this would be true. That is,
package.get_build_type()
will never returnament_cmake_python
.That said, it would still be worthwhile to have some way to create a package template for a Python package using CMake. However, it will have to be done a different way because it will use a
build_type
ofament_cmake
. Maybe we can add in a new command-line argument that tells it to generate Python installation stuff in the CMakeLists.txt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I agree with that
build_type
is not appropriate field for generating templates.So maybe something like like,