Skip to content

Commit 04e4b7f

Browse files
committed
Add GENERATE_PARSER_OUTPUT_DIR argument to yarp_prepare_plugin function
This parameter can be used to (optionally) generate the files related to device param parser in an arbitrary location. This is tipically used to generate the files in the build directory instead of the source one, removing the need of committing generate files in the repo.
1 parent 8300e52 commit 04e4b7f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cmake/YarpDeviceParamsParserGenerator.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ function(generateDeviceParamsParser_fromIniFile CLASSNAME DEVICENAME FILEINI EXT
5555
generateDeviceParamsParser_commandline (${COMMAND})
5656
endfunction()
5757

58+
# If an additional argument is specified, it is considered the OUTPUTDIR
5859
function(generateDeviceParamsParser CLASSNAME DEVICENAME)
60+
if (NOT ARGN)
61+
set (OUTPUTDIR ${CMAKE_CURRENT_SOURCE_DIR})
62+
else ()
63+
set (OUTPUTDIR ${ARGN})
64+
endif ()
5965
set (INPUTFILENAME_INI "${CMAKE_CURRENT_SOURCE_DIR}/${CLASSNAME}_params.ini")
6066
set (INPUTFILENAME_MD "${CMAKE_CURRENT_SOURCE_DIR}/${CLASSNAME}_params.md")
6167
set (INPUTFILENAME_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/${CLASSNAME}_params_extracomments.md")
6268

6369
if (EXISTS ${INPUTFILENAME_INI})
64-
set (COMMAND "--class_name ${CLASSNAME} --module_name ${DEVICENAME} --input_filename_ini ${INPUTFILENAME_INI}")
70+
set (COMMAND "--class_name ${CLASSNAME} --module_name ${DEVICENAME} --input_filename_ini ${INPUTFILENAME_INI} --output_dir ${OUTPUTDIR}")
6571
elseif (EXISTS ${INPUTFILENAME_MD})
66-
set (COMMAND "--class_name ${CLASSNAME} --module_name ${DEVICENAME} --input_filename_md ${INPUTFILENAME_MD}")
72+
set (COMMAND "--class_name ${CLASSNAME} --module_name ${DEVICENAME} --input_filename_md ${INPUTFILENAME_MD} --output_dir ${OUTPUTDIR}")
6773
else()
6874
message(FATAL_ERROR "Cannot find input file ${INPUTFILENAME_INI} or ${INPUTFILENAME_MD}")
6975
endif()

cmake/YarpPlugin.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ endmacro()
170170
# [ADVANCED]
171171
# [INTERNAL]
172172
# [GENERATE_PARSER]
173+
# [GENERATE_PARSER_OUTPUT_DIR <output_dir>]
173174
# [DEPENDS <condition>]
174175
# [TEMPLATE <file_name|path_to_a_file>]
175176
# [TEMPLATE_DIR <dir>]
@@ -221,6 +222,8 @@ endmacro()
221222
# CMake.
222223
# If the ``GENERATE_PARSER`` option is enabled, a parameter parser will be generated
223224
# for the plugin. See documentation of: generateDeviceParamsParser()
225+
# If the ``GENERATE_PARSER_OUTPUT_DIR`` parameter is passed and ``GENERATE_PARSER`` option is enabled,
226+
# the file generated by ``GENERATE_PARSER`` will be placed in the specified directory.
224227
# If the ``INTERNAL`` option is enabled, this option is marked as internal in
225228
# CMake, and therefore not displayed in CMake gui. This also implies
226229
# `DEFAULT=ON` unless explicitly specified.
@@ -265,6 +268,7 @@ macro(YARP_PREPARE_PLUGIN _plugin_name)
265268
DEFAULT
266269
TEMPLATE
267270
TEMPLATE_DIR
271+
GENERATE_PARSER_OUTPUT_DIR
268272
)
269273
set(_multiValueArgs
270274
DEPENDS
@@ -572,9 +576,12 @@ YARP_DEFINE_SHARED_SUBCLASS(\@YARPPLUG_NAME\@, \@YARPPLUG_TYPE\@, \@YARPPLUG_PAR
572576
endif()
573577

574578
if (NOT SKIP_${_plugin_name})
579+
if(NOT _YPP_GENERATE_PARSER_OUTPUT_DIR)
580+
set(_YPP_GENERATE_PARSER_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
581+
endif()
575582
if(_YPP_GENERATE_PARSER)
576583
message ("Invoking generateDeviceParamsParser (${_YPP_TYPE} ${_plugin_name})")
577-
generateDeviceParamsParser(${_YPP_TYPE} ${_plugin_name})
584+
generateDeviceParamsParser(${_YPP_TYPE} ${_plugin_name} ${_YPP_GENERATE_PARSER_OUTPUT_DIR})
578585
endif()
579586
endif()
580587
endmacro()

0 commit comments

Comments
 (0)