Skip to content

Commit

Permalink
Add optional binary relocatability
Browse files Browse the repository at this point in the history
Signed-off-by: Silvio Traversaro <[email protected]>
  • Loading branch information
traversaro committed May 8, 2023
1 parent 7a81015 commit 5379713
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ gz_configure_project(VERSION_SUFFIX)
# Set project-specific options
#============================================================================

set(GZ_LAUNCH_PLUGIN_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/")
set(GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH "${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/")
set(GZ_LAUNCH_PLUGIN_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH}")

#============================================================================
# Search for project-specific dependencies
Expand Down
46 changes: 46 additions & 0 deletions include/gz/launch/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_LAUNCH_INSTALLATION_DIRECTORIES_HH_
#define GZ_LAUNCH_INSTALLATION_DIRECTORIES_HH_

#include <string>

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

namespace gz
{
namespace launch
{
inline namespace GZ_LAUNCH_VERSION_NAMESPACE {

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

/// \brief getPluginInstallPath return the plugin install path
GZ_LAUNCH_VISIBLE std::string getPluginInstallPath();

/// \brief getInitialConfigPath return the initial config path
GZ_LAUNCH_VISIBLE std::string getInitialConfigPath();

}
}
}

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

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

#define GZ_LAUNCH_INITIAL_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_DATA_INSTALL_DIR}/configs"
#define GZ_LAUNCH_INITIAL_CONFIG_PATH _Pragma ("GCC warning \"'GZ_LAUNCH_INITIAL_CONFIG_PATH' macro is deprecated, use gz::launch::getInitialConfigPath() function instead. \"") "${CMAKE_INSTALL_PREFIX}/${GZ_DATA_INSTALL_DIR}/configs"

#define GZ_LAUNCH_PLUGIN_INSTALL_PATH "${GZ_LAUNCH_PLUGIN_INSTALL_PATH}"
#define GZ_LAUNCH_PLUGIN_INSTALL_PATH _Pragma ("GCC warning \"'GZ_LAUNCH_PLUGIN_INSTALL_PATH' macro is deprecated, use gz::launch::getPluginInstallPath() function instead. \"") "${GZ_LAUNCH_PLUGIN_INSTALL_PATH}"

#endif
13 changes: 13 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# add_subdirectory(plugins)

set (sources
InstallationDirectories.cc
Manager.cc
)

Expand All @@ -10,6 +11,16 @@ set (gtest_sources

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

set_property(
SOURCE InstallationDirectories.cc
PROPERTY COMPILE_DEFINITIONS
GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH="${GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH}"
GZ_LAUNCH_INITIAL_CONFIG_RELATIVE_PATH="${GZ_DATA_INSTALL_DIR}/configs"
)

# Link the libraries that we always need.
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
Expand All @@ -31,6 +42,8 @@ gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}
LIB_DEPS
${PROJECT_LIBRARY_TARGET_NAME}
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
ENVIRONMENT
GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

add_subdirectory(cmd)
43 changes: 43 additions & 0 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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/launch/config.hh>
#include <gz/launch/InstallationDirectories.hh>

#include <gz/common/Filesystem.hh>

namespace gz
{
namespace launch
{
inline namespace GZ_LAUNCH_VERSION_NAMESPACE {

std::string getPluginInstallPath()
{
return gz::common::joinPaths(
getInstallPrefix(), GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH);
}

std::string getInitialConfigPath()
{
return gz::common::joinPaths(
getInstallPrefix(), GZ_LAUNCH_INITIAL_CONFIG_RELATIVE_PATH);
}

}
}
}
3 changes: 2 additions & 1 deletion src/Manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <gz/plugin/Loader.hh>

#include "gz/launch/config.hh"
#include "gz/launch/InstallationDirectories.hh"
#include "gz/launch/Plugin.hh"

#include "vendor/backward.hpp"
Expand Down Expand Up @@ -1089,7 +1090,7 @@ void ManagerPrivate::LoadPlugin(const tinyxml2::XMLElement *_elem)

gz::common::SystemPaths systemPaths;
systemPaths.SetPluginPathEnv("GZ_LAUNCH_PLUGIN_PATH");
systemPaths.AddPluginPaths(GZ_LAUNCH_PLUGIN_INSTALL_PATH);
systemPaths.AddPluginPaths(gz::launch::getPluginInstallPath());

// Add LD_LIBRARY_PATH
#ifdef __linux__
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ install(
# Build the unit tests.
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}
TEST_LIST test_list
LIB_DEPS ${EXTRA_TEST_LIB_DEPS})
LIB_DEPS ${EXTRA_TEST_LIB_DEPS}
ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

foreach(test ${test_list})
target_link_libraries(${test} gz)
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/gz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*
*/
#include <cstring>
#include <string>
#include <gz/common/Console.hh>

#include "gz/launch/config.hh"
#include "gz/launch/InstallationDirectories.hh"
#include "gz.hh"
#include "../Manager.hh"

Expand All @@ -30,7 +32,8 @@ extern "C" char *gzVersion()
//////////////////////////////////////////////////
extern "C" const char *configPath()
{
return GZ_LAUNCH_INITIAL_CONFIG_PATH;
std::string configPath = gz::launch::getPluginInstallPath();
return configPath.c_str();
}

//////////////////////////////////////////////////
Expand Down
5 changes: 4 additions & 1 deletion test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ if(NOT WIN32)
# Disable test on Windows, it deals with UNIX signals
set(tests faulty_plugins.cc)

gz_build_tests(TYPE INTEGRATION SOURCES ${tests} TEST_LIST test_targets)
gz_build_tests(TYPE INTEGRATION
SOURCES ${tests}
TEST_LIST test_targets
ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
foreach(test ${test_targets})
target_compile_definitions(${test} PRIVATE
"bad_plugins_LIB=\"$<TARGET_FILE:bad_plugins>\"")
Expand Down
4 changes: 3 additions & 1 deletion test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set(tests)

link_directories(${PROJECT_BINARY_DIR}/test)

gz_build_tests(TYPE PERFORMANCE SOURCES ${tests})
gz_build_tests(TYPE PERFORMANCE
SOURCES ${tests}
ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
4 changes: 3 additions & 1 deletion test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ set(tests

link_directories(${PROJECT_BINARY_DIR}/test)

gz_build_tests(TYPE REGRESSION SOURCES ${tests})
gz_build_tests(TYPE REGRESSION
SOURCES ${tests}
ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

0 comments on commit 5379713

Please sign in to comment.