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

Make custom_validators accessible from external library #239

Open
christophfroehlich opened this issue Jan 22, 2025 · 5 comments
Open

Make custom_validators accessible from external library #239

christophfroehlich opened this issue Jan 22, 2025 · 5 comments

Comments

@christophfroehlich
Copy link
Collaborator

With #213 it is straightforward to use a complete cpp library within another package. But how can I use a custom_validator file from a different package?

Is there a smarter way to include the file from here to another library than

find_package(control_toolbox)
# get include dirs from control_toolbox for the custom validators
get_target_property(TB_INCLUDE_DIRS control_toolbox::rate_limiter_parameters INTERFACE_INCLUDE_DIRECTORIES)
generate_parameter_library(diff_drive_controller_parameters
  src/diff_drive_controller_parameter.yaml
  ${TB_INCLUDE_DIRS}/control_toolbox/custom_validators.hpp
)

@AugusteBourgois any suggestions?
Changing the macro here to avoid a COPY but just use the correct include path control_toolbox/custom_validators.hpp?

if(${ARGC} EQUAL 3)
cmake_path(SET IN_VALIDATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR})
cmake_path(APPEND IN_VALIDATE_HEADER ${ARGV2})
cmake_path(GET IN_VALIDATE_HEADER FILENAME VALIDATE_HEADER_FILENAME)
cmake_path(SET VALIDATE_HEADER ${LIB_INCLUDE_DIR})
cmake_path(APPEND VALIDATE_HEADER ${VALIDATE_HEADER_FILENAME})
# Copy the header file into the include directory
file(COPY ${IN_VALIDATE_HEADER} DESTINATION ${LIB_INCLUDE_DIR})
# necessary so that #include <param_file.hpp> can be used in the local package (deprecated)
file(COPY ${IN_VALIDATE_HEADER} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include)
endif()

@pac48
Copy link
Collaborator

pac48 commented Feb 3, 2025

@christophfroehlich I think inserting the include directly as specified, e.g. <control_toolbox/custom_validators.hpp> makes the most sense. That way, you can call target_include_directories or target_link_libraries on the generated target to make sure your custom header is in the included paths. For now, maybe the file should still be copied if the relative path exists, but otherwise, just insert it in the generated code anyway.

@AugusteBourgois
Copy link
Contributor

@christophfroehlich to be sure I understand you problem correctly :

  • You have two packages, A and B.
  • You want to generate the parameter files in A, i.e. your .yaml config file is located there, and you call generate_parameter_library from A's CMakeLists.txt
  • You have a custom validator, i.e. a .hpp file located in B, which you want to use in A's .yaml file.

Am I correct ?

@christophfroehlich
Copy link
Collaborator Author

exactly 🤔

@AugusteBourgois
Copy link
Contributor

AugusteBourgois commented Feb 4, 2025

@pac48 do you mean you could write in A's CMakeLists.txt :

find_package(B REQUIRED)

generate_parameter_library(my_parameters_target
src/my_parameters_definition.yaml
B/custom_validator.hpp
)
target_link_libraries(my_parameters_target B::custom_validator)

@pac48
Copy link
Collaborator

pac48 commented Feb 4, 2025

@AugusteBourgois That looks right. I think one additional step would be to ensure custom_validator.hpp is installed by B in its CMake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants