Skip to content

Commit

Permalink
Add options to install python/ruby in system standard paths (#236)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <[email protected]>

Co-authored-by: Steve Peters <[email protected]>
  • Loading branch information
j-rivero and scpeters authored Sep 13, 2021
1 parent c3ab4dc commit 82acdff
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ ign_configure_project(VERSION_SUFFIX)
# Set project-specific options
#============================================================================

# ignition-math currently has no options that are unique to it
option(USE_SYSTEM_PATHS_FOR_RUBY_INSTALLATION
"Install ruby modules in standard system paths in the system"
OFF)

option(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION
"Install python modules in standard system paths in the system"
OFF)

option(USE_DIST_PACKAGES_FOR_PYTHON
"Use dist-packages instead of site-package to install python modules"
OFF)

#============================================================================
# Search for project-specific dependencies
Expand Down
31 changes: 29 additions & 2 deletions src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,35 @@ if (PYTHONLIBS_FOUND)
$<$<CXX_COMPILER_ID:Clang>:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-cast-function-type -Wno-missing-field-initializers -Wno-class-memaccess>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-cast-function-type -Wno-missing-field-initializers -Wno-class-memaccess>
)
install(TARGETS ${SWIG_PY_LIB} DESTINATION ${IGN_LIB_INSTALL_DIR}/python/ignition)
install(FILES ${CMAKE_BINARY_DIR}/lib/python/math.py DESTINATION ${IGN_LIB_INSTALL_DIR}/python/ignition)

if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "if True:
from distutils import sysconfig as sc
print(sc.get_python_lib(plat_specific=True))"
OUTPUT_VARIABLE Python3_SITEARCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
# Get install variable from Python3 module
# Python3_SITEARCH is available from 3.12 on, workaround if needed:
find_package(Python3 COMPONENTS Interpreter)
endif()

if(USE_DIST_PACKAGES_FOR_PYTHON)
string(REPLACE "site-packages" "dist-packages" IGN_PYTHON_INSTALL_PATH ${Python3_SITEARCH})
else()
# custom cmake command is returning dist-packages
string(REPLACE "dist-packages" "site-packages" IGN_PYTHON_INSTALL_PATH ${Python3_SITEARCH})
endif()
else()
# If not a system installation, respect local paths
set(IGN_PYTHON_INSTALL_PATH ${IGN_LIB_INSTALL_DIR}/python)
endif()

set(IGN_PYTHON_INSTALL_PATH "${IGN_PYTHON_INSTALL_PATH}/ignition")
install(TARGETS ${SWIG_PY_LIB} DESTINATION ${IGN_PYTHON_INSTALL_PATH})
install(FILES ${CMAKE_BINARY_DIR}/lib/python/math.py DESTINATION ${IGN_PYTHON_INSTALL_PATH})

if (BUILD_TESTING)
# Add the Python tests
Expand Down
12 changes: 11 additions & 1 deletion src/ruby/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ if (RUBY_FOUND)
ignition-math${PROJECT_VERSION_MAJOR}
)
target_compile_features(math PUBLIC ${IGN_CXX_${c++standard}_FEATURES})
install(TARGETS math DESTINATION ${IGN_LIB_INSTALL_DIR}/ruby/ignition)

if(USE_SYSTEM_PATHS_FOR_RUBY_INSTALLATION)
execute_process(
COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendordir']"
OUTPUT_VARIABLE IGN_RUBY_INSTALL_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(IGN_RUBY_INSTALL_PATH ${IGN_LIB_INSTALL_DIR}/ruby)
endif()
set(IGN_RUBY_INSTALL_PATH "${IGN_RUBY_INSTALL_PATH}/ignition")
install(TARGETS math DESTINATION ${IGN_RUBY_INSTALL_PATH})

# Add the ruby tests
foreach (test ${ruby_tests})
Expand Down

0 comments on commit 82acdff

Please sign in to comment.