Skip to content

Commit

Permalink
Adding CMake dependencies and dds_dcps.idl
Browse files Browse the repository at this point in the history
  • Loading branch information
angelrti committed Jan 10, 2024
1 parent 6b98cd1 commit a6f6c89
Show file tree
Hide file tree
Showing 5 changed files with 691 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "rticonnextdds-cmake-utils"]
path = rticonnextdds-cmake-utils
url = https://github.com/rticommunity/rticonnextdds-cmake-utils
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# dds-datamodels-utils
This repository provides common files to all datamodel repositories, such as CMake files, idl files, etc...

This repository provides common files to all datamodel repositories, such as
CMake files, idl files, etc...
121 changes: 121 additions & 0 deletions cmake/ConnextDdsDatamodelsGenerateCode.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
###############################################################################
# (c) 2024 Copyright, Real-Time Innovations, Inc. (RTI) All rights reserved. #
# #
# RTI grants Licensee a license to use, modify, compile, and create #
# derivative works of the software solely for use with RTI Connext DDS. #
# Licensee may redistribute copies of the software provided that all such #
# copies are subject to this license. #
# The software is provided "as is", with no warranty of any type, including #
# any warranty for fitness for any purpose. RTI is under no obligation to #
# maintain or support the software. RTI shall not be liable for any #
# incidental or consequential damages arising out of the use or inability to #
# use the software. #
# #
###############################################################################

#[[
connextdds_datamodels_generate_code
-----------------------------------
This function calls rtiddsgen to all IDL files included in the INPUT_FOLDERS.
Then, this function returns the generated files.
Input parameters:
``INPUT_FOLDERS`` (mandatory)
Folder that contains the idl files to process.
``OUTPUT_FOLDER`` (mandatory)
Folder that will contain the generated files.
``LANG`` (optional)
The language that rtiddsgen will generate code for. Default: C++11
``IGNORE_IDL_NAMES`` (optional)
List of file names (without extension) that will be ignored and, therefore
rtiddsgen will not generate code for.
``IDL_DEPENDENCIES_FOLDERS`` (optional)
Folder that contains dependencies of the IDL files. For example if an IDL
file has an #include "file.idl", this variable should contain the folder
where file.idl is located.
``CODEGEN_EXTRA_ARGS`` (optional)
Additional flags for Codegen.
Output parameters:
``GENERATED_SRC_FILES``
List of all generated soruce files. The extension of these files depends
on the LANG input parameter.
* How to use it:
connextdds_datamodels_load_dependencies(
RTI_CMAKE_UTILS_BRANCH release/7.2.0
RTI_CMAKE_UTILS_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}"
DDS_DCPS_DIR "${CMAKE_CURRENT_BINARY_DIR}/dependencies/"
)
]]

function(connextdds_datamodels_generate_code)
set(_BOOLEANS)
set(_SINGLE_VALUE_ARGS OUTPUT_FOLDER LANG)
set(_MULTI_VALUE_ARGS
INPUT_FOLDERS IGNORE_IDL_NAMES IDL_DEPENDENCIES_FOLDERS CODEGEN_EXTRA_ARGS)

cmake_parse_arguments(_args
"${_BOOLEANS}"
"${_SINGLE_VALUE_ARGS}"
"${_MULTI_VALUE_ARGS}"
${ARGN}
)

if(NOT DEFINED _args_INPUT_FOLDERS)
message(FATAL_ERROR "Error in function connextdds_datamodels_generate_code() "
"The mandatory parameter INPUT_FOLDERS is not defined.")
endif()

if(NOT DEFINED _args_OUTPUT_FOLDER)
message(FATAL_ERROR "Error in function connextdds_datamodels_generate_code() "
"The mandatory parameter OUTPUT_FOLDER is not defined.")
endif()

if (NOT DEFINED _args_LANG)
set(_args_LANG C++11)
endif()

include(ConnextDdsCodegen)

# Get the name of all the idl files under datamodel/idl/
set(idl_files)
foreach(input_folder in ${_args_INPUT_FOLDERS})
file(GLOB idl_files_from_folder "${input_folder}/*.idl")
list(APPEND idl_files ${idl_files_from_folder})
endforeach()

foreach(input_folder in ${_args_IDL_DEPENDENCIES_FOLDERS})
file(GLOB idl_files_from_folder "${input_folder}/*.idl")
list(APPEND idl_files ${idl_files_from_folder})
endforeach()

cmake_policy(SET CMP0057 NEW)

# Call codegen to generate code for all IDL files
foreach(idl_file_path IN LISTS idl_files)
get_filename_component(idl_name ${idl_file_path} NAME_WE)
if(NOT idl_name IN_LIST _args_IGNORE_IDL_NAMES)
connextdds_rtiddsgen_run(
IDL_FILE "${idl_file_path}"
LANG ${_args_LANG}
OUTPUT_DIRECTORY "${_args_OUTPUT_FOLDER}"
INCLUDE_DIRS ${_args_IDL_DEPENDENCIES_FOLDERS}
EXTRA_ARGS ${_args_CODEGEN_EXTRA_ARGS}
)
list(APPEND src_files ${${idl_name}_CXX11_SOURCES})
endif()
endforeach()

set(GENERATED_SRC_FILES ${src_files} PARENT_SCOPE)

endfunction()
Loading

0 comments on commit a6f6c89

Please sign in to comment.