Add optional binary relocatability
Closes part of https://github.com/gazebosim/gz-sim/issues/626
Summary
This PR uses the changes introduced in gz-cmake3 in https://github.com/gazebosim/gz-cmake/pull/334 to support the cmake installation directory to be moved after the make install prefix, and continue to work without the need to set any special environment variable, as long as the library is compiled as shared. To avoid regressions and problems in Ubuntu Focal due to the use of std::filesystem, this new behaviour is only activated if the GZ_ENABLE_RELOCATABLE_INSTALL option is enabled, and its default value is OFF .
In particular, this PR defines a sdf::getSharePath() function that should be used in place of the SDF_SHARE_PATH macro to ensure that the library is relocatable.
Furthermore, this PR also deprecates the SDF_SHARE_PATH macro, using the strategy described in https://stackoverflow.com/a/29297970 . That strategy works fine on GCC and Clang, while on MSVC it raise a warning:
warning C4068: unknown pragma
However, I think that it does anyhow the job of raising some kind of warning, and then at soon as the developer checks the macro definition the kind of warning is clear.
The PR also deprecates the SDF_VERSION_PATH macro without providing any replacement. This is done as at the moment the SDF_VERSION_PATH points to a non-existent directory:
#ifndef SDF_VERSION_PATH
#define SDF_VERSION_PATH "/home/traversaro/miniforge3/envs/sdformat14/share/sdformat14/14.2"
#endif
so I guess it is mostly unused, and it can be safely deprecated.
Similarly to https://github.com/gazebosim/gz-physics/pull/507, a local copy of joinPaths is imported to avoid to add a dependency on gz-common.
Test it
The test should work as usual. The used CMake machinery is tested in https://github.com/gazebosim/gz-cmake/pull/334 .
Checklist
- [x] Signed all commits for DCO
- [ ] Added tests
- [ ] Added example and/or tutorial
- [x] Updated documentation (as needed)
- [x] Updated migration guide (as needed)
- [x] Consider updating Python bindings (if the library has them)
- [ ]
codecheckpassed (See contributing) - [ ] All tests passed (See test coverage)
- [ ] While waiting for a review on your PR, please help review another open pull request to support the maintainers
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.
cc @xela-95
@mjcarroll I guess the bazel build system needs to be adapted to this change, do you have any pointer on how I could do that? Thanks!
@mjcarroll I guess the bazel build system needs to be adapted to this change, do you have any pointer on how I could do that? Thanks!
Friendly ping @mjcarroll, thanks!
changes look good to me. Perhaps we can get this in first and adapt the changes to bzl as a follow-on task?
changes look good to me. Perhaps we can get this in first and adapt the changes to bzl as a follow-on task?
Ok for me!
I've started seeing windows builds of downstream packages fail since this was merged:
- gz-physics7
https://build.osrfoundation.org/job/gz_physics-7-win/80/
- gz-sensors8
https://build.osrfoundation.org/job/gz_sensors-8-win/73/
- gz-sim8
https://build.osrfoundation.org/job/gz_sim-8-win/108/
InstallationDirectories.obj :
error LNK2001: unresolved external symbol __imp_PathCombineA
[C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
# BEGIN SECTION: colcon compilation without test for dependencies of gz-physics7
"COLCON_EXTRA_ARGS: --packages-skip gz-physics7"
"COLCON_EXTRA_CMAKE_ARGS: "-DBUILD_TESTING=0""
"COLCON_EXTRA_CMAKE_ARGS2: "-DCMAKE_CXX_FLAGS=-w""
...
--- output: sdformat14
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.20348.
-- The C compiler identification is MSVC 19.29.30148.0
-- The CXX compiler identification is MSVC 19.29.30148.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- sdformat14 version 14.5.0
-- Operating system is Windows
-- Checking for module 'tinyxml2'
-- Found tinyxml2, version 9.0.0
-- Looking for TINYXML2 - found
-- Looking for urdfdom - not found
-- Looking for urdfdom - not found
-- Using internal URDF
-- Found Python3: C:/vcpkg/installed/x64-windows/tools/python3/python.exe (found version "3.10.1") found components: Interpreter Development Development.Module Development.Embed
-- Performing Test HAS_MSVC_GL_LTCG
-- Performing Test HAS_MSVC_GL_LTCG - Success
-- Searching for pybind11 - found version 2.9.1.
-- Could NOT find PY_psutil (missing: PY_PSUTIL)
-- Looking for gz-math7 -- found version 7.5.0
-- Searching for dependencies of gz-math7
-- Looking for gz-utils2 -- found version 2.2.0
-- Searching for dependencies of gz-utils2
-- Looking for gz-math7 - found
-- Looking for gz-utils2 -- found version 2.2.0
-- Searching for dependencies of gz-utils2
-- Searching for <gz-utils2> component [cli]
-- Looking for gz-utils2-cli -- found version 2.2.0
-- Searching for dependencies of gz-utils2-cli
-- Looking for gz-utils2 - found
CMake Warning at C:/J/workspace/gz_physics-7-win/ws/install/gz-cmake3/share/cmake/gz-cmake3/cmake3/GzConfigureBuild.cmake:68 (message):
CONFIGURATION WARNINGS:
-- Python psutil package not found. Memory leak tests will be skipped
Call Stack (most recent call first):
CMakeLists.txt:155 (gz_configure_build)
-- Configuring library: sdformat14
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- The program [cppcheck] was not found! Skipping codecheck setup
-- Build configuration successful
-- Build type: Release
-- Install prefix: C:/J/workspace/gz_physics-7-win/ws/install/sdformat14
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuration successful. Type make to compile sdf
-- Configuring done
-- Generating done
-- Build files have been written to: C:/J/workspace/gz_physics-7-win/ws/build/sdformat14
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/J/workspace/gz_physics-7-win/ws/sdformat/src/CMakeLists.txt
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
Actor.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
AirPressure.cc
AirSpeed.cc
Altimeter.cc
Atmosphere.cc
Box.cc
Camera.cc
Capsule.cc
Collision.cc
Cone.cc
Console.cc
Converter.cc
CustomInertiaCalcProperties.cc
Cylinder.cc
Element.cc
Ellipsoid.cc
Error.cc
Exception.cc
Filesystem.cc
ForceTorque.cc
Frame.cc
FrameSemantics.cc
Geometry.cc
Gui.cc
Heightmap.cc
Imu.cc
InterfaceElements.cc
InterfaceFrame.cc
InterfaceJoint.cc
InterfaceLink.cc
InterfaceModel.cc
InterfaceModelPoseGraph.cc
JointAxis.cc
Lidar.cc
Light.cc
Magnetometer.cc
Material.cc
Mesh.cc
NavSat.cc
Noise.cc
OutputConfig.cc
Param.cc
ParamPassing.cc
ParserConfig.cc
ParticleEmitter.cc
Pbr.cc
Physics.cc
Plane.cc
Plugin.cc
Polyline.cc
PrintConfig.cc
Projector.cc
Root.cc
SDF.cc
SDFExtension.cc
Scene.cc
SemanticPose.cc
Sensor.cc
Sky.cc
Sphere.cc
Surface.cc
Types.cc
Utils.cc
Visual.cc
XmlUtils.cc
gz.cc
parser.cc
parser_urdf.cc
EmbeddedSdf.cc
pose.cpp
twist.cpp
urdf_model_state.cpp
urdf_sensor.cpp
sdformat14_get_install_prefix_impl.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
InstallationDirectories.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
Joint.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
Link.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
Model.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
World.cc
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
model.cpp
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
link.cpp
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
joint.cpp
cl : command line warning D9025: overriding '/W2' with '/w' [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
world.cpp
Actor.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
Creating library C:/J/workspace/gz_physics-7-win/ws/build/sdformat14/lib/Release/sdformat14.lib and object C:/J/workspace/gz_physics-7-win/ws/build/sdformat14/lib/Release/sdformat14.exp
InstallationDirectories.obj : error LNK2001: unresolved external symbol __imp_PathCombineA [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\bin\Release\sdformat14.dll : fatal error LNK1120: 1 unresolved externals [C:\J\workspace\gz_physics-7-win\ws\build\sdformat14\src\sdformat14.vcxproj]
The note on the joinPaths function says it's copied from ign-common4. May we can update the code to use a copy of the joinPaths code from gz-common5 instead? It uses std::filesystem and does not have platform specific ifdefs
The note on the
joinPathsfunction says it's copied from ign-common4. May we can update the code to use a copy of thejoinPathscode from gz-common5 instead? It usesstd::filesystemand does not have platform specific ifdefs
Originally this was done to avoid to link std::filesystem that created ABI problems in Ubuntu 20.04, if we dropped support for that I guess we can use std::filesystem.
The note on the
joinPathsfunction says it's copied from ign-common4. May we can update the code to use a copy of thejoinPathscode from gz-common5 instead? It usesstd::filesystemand does not have platform specific ifdefsOriginally this was done to avoid to link
std::filesystemthat created ABI problems in Ubuntu 20.04, if we dropped support for that I guess we can usestd::filesystem.
Gazebo Harmonic and up don't support 20.04, so yeah, we could copy the gz-common joinPaths implementation with std::filesystem as an alternative to shlwapi