Skip to content

Commit

Permalink
Standalone gz sdf executable (#1539)
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
Signed-off-by: Saurabh Kamat <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Co-authored-by: Steve Peters <[email protected]>
Co-authored-by: Addisu Z. Taddese <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
4 people authored Mar 5, 2025
1 parent bf054f0 commit 1668f31
Show file tree
Hide file tree
Showing 11 changed files with 717 additions and 672 deletions.
36 changes: 18 additions & 18 deletions sdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ endif()
# Generate aggregated SDF description files for use by the sdformat.org
# website. If the description files change, the generated full*.sdf files need
# to be removed before running this target.
if (GZ_PROGRAM)

# Update this list as new sdformat spec versions are added.
set(sdf_desc_versions 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12)
# Update this list as new sdformat spec versions are added.
set(sdf_desc_versions 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12)

set(description_targets)
foreach(desc_ver ${sdf_desc_versions})
string(REPLACE "." "-" desc_ver_dash ${desc_ver})
list(APPEND description_targets ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf
COMMAND
${CMAKE_COMMAND} -E env GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>
${GZ_PROGRAM}
ARGS sdf -d ${desc_ver} > ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf
COMMENT "Generating full description for spec ${desc_ver}"
VERBATIM)
endforeach()
add_custom_target(sdf_descriptions DEPENDS ${description_targets} ${PROJECT_LIBRARY_TARGET_NAME})
endif()
set(description_targets)
foreach(desc_ver ${sdf_desc_versions})
string(REPLACE "." "-" desc_ver_dash ${desc_ver})
list(APPEND description_targets ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf
COMMAND
${CMAKE_COMMAND} -E env GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>
$<TARGET_FILE:gz-sdformat-sdf>
ARGS sdf -d ${desc_ver} > ${CMAKE_CURRENT_BINARY_DIR}/full_${desc_ver_dash}.sdf
COMMENT "Generating full description for spec ${desc_ver}"
VERBATIM)
endforeach()
add_custom_target(sdf_descriptions DEPENDS ${description_targets})
# Add a dependency on the gz-sdformat-sdf target which is created in in ../cmd/CMakeLists
add_dependencies(sdf_descriptions gz-sdformat-sdf)
12 changes: 0 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ target_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
)

if (BUILD_TESTING)
# Build this test file only if Gazebo Tools is installed.
if (NOT GZ_PROGRAM)
list(REMOVE_ITEM gtest_sources gz_TEST.cc)
endif()

add_library(library_for_tests OBJECT
Converter.cc
EmbeddedSdf.cc
Expand Down Expand Up @@ -120,13 +115,6 @@ if (BUILD_TESTING)
ENVIRONMENT
SDF_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

if (TARGET UNIT_gz_TEST)
target_compile_definitions(UNIT_gz_TEST PRIVATE
-DGZ_PATH="${GZ_PROGRAM}"
-DDETAIL_GZ_CONFIG_PATH="${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
-DGZ_TEST_LIBRARY_PATH="${PROJECT_BINARY_DIR}/src")
endif()
endif()

add_subdirectory(cmd)
48 changes: 43 additions & 5 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
# Build sdf CLI executable
set(sdf_executable gz-sdformat-sdf)
add_executable(${sdf_executable} sdf_main.cc gz.cc ../FrameSemantics.cc)
target_link_libraries(${sdf_executable}
gz-utils${GZ_UTILS_VER}::cli
${PROJECT_LIBRARY_TARGET_NAME}
TINYXML2::TINYXML2
)
install(
TARGETS ${sdf_executable}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/gz/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}/
)

# Build the unit tests only if Gazebo tools is installed
if(BUILD_TESTING AND GZ_PROGRAM)
gz_build_tests(TYPE UNIT
SOURCES
gz_TEST.cc
INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/test
TEST_LIST
test_list
LIB_DEPS
gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER}
${EXTRA_TEST_LIB_DEPS}
ENVIRONMENT
SDF_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

if(TARGET UNIT_gz_TEST)
target_compile_definitions(UNIT_gz_TEST
PRIVATE
"GZ_PATH=\"${GZ_PROGRAM}\""
"DETAIL_GZ_CONFIG_PATH=\"${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>\""
"GZ_TEST_LIBRARY_PATH=\"$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>\""
)
endif()
endif()

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
# Ex: cmdsdformat0.rb
set(cmd_script_generated_test
set(cmd_script_generated_test
"${CMAKE_BINARY_DIR}/test/lib/$<CONFIG>/ruby/gz/cmd${PROJECT_NAME}.rb")
set(cmd_script_configured_test
set(cmd_script_configured_test
"${CMAKE_CURRENT_BINARY_DIR}/test_cmd${PROJECT_NAME}.rb.configured")

# Set the library_location variable to the full path of the library file within
# the build directory.
set(library_location "$<TARGET_FILE:${PROJECT_NAME}>")
set(library_location "$<TARGET_FILE:${sdf_executable}>")

configure_file(
"cmd${PROJECT_NAME_NO_VERSION_LOWER}.rb.in"
Expand All @@ -20,7 +59,6 @@ file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")


#===============================================================================
# Used for the installed version.
# Generate the ruby script that gets installed.
Expand All @@ -37,7 +75,7 @@ else()
set(library_location_prefix "${CMAKE_INSTALL_LIBDIR}")
endif()

set(library_location "../../../${library_location_prefix}/$<TARGET_FILE_NAME:${PROJECT_NAME}>")
set(library_location "../../../${CMAKE_INSTALL_LIBEXECDIR}/gz/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}/$<TARGET_FILE_NAME:${sdf_executable}>")

configure_file(
"cmd${PROJECT_NAME_NO_VERSION_LOWER}.rb.in"
Expand Down
Loading

0 comments on commit 1668f31

Please sign in to comment.