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

Add optional binary relocatability #804

Merged
merged 4 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable binary relocatability
Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
  • Loading branch information
traversaro committed Apr 24, 2023
commit e93056268e3aba8f2d07feafa2360d8cb6dc3e5c
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ if (OGRE2_FOUND)
endif()

# Plugin install dirs
set(GZ_RENDERING_ENGINE_INSTALL_DIR
${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/engine-plugins
set(GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR
${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/engine-plugins
)
set(GZ_RENDERING_ENGINE_INSTALL_DIR
${CMAKE_INSTALL_PREFIX}/${GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR})


#--------------------------------------
# Find dependencies that we ignore for Visual Studio
Expand Down Expand Up @@ -155,7 +158,8 @@ else()
set(GZ_RENDERING_PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
endif()

set(GZ_RENDERING_RESOURCE_PATH ${CMAKE_INSTALL_PREFIX}/${GZ_DATA_INSTALL_DIR})
set(GZ_RENDERING_RELATIVE_RESOURCE_PATH ${GZ_DATA_INSTALL_DIR})
set(GZ_RENDERING_RESOURCE_PATH ${CMAKE_INSTALL_PREFIX}/${GZ_RENDERING_RELATIVE_RESOURCE_PATH})

#============================================================================
# Configure the build
Expand Down
46 changes: 46 additions & 0 deletions include/gz/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 GZ_RENDERING_INSTALLATION_DIRECTORIES_HH_
#define GZ_RENDERING_INSTALLATION_DIRECTORIES_HH_

#include <string>

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

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {

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

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

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

}
}
}

#endif
4 changes: 2 additions & 2 deletions include/gz/rendering/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

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

#define GZ_RENDERING_RESOURCE_PATH "${GZ_RENDERING_RESOURCE_PATH}"
#define GZ_RENDERING_RESOURCE_PATH _Pragma ("GCC warning \"'GZ_RENDERING_RESOURCE_PATH' macro is deprecated, use gz::rendering::getResourcePath() function instead. \"") "${GZ_RENDERING_RESOURCE_PATH}"

#define GZ_RENDERING_ENGINE_INSTALL_DIR "${GZ_RENDERING_ENGINE_INSTALL_DIR}"
#define GZ_RENDERING_ENGINE_INSTALL_DIR _Pragma ("GCC warning \"'GZ_RENDERING_ENGINE_INSTALL_DIR' macro is deprecated, use gz::rendering::getEngineInstallDir() function instead. \"") "${GZ_RENDERING_ENGINE_INSTALL_DIR}"

#cmakedefine HAVE_OGRE 1
#cmakedefine HAVE_OGRE2 1
Expand Down
6 changes: 4 additions & 2 deletions 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
GZ_RENDERING_RESOURCE_PATH="${GZ_RENDERING_RESOURCE_PATH}"
OGRE_RESOURCE_PATH="${OGRE_RESOURCE_PATH}"
)

Expand All @@ -41,7 +40,10 @@ target_link_libraries(${ogre_target}
)

# Build the unit tests
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${ogre_target})
gz_build_tests(TYPE UNIT
SOURCES ${gtest_sources}
LIB_DEPS ${ogre_target}
ENVIRONMENT GZ_RENDERING_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

# Note that plugins are currently being installed in 2 places: /lib and the engine-plugins dir
install(TARGETS ${ogre_target} DESTINATION ${GZ_RENDERING_ENGINE_INSTALL_DIR})
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 "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/ogre/OgreCamera.hh"
#include "gz/rendering/ogre/OgreConversions.hh"
#include "gz/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 <gz/math/Helpers.hh>
#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/ogre/OgreDepthCamera.hh"
#include "gz/rendering/ogre/OgreMaterial.hh"

Expand Down Expand Up @@ -235,7 +236,7 @@ void OgreDepthCamera::CreatePointCloudTexture()
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::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 <gz/common/Console.hh>
#include <gz/common/Filesystem.hh>

#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/ShaderParams.hh"
#include "gz/rendering/ogre/OgreMaterial.hh"
#include "gz/rendering/ogre/OgreConversions.hh"
Expand Down Expand Up @@ -737,7 +738,7 @@ void OgreMaterial::SetDepthMaterial(const double _far,
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::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 <gz/common/Filesystem.hh>
#include <gz/common/Util.hh>

#include "gz/rendering/config.hh"
#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/ogre/OgreRenderEngine.hh"
#include "gz/rendering/ogre/OgreScene.hh"
#include "gz/rendering/ogre/OgreMaterial.hh"
Expand Down Expand Up @@ -501,7 +501,7 @@ bool OgreRTShaderSystem::Paths(std::string &coreLibsPath,
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::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 <gz/common/Filesystem.hh>
#include <gz/common/Util.hh>

#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/RenderEngineManager.hh"
#include "gz/rendering/ogre/OgreIncludes.hh"
#include "gz/rendering/ogre/OgreRenderEngine.hh"
Expand Down Expand Up @@ -582,7 +583,7 @@ void OgreRenderEngine::CreateResources()
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::rendering::getResourcePath();
// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre", "media");
paths.push_back(mediaPath);
Expand Down
6 changes: 4 additions & 2 deletions ogre2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ gz_add_component(${engine_name} SOURCES ${sources} GET_TARGET_NAME ogre2_target)
set_property(
SOURCE Ogre2RenderEngine.cc
PROPERTY COMPILE_DEFINITIONS
GZ_RENDERING_RESOURCE_PATH="${GZ_RENDERING_RESOURCE_PATH}"
OGRE2_RESOURCE_PATH="${OGRE2_RESOURCE_PATH}"
OGRE2_VERSION="${OGRE2_VERSION}"
)
Expand Down Expand Up @@ -82,6 +81,9 @@ if (USE_GLX)
endif()

# Build the unit tests
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${ogre2_target})
gz_build_tests(TYPE UNIT
SOURCES ${gtest_sources}
LIB_DEPS ${ogre2_target}
ENVIRONMENT GZ_RENDERING_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

install(DIRECTORY "media" DESTINATION ${GZ_RENDERING_RESOURCE_PATH}/ogre2)
6 changes: 4 additions & 2 deletions ogre2/src/Ogre2RenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <gz/plugin/Register.hh>

#include "gz/rendering/GraphicsAPI.hh"
#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/RenderEngineManager.hh"
#include "gz/rendering/ogre2/Ogre2Includes.hh"
#include "gz/rendering/ogre2/Ogre2RenderEngine.hh"
Expand Down Expand Up @@ -766,7 +767,8 @@ void Ogre2RenderEngine::RegisterHlms()
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::rendering::getResourcePath();

// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre2", "media");
if (!common::exists(mediaPath))
Expand Down Expand Up @@ -969,7 +971,7 @@ void Ogre2RenderEngine::CreateResources()
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::rendering::getResourcePath();
// install path
std::string mediaPath = common::joinPaths(resourcePath, "ogre2", "media");
if (!common::exists(mediaPath))
Expand Down
6 changes: 3 additions & 3 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
GZ_RENDERING_RESOURCE_PATH="${GZ_RENDERING_RESOURCE_PATH}"
)

target_link_libraries(${optix_target}
Expand All @@ -43,7 +41,9 @@ target_link_libraries(${optix_target}
optix::optix_prime)

# Build the unit tests
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT
SOURCES ${gtest_sources}
ENVIRONMENT GZ_RENDERING_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

# Note that plugins are currently being installed in 2 places: /lib and the engine-plugins dir
install(TARGETS ${optix_target} DESTINATION ${GZ_RENDERING_ENGINE_INSTALL_DIR})
Expand Down
2 changes: 1 addition & 1 deletion optix/src/OptixRenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::string OptixRenderEngine::PtxFile(const std::string& _fileBase) const
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::rendering::getResourcePath();
resourcePath = common::joinPaths(resourcePath, "optix");
folders.push_back(resourcePath);

Expand Down
14 changes: 13 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ endif()

# Create the library target.
gz_create_core_library(SOURCES ${sources})
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION gz::rendering::getInstallPrefix
GET_INSTALL_PREFIX_HEADER gz/rendering/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GZ_RENDERING_INSTALL_PREFIX)

# Include the interface directories that we always need.
#gz_target_interface_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
Expand All @@ -26,6 +29,13 @@ set_property(
GZ_RENDERING_PLUGIN_PATH="${GZ_RENDERING_PLUGIN_PATH}"
)

set_property(
SOURCE InstallationDirectories.cc
PROPERTY COMPILE_DEFINITIONS
GZ_RENDERING_RELATIVE_RESOURCE_PATH="${GZ_RENDERING_RELATIVE_RESOURCE_PATH}"
GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR="${GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR}"
)

target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
gz-common${GZ_COMMON_VER}::requested
Expand All @@ -38,4 +48,6 @@ if (UNIX AND NOT APPLE)
endif()

# Build the unit tests.
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources})
gz_build_tests(TYPE UNIT
SOURCES ${gtest_sources}
ENVIRONMENT GZ_RENDERING_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
41 changes: 41 additions & 0 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*
*/

#include <gz/rendering/config.hh>
#include <gz/rendering/InstallationDirectories.hh>

#include <gz/common/Filesystem.hh>

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {

std::string getResourcePath()
{
return gz::common::joinPaths(getInstallPrefix(), GZ_RENDERING_RELATIVE_RESOURCE_PATH);
}

std::string getEngineInstallDir()
{
return gz::common::joinPaths(getInstallPrefix(), GZ_RENDERING_ENGINE_RELATIVE_INSTALL_DIR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI picked up a couple of minor issues here:

  /github/workspace/src/InstallationDirectories.cc:31:  Lines should be <= 80 characters long  [whitespace/line_length] [2]
  /github/workspace/src/InstallationDirectories.cc:36:  Lines should be <= 80 characters long  [whitespace/line_length] [2]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I did not notice that as I tought the CI errors were all due to the gz-cmake 3.1.0 missing on Focal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c412915 .

}

}
}
}
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 <gz/plugin/Loader.hh>

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

// Add default install folder.
systemPaths.AddPluginPaths(std::string(GZ_RENDERING_PLUGIN_PATH));
systemPaths.AddPluginPaths({GZ_RENDERING_ENGINE_INSTALL_DIR});
systemPaths.AddPluginPaths(gz::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 @@ -28,6 +28,7 @@
#include "gz/rendering/BoundingBoxCamera.hh"
#include "gz/rendering/COMVisual.hh"
#include "gz/rendering/InertiaVisual.hh"
#include "gz/rendering/InstallationDirectories.hh"
#include "gz/rendering/JointVisual.hh"
#include "gz/rendering/LidarVisual.hh"
#include "gz/rendering/LightVisual.hh"
Expand Down Expand Up @@ -1569,7 +1570,7 @@ void BaseScene::CreateMaterials()
}

std::string resourcePath = (env) ? std::string(env) :
GZ_RENDERING_RESOURCE_PATH;
gz::rendering::getResourcePath();

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