Skip to content

Commit

Permalink
Fix for binary relocatability
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Nov 21, 2022
1 parent 6bc33a2 commit 0ac1a4e
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 11 deletions.
48 changes: 48 additions & 0 deletions include/ignition/gazebo/config.hh.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/* Config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */

#ifndef IGNITION_${GZ_DESIGNATION_UPPER}_CONFIG_HH_
#define IGNITION_${GZ_DESIGNATION_UPPER}_CONFIG_HH_

#include <ignition/gazebo/Export.hh>

#include <string>

/* Version number */
#define IGNITION_GAZEBO_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
#define IGNITION_GAZEBO_MINOR_VERSION ${PROJECT_VERSION_MINOR}
Expand All @@ -19,8 +26,49 @@
#define IGN_GAZEBO_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
#define IGN_GAZEBO_GUI_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/gui"
#define IGN_GAZEBO_WORLD_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR}/worlds"

#define IGNITION_GAZEBO_GUI_CONFIG_RELATIVE_PATH "${IGN_DATA_INSTALL_DIR}/gui"
#define IGNITION_GAZEBO_SYSTEM_CONFIG_RELATIVE_PATH "${IGN_DATA_INSTALL_DIR}/systems"
#define IGNITION_GAZEBO_SERVER_CONFIG_RELATIVE_PATH "${IGN_DATA_INSTALL_DIR}"
#define IGN_GAZEBO_PLUGIN_RELATIVE_INSTALL_DIR "${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
#define IGN_GAZEBO_GUI_PLUGIN_RELATIVE_INSTALL_DIR "${IGN_LIB_INSTALL_DIR}/ign-${IGN_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/gui"
#define IGN_GAZEBO_WORLD_RELATIVE_INSTALL_DIR "${IGN_DATA_INSTALL_DIR}/worlds"



#define GZ_DISTRIBUTION "${GZ_DISTRIBUTION}"

#cmakedefine IGNITION_GAZEBO_BUILD_TYPE_PROFILE 1
#cmakedefine IGNITION_GAZEBO_BUILD_TYPE_DEBUG 1
#cmakedefine IGNITION_GAZEBO_BUILD_TYPE_RELEASE 1

namespace ignition
{
namespace gazebo
{
/// \brief getInstallPrefix return the install prefix of the library
/// i.e. CMAKE_INSTALL_PREFIX unless the library has been moved
IGNITION_GAZEBO_VISIBLE std::string getInstallPrefix();

/// \brief getGUIConfigPath return the GUI config path
IGNITION_GAZEBO_VISIBLE std::string getGUIConfigPath();

/// \brief getSystemConfigPath return the system config path
IGNITION_GAZEBO_VISIBLE std::string getSystemConfigPath();

/// \brief getServerConfigPath return the server config path
IGNITION_GAZEBO_VISIBLE std::string getServerConfigPath();

/// \brief getPluginInstallDir return the plugin install dir
IGNITION_GAZEBO_VISIBLE std::string getPluginInstallDir();

/// \brief getGUIPluginInstallDir return the GUI plugin install dir
IGNITION_GAZEBO_VISIBLE std::string getGUIPluginInstallDir();

/// \brief getWorldInstallDir return the world install dir
IGNITION_GAZEBO_VISIBLE std::string getWorldInstallDir();
}
}


#endif
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set (sources
View.cc
World.cc
cmd/ModelCommandAPI.cc
config.cc
${PROTO_PRIVATE_SRC}
${network_sources}
${comms_sources}
Expand Down Expand Up @@ -152,6 +153,8 @@ target_link_libraries(${ign_lib_target}

# Create the library target
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 17)
ign_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION ignition::gazebo::getInstallPrefix)

target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
ignition-math${IGN_MATH_VER}
Expand Down
2 changes: 1 addition & 1 deletion src/ServerConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ gazebo::loadPluginInfo(bool _isPlayback)
if (!common::exists(defaultConfig))
{
auto installedConfig = common::joinPaths(
IGNITION_GAZEBO_SERVER_CONFIG_PATH,
getServerConfigPath(),
configFilename);

if (!common::createDirectories(defaultConfigDir))
Expand Down
2 changes: 1 addition & 1 deletion src/SystemLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ignition::gazebo::SystemLoaderPrivate
ignition::common::env(IGN_HOMEDIR, homePath);
systemPaths.AddPluginPaths(common::joinPaths(
homePath, ".ignition", "gazebo", "plugins"));
systemPaths.AddPluginPaths(IGN_GAZEBO_PLUGIN_INSTALL_DIR);
systemPaths.AddPluginPaths(getPluginInstallDir());

return systemPaths.PluginPaths();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ std::string resolveSdfWorldFile(const std::string &_sdfFile,
systemPaths.SetFilePathEnv(kResourcePathEnv);

// Worlds installed with ign-gazebo
systemPaths.AddFilePaths(IGN_GAZEBO_WORLD_INSTALL_DIR);
systemPaths.AddFilePaths(getWorldInstallDir());

filePath = systemPaths.FindFile(_sdfFile);
}
Expand Down
76 changes: 76 additions & 0 deletions src/config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <ignition/gazebo/config.hh>

#include <filesystem>

namespace ignition
{
namespace gazebo
{

std::string getGUIConfigPath()
{
std::filesystem::path relative_ret_path(IGNITION_GAZEBO_GUI_CONFIG_RELATIVE_PATH);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

std::string getSystemConfigPath()
{
std::filesystem::path relative_ret_path(IGNITION_GAZEBO_SYSTEM_CONFIG_RELATIVE_PATH);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

std::string getServerConfigPath()
{
std::filesystem::path relative_ret_path(IGNITION_GAZEBO_SERVER_CONFIG_RELATIVE_PATH);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

std::string getPluginInstallDir()
{
std::filesystem::path relative_ret_path(IGN_GAZEBO_PLUGIN_RELATIVE_INSTALL_DIR);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

std::string getGUIPluginInstallDir()
{
std::filesystem::path relative_ret_path(IGN_GAZEBO_GUI_PLUGIN_RELATIVE_INSTALL_DIR);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

std::string getWorldInstallDir()
{
std::filesystem::path relative_ret_path(IGN_GAZEBO_WORLD_RELATIVE_INSTALL_DIR);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path ret_path = install_prefix / relative_ret_path;
return ret_path.string();
}

}
}
7 changes: 4 additions & 3 deletions src/gui/Gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::string defaultGuiConfigFile(bool _isPlayback,
}

auto installedConfig = common::joinPaths(
IGNITION_GAZEBO_GUI_CONFIG_PATH, defaultGuiConfigName);
getGUIConfigPath(), defaultGuiConfigName);
if (!common::copyFile(installedConfig, defaultConfig))
{
ignerr << "Failed to copy installed config [" << installedConfig
Expand Down Expand Up @@ -268,7 +268,7 @@ std::unique_ptr<ignition::gui::Application> createGui(
auto app = std::make_unique<ignition::gui::Application>(
_argc, _argv, ignition::gui::WindowType::kMainWindow);

app->AddPluginPath(IGN_GAZEBO_GUI_PLUGIN_INSTALL_DIR);
app->AddPluginPath(getGUIPluginInstallDir());

auto aboutDialogHandler = new ignition::gazebo::gui::AboutDialogHandler();
aboutDialogHandler->setParent(app->Engine());
Expand All @@ -280,7 +280,8 @@ std::unique_ptr<ignition::gui::Application> createGui(
pathManager->setParent(app->Engine());

// add import path so we can load custom modules
app->Engine()->addImportPath(IGN_GAZEBO_GUI_PLUGIN_INSTALL_DIR);
std::string gui_plugin_install_dir = getGUIPluginInstallDir();
app->Engine()->addImportPath(gui_plugin_install_dir.c_str());

app->SetDefaultConfigPath(defaultConfig);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/QuickStartHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class IGNITION_GAZEBO_GUI_VISIBLE QuickStartHandler : public QObject
private: std::string worldsPath{IGN_GAZEBO_WORLD_INSTALL_DIR};

/// \brief Get starting world url.
private: std::string startingWorld{""};
private: std::string startingWorld{getWorldInstallDir()};
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ extern "C" void cmdVerbosity(
//////////////////////////////////////////////////
extern "C" const char *worldInstallDir()
{
return IGN_GAZEBO_WORLD_INSTALL_DIR;
static std::string worldInstallDir = getWorldInstallDir();
return worldInstallDir.c_str();
}

//////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/systems/physics/EntityFeatureMap_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EntityFeatureMapFixture: public InternalFixture<::testing::Test>
const std::string pluginLib = "libignition-physics-dartsim-plugin.so";

common::SystemPaths systemPaths;
systemPaths.AddPluginPaths({IGNITION_PHYSICS_ENGINE_INSTALL_DIR});
systemPaths.AddPluginPaths(ignition::physics::getEngineInstallDir());

auto pathToLib = systemPaths.FindSharedLibrary(pluginLib);
ASSERT_FALSE(pathToLib.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/systems/physics/Physics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ void Physics::Configure(const Entity &_entity,
// * Engines installed with ign-physics
common::SystemPaths systemPaths;
systemPaths.SetPluginPathEnv(this->dataPtr->pluginPathEnv);
systemPaths.AddPluginPaths({IGNITION_PHYSICS_ENGINE_INSTALL_DIR});
systemPaths.AddPluginPaths(ignition::physics::getEngineInstallDir());

auto pathToLib = systemPaths.FindSharedLibrary(pluginLib);
if (pathToLib.empty())
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tracked_vehicle_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TrackedVehicleTest : public InternalFixture<::testing::Test>
// modifications)
common::SystemPaths systemPaths;
systemPaths.SetPluginPathEnv("IGN_GAZEBO_PHYSICS_ENGINE_PATH");
systemPaths.AddPluginPaths({IGNITION_PHYSICS_ENGINE_INSTALL_DIR});
systemPaths.AddPluginPaths(ignition::physics::getEngineInstallDir());

auto pathToLib = systemPaths.FindSharedLibrary(*pluginLib);
ASSERT_FALSE(pathToLib.empty())
Expand Down

0 comments on commit 0ac1a4e

Please sign in to comment.