| /***************************************************************************** |
| * Copyright (c) 2018 CEA LIST. |
| * |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * Ansgar Radermacher ansgar.radermacher@cea.fr |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.robotics.ros2.codegen.build |
| |
| import org.eclipse.uml2.uml.Class |
| import org.eclipse.uml2.uml.Package |
| import static extension org.eclipse.papyrus.robotics.ros2.codegen.utils.PackageTools.pkgName |
| import static extension org.eclipse.papyrus.robotics.ros2.codegen.utils.ActivityUtils.hasExternalCode |
| import org.eclipse.papyrus.infra.tools.file.IPFileSystemAccess |
| import java.util.List |
| import org.eclipse.papyrus.robotics.ros2.codegen.utils.MessageUtils |
| import org.eclipse.papyrus.robotics.ros2.codegen.component.CodeSkeleton |
| import java.util.Collections |
| |
| /** |
| * Create CMakeLists file for a component definition |
| */ |
| class CreateCompCMakeLists { |
| static def createCMakeLists(Package pkg, List<Class> components, Class system) ''' |
| cmake_minimum_required(VERSION 3.5.0) |
| project(«pkg.pkgName») |
| |
| # Default to C++14 |
| if(NOT CMAKE_CXX_STANDARD) |
| set(CMAKE_CXX_STANDARD 14) |
| endif() |
| |
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| add_compile_options(-Wall -Wextra -Wpedantic) |
| endif() |
| |
| find_package(ament_cmake REQUIRED) |
| «FOR msg_pkg : CreateCompPackageXML.calcDependencies(components)» |
| find_package(«msg_pkg» REQUIRED) |
| «ENDFOR» |
| |
| include_directories( |
| # assure that generated .h files are found |
| ${PROJECT_SOURCE_DIR}/src |
| ${PROJECT_SOURCE_DIR}/src-gen |
| ) |
| |
| «FOR component : components» |
| «val compBaseFile = component.qualifiedName.replace("::", "/")» |
| add_executable(«component.name» src-gen/«compBaseFile».cpp«IF component.hasExternalCode» src/«compBaseFile»«CodeSkeleton.POSTFIX».cpp«ENDIF») |
| ament_target_dependencies(«component.name» «FOR msg_pkg : CreateCompPackageXML.calcDependencies(Collections.singletonList(component)) SEPARATOR " "»«msg_pkg»«ENDFOR») |
| # target_link_libraries(«component.name» ${catkin_LIBRARIES}) |
| |
| «ENDFOR» |
| «FOR component : components» |
| install(TARGETS |
| «component.name» |
| DESTINATION lib/${PROJECT_NAME} |
| ) |
| «ENDFOR» |
| «IF system !== null» |
| |
| # Install launch files. |
| install(DIRECTORY |
| launch |
| DESTINATION share/${PROJECT_NAME}/ |
| ) |
| «ENDIF» |
| ament_package() |
| ''' |
| |
| static def generate(IPFileSystemAccess fileAccess, Package pkg, List<Class> components, Class system) { |
| fileAccess.generateFile("CMakeLists.txt", createCMakeLists(pkg, components, system).toString) |
| } |
| } |