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

CMake improvements #331

Merged
merged 6 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand Down
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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)
Expand Down
33 changes: 19 additions & 14 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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})
8 changes: 4 additions & 4 deletions bindings/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions bindings/gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions cpp/scenario/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down