Skip to content

Commit

Permalink
Enable binary relocatability
Browse files Browse the repository at this point in the history
Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
  • Loading branch information
traversaro committed Jan 16, 2023
1 parent 41be240 commit 2d00d80
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 17 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ if (OGRE2_FOUND)
endif()

# Plugin install dirs
set(IGNITION_RENDERING_ENGINE_RELATIVE_INSTALL_DIR
${IGN_LIB_INSTALL_DIR}/ign-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/engine-plugins
)
set(IGNITION_RENDERING_ENGINE_INSTALL_DIR
${CMAKE_INSTALL_PREFIX}/${IGN_LIB_INSTALL_DIR}/ign-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/engine-plugins
${CMAKE_INSTALL_PREFIX}/${IGNITION_RENDERING_ENGINE_RELATIVE_INSTALL_DIR}
)

#--------------------------------------
Expand Down Expand Up @@ -147,7 +150,8 @@ else()
set(IGN_RENDERING_PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
endif()

set(IGN_RENDERING_RESOURCE_PATH ${CMAKE_INSTALL_PREFIX}/${IGN_DATA_INSTALL_DIR})
set(IGN_RENDERING_RELATIVE_RESOURCE_PATH ${IGN_DATA_INSTALL_DIR})
set(IGN_RENDERING_RESOURCE_PATH ${CMAKE_INSTALL_PREFIX}/${IGN_RENDERING_RELATIVE_RESOURCE_PATH})

#============================================================================
# Configure the build
Expand Down
46 changes: 46 additions & 0 deletions include/ignition/rendering/InstallationDirectories.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2023 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.
*
*/

#ifndef IGNITION_RENDERING_INSTALLATION_DIRECTORIES_HH_
#define IGNITION_RENDERING_INSTALLATION_DIRECTORIES_HH_

#include <string>

#include <ignition/rendering/config.hh>
#include <ignition/rendering/Export.hh>

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

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

/// \brief getResourcePath return the resource path
IGNITION_RENDERING_VISIBLE std::string getResourcePath();

/// \brief getEngineInstallDir return the install directory of the engines
IGNITION_RENDERING_VISIBLE std::string getEngineInstallDir();

}
}
}

#endif
11 changes: 11 additions & 0 deletions include/ignition/rendering/config.hh.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* Config.hh. Generated by CMake for @PROJECT_NAME@. */

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

/* Version number */
#define IGNITION_RENDERING_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
#define IGNITION_RENDERING_MINOR_VERSION ${PROJECT_VERSION_MINOR}
Expand All @@ -12,10 +15,16 @@

#define IGNITION_RENDERING_VERSION_HEADER "Ignition ${IGN_PROJECT_NAME}, version ${PROJECT_VERSION_FULL}\nCopyright (C) 2014 Open Source Robotics Foundation.\nReleased under the Apache 2.0 License.\n\n"

// Deprecated: use ignition::rendering::getResourcePath() instead
#define IGN_RENDERING_RESOURCE_PATH "${IGN_RENDERING_RESOURCE_PATH}"

#define IGN_RENDERING_RELATIVE_RESOURCE_PATH "${IGN_RENDERING_RELATIVE_RESOURCE_PATH}"

// Deprecated: use ignition::rendering::getEngineInstallDir() instead
#define IGNITION_RENDERING_ENGINE_INSTALL_DIR "${IGNITION_RENDERING_ENGINE_INSTALL_DIR}"

#define IGNITION_RENDERING_ENGINE_RELATIVE_INSTALL_DIR "${IGNITION_RENDERING_ENGINE_RELATIVE_INSTALL_DIR}"

#cmakedefine BUILD_TYPE_PROFILE 1
#cmakedefine BUILD_TYPE_DEBUG 1
#cmakedefine BUILD_TYPE_RELEASE 1
Expand All @@ -24,3 +33,5 @@
#cmakedefine HAVE_OPTIX 1
#cmakedefine HAVE_GAZEBO 1
#cmakedefine INCLUDE_RTSHADER 1

#endif
1 change: 0 additions & 1 deletion ogre/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ find_package(OpenGL)
set_property(
SOURCE OgreRenderEngine.cc OgreRTShaderSystem.cc OgreGpuRays.cc OgreMaterial.cc OgreDepthCamera.cc OgreThermalCamera.cc
PROPERTY COMPILE_DEFINITIONS
IGN_RENDERING_RESOURCE_PATH="${IGN_RENDERING_RESOURCE_PATH}"
OGRE_RESOURCE_PATH="${OGRE_RESOURCE_PATH}"
)

Expand Down
1 change: 1 addition & 0 deletions ogre/src/OgreCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/ogre/OgreCamera.hh"
#include "ignition/rendering/ogre/OgreConversions.hh"
#include "ignition/rendering/ogre/OgreIncludes.hh"
Expand Down
3 changes: 2 additions & 1 deletion ogre/src/OgreDepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <windows.h>
#endif
#include <ignition/math/Helpers.hh>
#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/ogre/OgreDepthCamera.hh"
#include "ignition/rendering/ogre/OgreMaterial.hh"

Expand Down Expand Up @@ -210,7 +211,7 @@ void OgreDepthCamera::CreatePointCloudTexture()

const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();

// path to look for vertex and fragment shader parameters
std::string pcdVSPath = common::joinPaths(
Expand Down
3 changes: 2 additions & 1 deletion ogre/src/OgreMaterial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>

#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/ShaderParams.hh"
#include "ignition/rendering/ogre/OgreMaterial.hh"
#include "ignition/rendering/ogre/OgreConversions.hh"
Expand Down Expand Up @@ -662,7 +663,7 @@ void OgreMaterial::SetDepthMaterial(const double _far,
// Get shader parameters path
const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();

// path to look for vertex and fragment shader parameters
std::string depth_vertex_shader_path = common::joinPaths(
Expand Down
4 changes: 2 additions & 2 deletions ogre/src/OgreRTShaderSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>

#include "ignition/rendering/config.hh"
#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/ogre/OgreRenderEngine.hh"
#include "ignition/rendering/ogre/OgreScene.hh"
#include "ignition/rendering/ogre/OgreMaterial.hh"
Expand Down Expand Up @@ -487,7 +487,7 @@ bool OgreRTShaderSystem::Paths(std::string &coreLibsPath,
{
const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();

// path to look for ogre media files
std::vector<std::string> paths;
Expand Down
3 changes: 2 additions & 1 deletion ogre/src/OgreRenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>

#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/RenderEngineManager.hh"
#include "ignition/rendering/ogre/OgreIncludes.hh"
#include "ignition/rendering/ogre/OgreRenderEngine.hh"
Expand Down Expand Up @@ -562,7 +563,7 @@ void OgreRenderEngine::CreateResources()
std::list<std::string> paths;
const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();
// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre", "media");
paths.push_back(mediaPath);
Expand Down
1 change: 0 additions & 1 deletion ogre2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ add_definitions(-DOGRE_IGNORE_UNKNOWN_DEBUG)
set_property(
SOURCE Ogre2RenderEngine.cc
PROPERTY COMPILE_DEFINITIONS
IGN_RENDERING_RESOURCE_PATH="${IGN_RENDERING_RESOURCE_PATH}"
OGRE2_RESOURCE_PATH="${OGRE2_RESOURCE_PATH}"
OGRE2_VERSION="${OGRE2_VERSION}"
)
Expand Down
5 changes: 3 additions & 2 deletions ogre2/src/Ogre2RenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <ignition/plugin/Register.hh>

#include "ignition/rendering/GraphicsAPI.hh"
#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/RenderEngineManager.hh"
#include "ignition/rendering/ogre2/Ogre2Includes.hh"
#include "ignition/rendering/ogre2/Ogre2RenderEngine.hh"
Expand Down Expand Up @@ -672,7 +673,7 @@ void Ogre2RenderEngine::RegisterHlms()
{
const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();
// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre2", "media");
if (!common::exists(mediaPath))
Expand Down Expand Up @@ -861,7 +862,7 @@ void Ogre2RenderEngine::CreateResources()
{
const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();
// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre2", "media");
if (!common::exists(mediaPath))
Expand Down
2 changes: 0 additions & 2 deletions optix/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ set(cuda_sources

set_property(
SOURCE OptixRenderEngine.cc
PROPERTY COMPILE_DEFINITIONS
IGN_RENDERING_RESOURCE_PATH="${IGN_RENDERING_RESOURCE_PATH}"
)

target_link_libraries(${optix_target}
Expand Down
2 changes: 1 addition & 1 deletion optix/src/OptixRenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::string OptixRenderEngine::PtxFile(const std::string& _fileBase) const

const char *env= std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();
resourcePath = common::joinPaths(resourcePath, "optix");
folders.push_back(resourcePath);

Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ endif()

# Create the library target.
ign_create_core_library(SOURCES ${sources} CXX_STANDARD 17)
ign_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION ignition::rendering::getInstallPrefix
GET_INSTALL_PREFIX_HEADER ignition/rendering/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE IGN_RENDERING_INSTALL_PREFIX)

# Include the interface directories that we always need.
#ign_target_interface_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
Expand All @@ -45,4 +48,5 @@ endif()

# Build the unit tests.
ign_build_tests(TYPE UNIT SOURCES ${gtest_sources})
ENVIRONMENT IGN_RENDERING_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

47 changes: 47 additions & 0 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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/rendering/config.hh>
#include <ignition/rendering/InstallationDirectories.hh>

#include <filesystem>

namespace ignition
{
namespace rendering
{
inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {

std::string getResourcePath()
{
std::filesystem::path relative_resource_path(IGN_RENDERING_RELATIVE_RESOURCE_PATH);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path resource_path = install_prefix / relative_resource_path;
return resource_path.string();
}

std::string getEngineInstallDir()
{
std::filesystem::path engine_relative_install_dir(IGNITION_RENDERING_ENGINE_RELATIVE_INSTALL_DIR);
std::filesystem::path install_prefix(getInstallPrefix());
std::filesystem::path engine_install_dir = install_prefix / engine_relative_install_dir;
return engine_install_dir.string();
}

}
}
}
4 changes: 2 additions & 2 deletions src/RenderEngineManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <ignition/plugin/Loader.hh>

#include "ignition/rendering/config.hh"
#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/RenderEngine.hh"
#include "ignition/rendering/RenderEngineManager.hh"
#include "ignition/rendering/RenderEnginePlugin.hh"
Expand Down Expand Up @@ -446,7 +446,7 @@ bool RenderEngineManagerPrivate::LoadEnginePlugin(

// Add default install folder.
systemPaths.AddPluginPaths(std::string(IGN_RENDERING_PLUGIN_PATH));
systemPaths.AddPluginPaths({IGNITION_RENDERING_ENGINE_INSTALL_DIR});
systemPaths.AddPluginPaths(ignition::rendering::getEngineInstallDir());

// Add any preset plugin paths.
for (const auto &path : this->pluginPaths)
Expand Down
3 changes: 2 additions & 1 deletion src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ignition/rendering/BoundingBoxCamera.hh"
#include "ignition/rendering/COMVisual.hh"
#include "ignition/rendering/InertiaVisual.hh"
#include "ignition/rendering/InstallationDirectories.hh"
#include "ignition/rendering/JointVisual.hh"
#include "ignition/rendering/LidarVisual.hh"
#include "ignition/rendering/LightVisual.hh"
Expand Down Expand Up @@ -1559,7 +1560,7 @@ void BaseScene::CreateMaterials()

const char *env = std::getenv("IGN_RENDERING_RESOURCE_PATH");
std::string resourcePath = (env) ? std::string(env) :
IGN_RENDERING_RESOURCE_PATH;
ignition::rendering::getResourcePath();

// path to look for CoM material texture
std::string com_material_texture_path = common::joinPaths(
Expand Down

0 comments on commit 2d00d80

Please sign in to comment.