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

cmake_target_compile_definitions #6

Closed
wants to merge 8 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
60 changes: 59 additions & 1 deletion cli/robocompdsl/robocompdsl/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,62 @@ It is recommended that once you are done with the manual tests you make sure to
```shell script
python3 test_component_generation.py -c
```
to delete temporary files and not upload them to the repository.
to delete temporary files and not upload them to the repository.


# Tutorial: Making changes to robocompdsl templates

Imagina que recibes un encargo de tu jefe de modificar el código que genera robocompdsl.
Objetivo: Componentes en C++. Conseguir generar componentes en C++ que compilen correctamente
Cosas a corregir:
* CMakeList.txt
* cmake_minimum_required(VERSION 3.10)
* reemplazar SUBDIRS(src) por add_subdirectory(src)

Como se ha explicado anteriormente robocompdsl funciona con templates. En el directorio robocompdsl/robocompdsl/templates
podemos encontrar el directorio templateCPP que es el que nos interesa. En este directorio podemos encontrar los directorios
files y plugins. En el directorio files podemos encontrar los ficheros que se copian tal cual al componente generado.
En el directorio plugins podemos encontrar los ficheros que se utilizan para generar dinámicamente el código del componente.

Lo normal es empezar mirando en files y buscar el fichero que se quiere modificar, en este caso CMakeLists.txt
robocomp_tools/cli/robocompdsl/robocompdsl/templates/templateCPP/files/CMakeLists.txt
En este fichero podemos encontras las referencias que nos piden que cambienpor por ejemplo,
actualmente la cabecera del fichero tiene la declaración
```
cmake_minimum_required( VERSION 2.8 )
```
que nos piden que actualicemos a
```
cmake_minimum_required( VERSION 3.10 )
```
Con este simple cambio todos los componentes que se generen a partir de ahora llevarán en ese CMakelists.txt la versión 3.10

El siguiente cambio que nos piden es que en lugar de utilizar la función SUBDIRS(src) se utilice la función add_subdirectory(src)
Como podemos ver este es un cambio que de nuevo podemos hacer directamente en ese fichero.
```
SUBDIRS(src)
```
por
```
add_subdirectory(src)
```




> Lo más importante es cambiar la parte de la variable de entorno del cmake
```
IF ( "$ENV{ROBOCOMP}" STREQUAL "")
MESSAGE(WARNING "ROBOCOMP variable not set. Using the default value: /opt/robocomp")
SET (ENV{ROBOCOMP} "/opt/robocomp/")
ENDIF ( "$ENV{ROBOCOMP}" STREQUAL "")
```
> esto no coge la variable ROBOCOMP definida en .bashrc por algún motivo. El default ahora debería ser /home/robocomp/robocomp

Lo primero que deberías hacer es averiguar si el trozo de código que se quiere cambiar es de un componente en C++ o en Python.
En este caso podemos ver que es un trozo de código de CMake y se utiliza en ambos componentes.
Si hacemos una búsqueda por ejemplo de un trozo de ese código
`MESSAGE(WARNING "ROBOCOMP variable not set. Using the default value: /opt/robocomp")`
Veremos que aparece en variso sitios (entre otros ahora dentro de este tutorial), pero el que parece más interesante
ahora mismo es en el fichero `robocomp_tools/cli/robocompdsl/robocompdsl/templates/templateCPP/files/src/CMakeLists.txt`
```cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required( VERSION 2.8 )
cmake_minimum_required( VERSION 3.10 )
PROJECT( ${component_name} )

SET(RC_COMPONENT_PATH $${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "component base path" FORCE)
Expand All @@ -12,7 +12,7 @@ SET(RC_COMPONENT_INSTALL_PATH "/opt/robocomp" CACHE STRING "component install pa
#STRING(STRIP $${COMPONENT_NAME} COMPONENT_NAME)
#SET(COMPONENT_NAME $${COMPONENT_NAME} CACHE STRING "component name" FORCE)

SUBDIRS( src )
ADD_SUBDIRECTORY( src )

INSTALL(FILES etc/config DESTINATION $${RC_COMPONENT_INSTALL_PATH}/etc-default/ RENAME ${component_name}.conf )

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
# Use the latest policy behavior
cmake_policy(VERSION 3.10)

# Set the minimum version
cmake_minimum_required(VERSION 3.10)

# Project call
project(${component_name})

# Check for ROBOCOMP environment variable
if (DEFINED ENV{ROBOCOMP})
set(ROBOCOMP_WORKSPACE $$ENV{ROBOCOMP})
else()
message(WARNING "ROBOCOMP environment variable not set. Using the default value: /opt/robocomp")
set(ROBOCOMP_WORKSPACE "/opt/robocomp/")
endif()

IF ( "$$ENV{ROBOCOMP}" STREQUAL "")
MESSAGE(WARNING "ROBOCOMP variable not set. Using the default value: /opt/robocomp")
SET (ENV{ROBOCOMP} "/opt/robocomp/")
ENDIF ( "$$ENV{ROBOCOMP}" STREQUAL "")
# Check for RoboComp's existence
if(NOT EXISTS $${ROBOCOMP_WORKSPACE}/cmake)
message(FATAL_ERROR "Couldn't find RoboComp in $${ROBOCOMP_WORKSPACE}! Exiting...")
endif()

IF(NOT EXISTS $$ENV{ROBOCOMP}/cmake)
MESSAGE(FATAL_ERROR "Couldn't find RoboComp in $$ENV{ROBOCOMP}! Exiting...")
ENDIF(NOT EXISTS $$ENV{ROBOCOMP}/cmake)
# Include RoboComp and Qt cmake scripts
list(APPEND CMAKE_MODULE_PATH $${ROBOCOMP_WORKSPACE}/cmake)
include(robocomp)
include(modules/qt)

INCLUDE( $$ENV{ROBOCOMP}/cmake/robocomp.cmake )
INCLUDE( $$ENV{ROBOCOMP}/cmake/modules/qt.cmake )
INCLUDE ( CMakeListsSpecific.txt)
# Include the specific cmake list
include(CMakeListsSpecific.txt)

# Sources set
SET ( SOURCES
$${SOURCES}
$$ENV{ROBOCOMP}/classes/rapplication/rapplication.cpp
$$ENV{ROBOCOMP}/classes/sigwatch/sigwatch.cpp
$$ENV{ROBOCOMP}/classes/qlog/qlog.cpp
main.cpp
genericmonitor.cpp
commonbehaviorI.cpp
genericworker.cpp
${interface_sources}
${statemachine_visual_sources}
set(SOURCES
$${SOURCES}
$${ROBOCOMP_WORKSPACE}/classes/rapplication/rapplication.cpp
$${ROBOCOMP_WORKSPACE}/classes/sigwatch/sigwatch.cpp
main.cpp
genericmonitor.cpp
commonbehaviorI.cpp
genericworker.cpp
${interface_sources}
${statemachine_visual_sources}
)

add_library(${component_name}_lib STATIC $${SOURCES})
target_include_directories(${component_name}_lib PUBLIC $${CMAKE_CURRENT_SOURCE_DIR})

${cpp11_ice_packages}

${agm_includes}

#ROBOCOMP
ROBOCOMP_INITIALIZE( $$ENV{ROBOCOMP}/ )
# RoboComp initialize
ROBOCOMP_INITIALIZE( $${ROBOCOMP_WORKSPACE}/ )
${wrap_ice}
SET (EXECUTABLE_OUTPUT_PATH $${RC_COMPONENT_DEVEL_PATH}/bin)

${wrap_ui}

# Specify construction and link process
add_executable(${component_name} $${SOURCES} $${MOC_SOURCES} $${RC_SOURCES} $${UI_HEADERS})

# Link libraries
target_link_libraries(${component_name}
$${LIBS}
$${STATIC_LIBS}
$${SPECIFIC_LIBS}
$${QT_LIBRARIES}
$${Ice_LIBRARIES}
)

# Add compile options
# no-char8_t to avoid a problem with ICE Connection lib.
add_definitions(-g -fmax-errors=1 -fno-char8_t)
target_compile_options(${component_name} PRIVATE -g -fmax-errors=1 -fno-char8_t)
set_target_properties(${component_name} PROPERTIES
CXX_STANDARD 20
)

# Specify construction and link process
ADD_EXECUTABLE( ${component_name} $${SOURCES} $${MOC_SOURCES} $${RC_SOURCES} $${UI_HEADERS} )
TARGET_LINK_LIBRARIES( ${component_name} $${LIBS} $${STATIC_LIBS} $${SPECIFIC_LIBS} $${QT_LIBRARIES} $${Ice_LIBRARIES})
SET_TARGET_PROPERTIES(${component_name}
PROPERTIES
CXX_STANDARD 20
)
INSTALL(FILES $${EXECUTABLE_OUTPUT_PATH}/${component_name} DESTINATION $${RC_COMPONENT_INSTALL_PATH}/bin/ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
# Installation
install(TARGETS ${component_name} DESTINATION $${RC_COMPONENT_INSTALL_PATH}/bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GenericMonitor::setPeriod(int _period)
*/
void GenericMonitor::killYourSelf()
{
rDebug("Killing myself");
qDebug("Killing myself");
worker->killYourSelf();
emit kill();

Expand All @@ -94,7 +94,7 @@ RoboCompCommonBehavior::ParameterList GenericMonitor::getParameterList()
*/
void GenericMonitor::setParameterList(RoboCompCommonBehavior::ParameterList l)
{
rInfo("Changing configuration params");
qWarning("Changing configuration params");
sendParamsToWorker(l);
}

Expand Down Expand Up @@ -145,7 +145,6 @@ bool GenericMonitor::configGetString(Ice::CommunicatorPtr communicator, const st
if (list->contains(QString::fromStdString(value)) == false)
{
qFatal("Reading config file: %s is not a valid string", compound.c_str());
rError("Reading config file:"+compound+" is not a valid string");
}
QString error = QString("not valid configuration value");
qDebug() << error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <QtCore>
#include "genericworker.h"
#include "config.h"
#include <qlog/qlog.h>
#include <CommonBehavior.h>

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ GenericWorker::~GenericWorker()
}
void GenericWorker::killYourSelf()
{
rDebug("Killing myself");
qDebug("Killing myself");
emit kill();
}
/**
Expand All @@ -52,7 +52,7 @@ void GenericWorker::killYourSelf()
*/
void GenericWorker::setPeriod(int p)
{
rDebug("Period changed"+QString::number(p));
qDebug("Period changed"+QString::number(p));
Period = p;
timer.start(Period);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "config.h"
#include <stdint.h>
#include <qlog/qlog.h>
#include <QtCore>
${gui_includes}
${statemachine_includes}
#include <CommonBehavior.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@

#include <rapplication/rapplication.h>
#include <sigwatch/sigwatch.h>
#include <qlog/qlog.h>

#include "config.h"
#include "genericmonitor.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void SpecificMonitor::run()
ready = true;
forever
{
//rDebug("specific monitor run");
//qDebug("specific monitor run");
this->sleep(period);
}
}
Expand All @@ -51,14 +51,14 @@ void SpecificMonitor::run()
*/
void SpecificMonitor::initialize()
{
rInfo("Starting monitor ...");
qWarning("Starting monitor ...");
initialTime=QTime::currentTime();
RoboCompCommonBehavior::ParameterList params;
readPConfParams(params);
readConfig(params);
if(!sendParamsToWorker(params))
{
rError("Error reading config parameters. Exiting");
qCritical("Error reading config parameters. Exiting");
killYourSelf();
}
state = RoboCompCommonBehavior::State::Running;
Expand All @@ -75,7 +75,7 @@ bool SpecificMonitor::sendParamsToWorker(RoboCompCommonBehavior::ParameterList p
}
else
{
rError("Incorrect parameters");
qWarning("Incorrect parameters");
}
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define SPECIFICWORKER_H

#include <genericworker.h>
#include <doublebuffer/DoubleBuffer.h>
${dsr_includes}

class SpecificWorker : public GenericWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
cout << "[" << PROGRAM_NAME << "]: Exception creating proxy <NORMAL><PROXYNUMBER>: " << ex;
return EXIT_FAILURE;
}
rInfo("<NORMAL>Proxy<PROXYNUMBER> initialized Ok!");
qWarning("<NORMAL>Proxy<PROXYNUMBER> initialized Ok!");

"""

Expand Down
Loading