Skip to content

Commit

Permalink
Enable use of ign gazebo -s on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Silvio <silvio@traversaro.it>
  • Loading branch information
traversaro committed Aug 28, 2022
1 parent 25bdef6 commit 579addc
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 79 deletions.
32 changes: 26 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@ set (gtest_sources
TestFixture_TEST.cc
Util_TEST.cc
World_TEST.cc
ign_TEST.cc
comms/Broker_TEST.cc
comms/MsgManager_TEST.cc
network/NetworkConfig_TEST.cc
network/PeerTracker_TEST.cc
network/NetworkManager_TEST.cc
)

# ign_TEST and ModelCommandAPI_TEST are not supported with multi config
# CMake generators, see also cmd/CMakeLists.txt
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND gtest_sources ign_TEST.cc)
endif()


# Tests that require a valid display
set(tests_needing_display
ModelCommandAPI_TEST.cc
)

if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND tests_needing_display ModelCommandAPI_TEST.cc)
endif()

# Add systems that need a valid display here.
# \todo(anyone) Find a way to run these tests with a virtual display such Xvfb
# or Xdummy instead of skipping them
Expand Down Expand Up @@ -222,9 +232,19 @@ foreach(CMD_TEST
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT "${_env_vars}")

endforeach()
# On Windows there is no RPATH, so an alternative way for tests for finding .dll libraries
# in build directory in necessary. For regular tests, the trick is to place all libraries
# and executables in a common CMAKE_RUNTIME_OUTPUT_DIRECTORY, so that the .dll are found
# as they are in the same directory where the executable is loaded. For tests that are
# launched via ruby, this does not work, so we need to manually add CMAKE_RUNTIME_OUTPUT_DIRECTORY
# to the PATH. This is done via the ENVIRONMENT_MODIFICATION that is only available
# since CMake 3.22 . However, if an older CMake is used another trick to install the libraries
# beforehand
if (WIN32 AND CMAKE_VERSION STRGREATER "3.22")
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()

if(NOT WIN32)
add_subdirectory(cmd)
endif()
endforeach()

add_subdirectory(cmd)
121 changes: 69 additions & 52 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
# Generate the ruby script.
# Note that the major version of the library is included in the name.
# Ex: cmdgazebo0.rb
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured "${cmd_script_generated}.configured")
set(cmd_script_name "cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>_${cmd_script_name}")
set(cmd_script_configured "${CMAKE_CURRENT_BINARY_DIR}/${cmd_script_name}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "../../../${CMAKE_INSTALL_LIBDIR}/$<TARGET_FILE_NAME:${ign_lib_target}>")
if(WIN32)
set(plugin_location ${CMAKE_INSTALL_BINDIR})
else()
set(plugin_location ${CMAKE_INSTALL_LIBDIR})
endif()

set(library_location "../../../${plugin_location}/$<TARGET_FILE_NAME:${ign_lib_target}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
Expand All @@ -19,7 +26,7 @@ file(GENERATE
INPUT "${cmd_script_configured}")

# Install the ruby command line library in an unversioned location.
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition)
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition RENAME ${cmd_script_name})

set(ign_library_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

Expand All @@ -40,8 +47,9 @@ install( FILES
# Used for the installed model command version.
# Generate the ruby script that gets installed.
# Note that the major version of the library is included in the name.
set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured "${cmd_model_script_generated}.configured")
set(cmd_model_script_name "cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>_${cmd_model_script_name}")
set(cmd_model_script_configured "${CMAKE_CURRENT_BINARY_DIR}/${cmd_script_name}.configured")

configure_file(
"cmdmodel.rb.in"
Expand All @@ -51,7 +59,7 @@ file(GENERATE
OUTPUT "${cmd_model_script_generated}"
INPUT "${cmd_model_script_configured}")

install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition)
install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition RENAME ${cmd_model_script_name})

# Used for the installed version.
set(ign_model_ruby_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdmodel${PROJECT_VERSION_MAJOR}")
Expand All @@ -68,55 +76,64 @@ install(FILES ${model_configured} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_IN
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
# Ex: cmdgazebo0.rb
set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured_test "${cmd_script_generated_test}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "$<TARGET_FILE:${ign_lib_target}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")

# Used only for internal testing.
set(ign_library_path
"${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

# Generate a configuration file for internal testing.
# Note that the major version of the library is included in the name.
# Ex: gazebo0.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
# The logic is valid only for single-config CMake generators, so no script is
# generated if a multiple-config CMake geneator is used
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT GENERATOR_IS_MULTI_CONFIG)
set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured_test "${cmd_script_generated_test}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "$<TARGET_FILE:${ign_lib_target}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")

# Used only for internal testing.
set(ign_library_path
"${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

# Generate a configuration file for internal testing.
# Note that the major version of the library is included in the name.
# Ex: gazebo0.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
endif()

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition")
set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_model_script_generated_test}"
INPUT "${cmd_model_script_configured_test}")

# Used for internal testing.
set(ign_model_ruby_path "${cmd_model_script_generated_test}")

configure_file(
"model.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
# The logic is valid only for single-config CMake generators, so no script is
# generated if a multiple-config CMake geneator is used
if(NOT GENERATOR_IS_MULTI_CONFIG)
set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition")
set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_model_script_generated_test}"
INPUT "${cmd_model_script_configured_test}")

# Used for internal testing.
set(ign_model_ruby_path "${cmd_model_script_generated_test}")

configure_file(
"model.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
endif()

#===============================================================================
# Bash completion
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/ModelCommandAPI.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
*
*/

#include "ignition/gazebo/Export.hh"

/// \brief External hook to get a list of available models.
extern "C" void cmdModelList();
extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelList();

/// \brief External hook to dump model information.
/// \param[in] _modelName Model name.
/// \param[in] _pose --pose option.
/// \param[in] _linkName Link name.
/// \param[in] _jointName Joint name.
/// \param[in] _sensorName Sensor name.
extern "C" void cmdModelInfo(
extern "C" IGNITION_GAZEBO_VISIBLE void cmdModelInfo(
const char *_modelName, int _pose, const char *_linkName,
const char *_jointName,
const char *_sensorName);
Expand Down
16 changes: 15 additions & 1 deletion src/cmd/cmdgazebo.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end

require 'optparse'
require 'erb'
require 'pathname'

# Constants.
LIBRARY_NAME = '@library_location@'
Expand Down Expand Up @@ -337,7 +338,8 @@ class Cmd
def execute(args)
options = parse(args)

if LIBRARY_NAME[0] == '/'
library_name_path = Pathname.new(LIBRARY_NAME)
if library_name_path.absolute?
# If the first character is a slash, we'll assume that we've been given an
# absolute path to the library. This is only used during test mode.
plugin = LIBRARY_NAME
Expand Down Expand Up @@ -467,6 +469,12 @@ See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
exit(-1)
end

if plugin.end_with? ".dll"
puts "`ign gazebo` currently only works with the -s argument on Windows.
See https://github.com/gazebosim/gz-sim/issues/168 for more info."
exit(-1)
end

serverPid = Process.fork do
ENV['RMT_PORT'] = '1500'
Process.setpgid(0, 0)
Expand Down Expand Up @@ -526,6 +534,12 @@ See https://github.com/ignitionrobotics/ign-gazebo/issues/44 for more info."
exit(-1)
end

if plugin.end_with? ".dll"
puts "`ign gazebo` currently only works with the -s argument on Windows.
See https://github.com/gazebosim/gz-sim/issues/168 for more info."
exit(-1)
end

ENV['RMT_PORT'] = '1501'
Importer.runGui(options['gui_config'], options['file'],
options['wait_gui'], options['render_engine_gui'])
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/cmdmodel.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ else
end

require 'optparse'
require 'pathname'

# Constants.
LIBRARY_NAME = '@library_location@'
Expand Down Expand Up @@ -157,7 +158,8 @@ class Cmd
options = parse(args)

# Read the plugin that handles the command.
if LIBRARY_NAME[0] == '/'
library_name_path = Pathname.new(LIBRARY_NAME)
if library_name_path.absolute?
# If the first character is a slash, we'll assume that we've been given an
# absolute path to the library. This is only used during test mode.
plugin = LIBRARY_NAME
Expand Down
16 changes: 8 additions & 8 deletions src/ign.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@

/// \brief External hook to read the library version.
/// \return C-string representing the version. Ex.: 0.1.2
extern "C" char *ignitionGazeboVersion();
extern "C" IGNITION_GAZEBO_VISIBLE char *ignitionGazeboVersion();

/// \brief Get the Gazebo version header.
/// \return C-string containing the Gazebo version information.
extern "C" char *gazeboVersionHeader();
extern "C" IGNITION_GAZEBO_VISIBLE char *gazeboVersionHeader();

/// \brief Set verbosity level
/// \param[in] _verbosity 0 to 4
extern "C" void cmdVerbosity(
extern "C" IGNITION_GAZEBO_VISIBLE void cmdVerbosity(
const char *_verbosity);

extern "C" const char *worldInstallDir();
extern "C" IGNITION_GAZEBO_VISIBLE const char *worldInstallDir();

/// \brief External hook to run simulation server.
/// \param[in] _sdfString SDF file to run, as a string.
Expand All @@ -59,7 +59,7 @@ extern "C" const char *worldInstallDir();
/// \param[in] _headless True if server rendering should run headless
/// \param[in] _recordPeriod --record-period option
/// \return 0 if successful, 1 if not.
extern "C" int runServer(const char *_sdfString,
extern "C" IGNITION_GAZEBO_VISIBLE int runServer(const char *_sdfString,
int _iterations, int _run, float _hz, int _levels,
const char *_networkRole, int _networkSecondaries, int _record,
const char *_recordPath, int _recordResources, int _logOverwrite,
Expand All @@ -77,14 +77,14 @@ extern "C" int runServer(const char *_sdfString,
/// it receives a world path from GUI.
/// \param[in] _renderEngine --render-engine-gui option
/// \return 0 if successful, 1 if not.
extern "C" int runGui(const char *_guiConfig, const char *_file, int _waitGui,
const char *_renderEngine);
extern "C" IGNITION_GAZEBO_VISIBLE int runGui(const char *_guiConfig,
const char *_file, int _waitGui, const char *_renderEngine);

/// \brief External hook to find or download a fuel world provided a URL.
/// \param[in] _pathToResource Path to the fuel world resource, ie,
/// https://staging-fuel.ignitionrobotics.org/1.0/gmas/worlds/ShapesClone
/// \return C-string containing the path to the local world sdf file
extern "C" const char *findFuelResource(
extern "C" IGNITION_GAZEBO_VISIBLE const char *findFuelResource(
char *_pathToResource);

#endif
Loading

0 comments on commit 579addc

Please sign in to comment.