diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 0e44ae267..38ead433a 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -165,7 +165,7 @@ jobs: - name: '[User] Create wheel' if: matrix.type == 'User' && matrix.ignition == 'dome' shell: bash -i -e {0} - run: pip3 wheel -w dist/ . + run: pip3 wheel -v -w dist/ . # Note: calling "pip wheel" with "--global-option" forces dependencies to be build from their sdist. # Since it's very slow, we create the wheel from setup.py without isolation. - name: '[User] Create wheel' @@ -183,6 +183,11 @@ jobs: cd dist pip3 install -v *.whl + - name: Inspect installed ScenarIO package + run: | + apt-get install -y --no-install-recommends tree + tree $(python3 -c "import scenario, pathlib; print(pathlib.Path(scenario.__file__).parent)") + - name: Ccache stats run: ccache --show-stats diff --git a/CMakeLists.txt b/CMakeLists.txt index c58139ab2..6bf84a8ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,7 +172,7 @@ if(NOT IGNITION_DISTRIBUTION) endif() -if(NOT IGNITION_DISTRIBUTION) +if(NOT IGNITION_DISTRIBUTION OR "${IGNITION_DISTRIBUTION}" STREQUAL "") set(USE_IGNITION FALSE) else() set(USE_IGNITION TRUE) @@ -182,8 +182,13 @@ option(SCENARIO_USE_IGNITION "Build C++ code depending on Ignition" ${USE_IGNITION}) +# Fail if Ignition is enabled but no compatible distribution was found +if(SCENARIO_USE_IGNITION AND "${IGNITION_DISTRIBUTION}" STREQUAL "") + message(FATAL_ERROR "Failed to find a compatible Ignition Gazebo distribution") +endif() + # Alias the targets -if(${SCENARIO_USE_IGNITION}) +if(SCENARIO_USE_IGNITION) include(ImportTargets${IGNITION_DISTRIBUTION}) endif() @@ -205,7 +210,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "PyPI" AND NOT USE_IGNITION) message(FATAL_ERROR "Found no Ignition distribution for PyPI package") endif() -option(SCENARIO_ENABLE_BINDINGS "Enable SWIG bindings" ON) +find_package(SWIG 4.0 QUIET) +option(SCENARIO_ENABLE_BINDINGS "Enable SWIG bindings" ${SWIG_FOUND}) if(SCENARIO_ENABLE_BINDINGS) add_subdirectory(bindings) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index ab028b186..74b524091 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -36,25 +36,30 @@ find_package(SWIG 4.0 REQUIRED) set(UseSWIG_MODULE_VERSION 2) include(${SWIG_USE_FILE}) -# Change the install prefix of the bindings targets depending on -# the installation mode (User or Developer) +# By default, install ScenarIO in the python site-package directory +if(NOT BINDINGS_INSTALL_PREFIX) + set(BINDINGS_INSTALL_PREFIX ${Python3_SITELIB}) +endif() + +# Expose the install prefix as CMake option +set(BINDINGS_INSTALL_PREFIX "${BINDINGS_INSTALL_PREFIX}" + CACHE STRING "Installation prefix of the bindings") + +# Final directory of the "scenario" package if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI") - if(NOT BINDINGS_INSTALL_PREFIX) - # Install in the python site-package directory - set(BINDINGS_INSTALL_PREFIX ${Python3_SITELIB}/scenario) - else() - set(BINDINGS_INSTALL_PREFIX "${BINDINGS_INSTALL_PREFIX}" - CACHE STRING "Custom location where to install the bindings") - endif() + set(SCENARIO_PACKAGE_INSTALL_DIR "${BINDINGS_INSTALL_PREFIX}/scenario") else() - # Install in the root of the PyPI package directory that - # will become the archive to install / publish. - set(BINDINGS_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + # If packaging for PyPI, install ScenarIO in the temp site-package directory + # created by either setup.py or pip. + # The "scenario/" folder is added by cmake_build_extension + set(SCENARIO_PACKAGE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") endif() # Add the SWIG folders add_subdirectory(core) -add_subdirectory(gazebo) +if(SCENARIO_USE_IGNITION) + add_subdirectory(gazebo) +endif() # Move main init.py file to package root of the build tree configure_file( @@ -68,4 +73,4 @@ file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/scenario/bindings/__init__.py) # Move main init.py file to package root of the install tree install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py - DESTINATION ${BINDINGS_INSTALL_PREFIX}) + DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}) diff --git a/bindings/core/CMakeLists.txt b/bindings/core/CMakeLists.txt index dd61aa177..c83132778 100644 --- a/bindings/core/CMakeLists.txt +++ b/bindings/core/CMakeLists.txt @@ -41,10 +41,10 @@ get_property(WRAPPER_PY_FILE TARGET ${scenario_swig_name} PROPERTY SWIG_SUPPORT_ install( TARGETS ${scenario_swig_name} - LIBRARY DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings - ARCHIVE DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings - RUNTIME DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings) + LIBRARY DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings + ARCHIVE DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings + RUNTIME DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) install( FILES ${WRAPPER_PY_FILE} - DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings) + DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) diff --git a/bindings/gazebo/CMakeLists.txt b/bindings/gazebo/CMakeLists.txt index 21c40f66b..c314b6851 100644 --- a/bindings/gazebo/CMakeLists.txt +++ b/bindings/gazebo/CMakeLists.txt @@ -42,10 +42,10 @@ get_property(WRAPPER_PY_FILE TARGET ${scenario_swig_name} PROPERTY SWIG_SUPPORT_ install( TARGETS ${scenario_swig_name} - LIBRARY DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings - ARCHIVE DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings - RUNTIME DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings) + LIBRARY DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings + ARCHIVE DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings + RUNTIME DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) install( FILES ${WRAPPER_PY_FILE} - DESTINATION ${BINDINGS_INSTALL_PREFIX}/bindings) + DESTINATION ${SCENARIO_PACKAGE_INSTALL_DIR}/bindings) diff --git a/cpp/scenario/core/CMakeLists.txt b/cpp/scenario/core/CMakeLists.txt index bcc3fb5eb..21e79f081 100644 --- a/cpp/scenario/core/CMakeLists.txt +++ b/cpp/scenario/core/CMakeLists.txt @@ -50,6 +50,8 @@ target_include_directories(CoreUtils PUBLIC set_target_properties(CoreUtils PROPERTIES PUBLIC_HEADER "${CORE_UTILS_HEADERS}") +# This definition is used by the "scenario" Python package +# to detect User / Developer installation mode if(NOT CMAKE_BUILD_TYPE STREQUAL "PyPI") target_compile_options(CoreUtils PRIVATE -DSCENARIO_CMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}")