Skip to content

Commit

Permalink
[core] Fix memory corruption segfault after adding frame to model. (#269
Browse files Browse the repository at this point in the history
)

* [misc] Update pre-compiled binaries of dependencies (EigenPy 2.6.0, Hpp-Fcl 1.6.0, Pinocchio 2.5.5).
* [misc] Fix several cmake edge cases.
* [misc] Enable linker optimizations.
* [core] Take advantage of new features and improved Windows 10 support to simply codebase.
* [core] Fix flaky memory corruption segfault when adding frame to model.
* [core] Fix special cmake linkage flags 'optimized'/'debug' not being properly detected for Boost.
* [python/simulator] Fix progress bar glitches if simulate raises an exception during a simulation.

Co-authored-by: Alexis Duburcq <alexis.duburcq@wandercraft.eu>
  • Loading branch information
duburcqa and Alexis Duburcq authored Jan 15, 2021
1 parent 358a804 commit c469a1f
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 533 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
cmake "$RootDir" -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE \
-DBoost_USE_STATIC_LIBS=OFF -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DBoost_USE_STATIC_LIBS=ON -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_PYTHON_INTERFACE=ON \
-DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_BUILD_TYPE="$BUILD_TYPE"
make install -j2
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/manylinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ jobs:
cd "$RootDir/build"
export LD_LIBRARY_PATH="$InstallDir/lib/:/usr/local/lib"
cmake "$RootDir" -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE \
-DBoost_USE_STATIC_LIBS=OFF -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DBoost_USE_STATIC_LIBS=ON -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_PYTHON_INTERFACE=ON \
-DCMAKE_CXX_FLAGS="-s" -DCMAKE_BUILD_TYPE="$BUILD_TYPE" # gcc flag '-s' removes all symbol table and relocation information
make -j2
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ jobs:
echo "RootDir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
echo "InstallDir=${GITHUB_WORKSPACE}/install" >> $GITHUB_ENV
if [ $(gcc -dumpversion) -ge 9 ]; then
echo "ENABLE_LTO=1" >> $GITHUB_ENV
else
echo "ENABLE_LTO=0" >> $GITHUB_ENV
fi
echo "/home/runner/.local/bin" >> $GITHUB_PATH
- name: Installing requirements
run: |
Expand All @@ -64,6 +70,7 @@ jobs:
cd "$RootDir/build"
cmake "$RootDir" -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ENABLE_LTO} \
-DBoost_NO_SYSTEM_PATHS=OFF -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_PYTHON_INTERFACE=ON \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ jobs:
cmake "$RootDir" -G "Visual Studio 16 2019" -T "v142" -DCMAKE_GENERATOR_PLATFORM=x64 `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" `
-DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_PREFIX_PATH="$InstallDir" `
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON `
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" `
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE `
-DBoost_USE_STATIC_LIBS=OFF -DPYTHON_REQUIRED_VERSION="${{ matrix.python-version }}" `
-DBoost_USE_STATIC_LIBS=ON -DPYTHON_REQUIRED_VERSION="${{ matrix.python-version }}" `
-DBUILD_TESTING=ON -DBUILD_EXAMPLES=ON -DBUILD_PYTHON_INTERFACE=ON `
-DCMAKE_CXX_FLAGS="/EHsc /bigobj /Zc:__cplusplus -D_USE_MATH_DEFINES -DBOOST_ALL_NO_LIB -DBOOST_LIB_DIAGNOSTIC -DEIGENPY_STATIC -DURDFDOM_STATIC -DHPP_FCL_STATIC -DPINOCCHIO_STATIC"
cmake --build . --config "${Env:BUILD_TYPE}" --parallel 2
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.10)

# Set the build version
set(BUILD_VERSION 1.5.0)
set(BUILD_VERSION 1.5.1)

# Add definition of Jiminy version for C++ headers
add_definitions("-DJIMINY_VERSION=\"${BUILD_VERSION}\"")
Expand Down Expand Up @@ -37,6 +37,7 @@ add_subdirectory(core)

option(BUILD_PYTHON_INTERFACE "Build the Python bindings" ON)
if(BUILD_PYTHON_INTERFACE)
include(${CMAKE_SOURCE_DIR}/build_tools/cmake/setupPython.cmake)
add_subdirectory(python)
endif()

Expand Down
21 changes: 16 additions & 5 deletions build_tools/build_install_deps_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ if [ -z ${BUILD_TYPE} ]; then
echo "BUILD_TYPE is unset. Defaulting to 'Release'."
fi

### Enable LTO if possible
if [ $(gcc -dumpversion) -ge 9 ]; then
ENABLE_LTO=1
else
ENABLE_LTO=0
fi

### Get the fullpath of Jiminy project
ScriptDir="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
RootDir="$(dirname $ScriptDir)"
Expand Down Expand Up @@ -54,7 +61,7 @@ if [ ! -d "$RootDir/eigenpy" ]; then
fi
cd "$RootDir/eigenpy"
git reset --hard
git checkout --force "v2.5.0"
git checkout --force "v2.6.0"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
git apply --reject --whitespace=fix "$RootDir/build_tools/patch_deps_linux/eigenpy.patch"
Expand Down Expand Up @@ -108,7 +115,7 @@ if [ ! -d "$RootDir/hpp-fcl" ]; then
fi
cd "$RootDir/hpp-fcl"
git reset --hard
git checkout --force "v1.5.4"
git checkout --force "v1.6.0"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
git apply --reject --whitespace=fix "$RootDir/build_tools/patch_deps_linux/hppfcl.patch"
Expand All @@ -121,7 +128,7 @@ if [ ! -d "$RootDir/pinocchio" ]; then
fi
cd "$RootDir/pinocchio"
git reset --hard
git checkout --force "v2.5.0"
git checkout --force "v2.5.5"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
git apply --reject --whitespace=fix "$RootDir/build_tools/patch_deps_linux/pinocchio.patch"
Expand Down Expand Up @@ -157,12 +164,12 @@ mkdir -p "$RootDir/boost/build"
--with-stacktrace --with-system --with-filesystem --with-atomic \
--with-thread --with-serialization --with-test \
--build-type=minimal architecture=x86 address-model=64 threading=multi \
--layout=system link=static runtime-link=static \
--layout=system --lto=on link=static runtime-link=static debug-symbols=off \
toolset=gcc cxxflags="-std=c++14 -fPIC -s" variant="$BuildTypeB2" install -q -d0 -j2
./b2 --prefix="$InstallDir" --build-dir="$RootDir/boost/build" \
--with-python \
--build-type=minimal architecture=x86 address-model=64 threading=multi \
--layout=system link=shared runtime-link=shared \
--layout=system --lto=on link=shared runtime-link=shared debug-symbols=off \
toolset=gcc cxxflags="-std=c++14 -fPIC -s" variant="$BuildTypeB2" install -q -d0 -j2

#################################### Build and install eigen3 ##########################################
Expand All @@ -179,6 +186,7 @@ make install -j2
mkdir -p "$RootDir/eigenpy/build"
cd "$RootDir/eigenpy/build"
cmake "$RootDir/eigenpy" -Wno-dev -DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ENABLE_LTO} \
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-DPYTHON_STANDARD_LAYOUT=ON -DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
Expand Down Expand Up @@ -224,6 +232,7 @@ make install -j2
mkdir -p "$RootDir/assimp/build"
cd "$RootDir/assimp/build"
cmake "$RootDir/assimp" -Wno-dev -DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ENABLE_LTO} \
-DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_ZLIB=ON -DASSIMP_BUILD_TESTS=OFF \
-DASSIMP_BUILD_SAMPLES=OFF -DBUILD_DOCS=OFF \
-DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS="-DNDEBUG -O3 -fPIC -s -Wno-strict-overflow -Wno-class-memaccess" -DCMAKE_BUILD_TYPE="$BUILD_TYPE"
Expand All @@ -241,6 +250,7 @@ make install -j2
mkdir -p "$RootDir/hpp-fcl/build"
cd "$RootDir/hpp-fcl/build"
cmake "$RootDir/hpp-fcl" -Wno-dev -DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ENABLE_LTO} \
-DCMAKE_PREFIX_PATH="$InstallDir" -DQhull_PREFIX="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-DPYTHON_STANDARD_LAYOUT=ON -DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
Expand All @@ -255,6 +265,7 @@ make install -j2
mkdir -p "$RootDir/pinocchio/build"
cd "$RootDir/pinocchio/build"
cmake "$RootDir/pinocchio" -Wno-dev -DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=${ENABLE_LTO} \
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
-DPYTHON_STANDARD_LAYOUT=ON -DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE \
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" \
Expand Down
16 changes: 8 additions & 8 deletions build_tools/build_install_deps_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (-not (Test-Path -PathType Container "$RootDir/eigenpy")) {
}
Set-Location -Path "$RootDir/eigenpy"
git reset --hard
git checkout --force "v2.5.0"
git checkout --force "v2.6.0"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
dos2unix "$RootDir/build_tools/patch_deps_windows/eigenpy.patch"
Expand Down Expand Up @@ -110,7 +110,7 @@ if (-not (Test-Path -PathType Container "$RootDir/hpp-fcl")) {
}
Set-Location -Path "$RootDir/hpp-fcl"
git reset --hard
git checkout --force "v1.5.4"
git checkout --force "v1.6.0"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
dos2unix "$RootDir/build_tools/patch_deps_windows/hppfcl.patch"
Expand All @@ -124,7 +124,7 @@ if (-not (Test-Path -PathType Container "$RootDir/pinocchio")) {
}
Set-Location -Path "$RootDir/pinocchio"
git reset --hard
git checkout --force "v2.5.0"
git checkout --force "v2.5.5"
git submodule --quiet foreach --recursive git reset --quiet --hard
git submodule --quiet update --init --recursive --jobs 8
dos2unix "$RootDir/build_tools/patch_deps_windows/pinocchio.patch"
Expand Down Expand Up @@ -163,12 +163,12 @@ if (-not (Test-Path -PathType Container "$RootDir/boost/build")) {
--with-stacktrace --with-system --with-filesystem --with-atomic `
--with-thread --with-serialization --with-test `
--build-type=minimal architecture=x86 address-model=64 threading=multi `
--layout=system link=static runtime-link=shared `
--layout=system --lto=on link=static runtime-link=shared debug-symbols=off `
toolset=msvc-14.2 variant="$BuildTypeB2" install -q -d0 -j2
./b2.exe --prefix="$InstallDir" --build-dir="$RootDir/boost/build" `
--with-python `
--build-type=minimal architecture=x86 address-model=64 threading=multi `
--layout=system link=shared runtime-link=shared `
--layout=system --lto=on link=shared runtime-link=shared debug-symbols=off `
toolset=msvc-14.2 cxxflags="/permissive-" variant="$BuildTypeB2" install -q -d0 -j2

#################################### Build and install eigen3 ##########################################
Expand All @@ -192,7 +192,7 @@ if (-not (Test-Path -PathType Container "$RootDir/eigenpy/build")) {
Set-Location -Path "$RootDir/eigenpy/build"
cmake "$RootDir/eigenpy" -Wno-dev -G "Visual Studio 16 2019" -T "v142" -DCMAKE_GENERATOR_PLATFORM=x64 `
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON `
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" `
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" `
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE `
Expand Down Expand Up @@ -289,7 +289,7 @@ if (-not (Test-Path -PathType Container "$RootDir/hpp-fcl/build")) {
Set-Location -Path "$RootDir/hpp-fcl/build"
cmake "$RootDir/hpp-fcl" -Wno-dev -G "Visual Studio 16 2019" -T "v142" -DCMAKE_GENERATOR_PLATFORM=x64 `
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON `
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" `
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" `
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE `
Expand All @@ -308,7 +308,7 @@ if (-not (Test-Path -PathType Container "$RootDir/pinocchio/build")) {
Set-Location -Path "$RootDir/pinocchio/build"
cmake "$RootDir/pinocchio" -Wno-dev -G "Visual Studio 16 2019" -T "v142" -DCMAKE_GENERATOR_PLATFORM=x64 `
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" `
-DCMAKE_CXX_STANDARD=14 -DCMAKE_INSTALL_PREFIX="$InstallDir" -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON `
-DCMAKE_PREFIX_PATH="$InstallDir" -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" `
-DBOOST_ROOT="$InstallDir" -DBoost_INCLUDE_DIR="$InstallDir/include" `
-DBoost_NO_SYSTEM_PATHS=TRUE -DBoost_NO_BOOST_CMAKE=TRUE `
Expand Down
141 changes: 0 additions & 141 deletions build_tools/cmake/base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,147 +82,6 @@ if(LEGACY_MODE)
endif()
list(APPEND CMAKE_PREFIX_PATH "/opt/openrobots/")

# Get the required information to build Python bindings
if(BUILD_PYTHON_INTERFACE)
# Get Python executable and version
if(NOT DEFINED PYTHON_EXECUTABLE)
if(${CMAKE_VERSION} VERSION_LESS "3.12.4")
if(PYTHON_REQUIRED_VERSION)
message(FATAL_ERROR "Impossible to handle PYTHON_REQUIRED_VERSION for cmake older than 3.12.4, Cmake will exit.")
endif()
find_program(PYTHON_EXECUTABLE python)
if(NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "No Python executable found, CMake will exit.")
endif()
else()
if(PYTHON_REQUIRED_VERSION)
find_package(Python ${PYTHON_REQUIRED_VERSION} EXACT REQUIRED COMPONENTS Interpreter)
else()
find_package(Python REQUIRED COMPONENTS Interpreter)
endif()
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
endif()
endif()

execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
"import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _VERSION)
string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}")
list(GET _VERSION 0 PYTHON_VERSION_MAJOR)
list(GET _VERSION 1 PYTHON_VERSION_MINOR)
list(GET _VERSION 2 PYTHON_VERSION_PATCH)
set(PYTHON_VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
if(${PYTHON_VERSION_MAJOR} EQUAL 3)
message(STATUS "Found PythonInterp: ${PYTHON_EXECUTABLE} (found version \"${PYTHON_VERSION_STRING}\")")
else()
message(FATAL_ERROR "Python3 is required if BUILD_PYTHON_INTERFACE=ON.")
endif()

# Get Python system and user site-packages
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
"import sysconfig; print(sysconfig.get_paths()['purelib'])"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_SYS_SITELIB)
message(STATUS "Python system site-packages: ${PYTHON_SYS_SITELIB}")
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -m site --user-site
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_USER_SITELIB)
message(STATUS "Python user site-package: ${PYTHON_USER_SITELIB}")

# Check write permissions on Python system site-package to
# determine whether to use user site as fallback.
# It also sets the installation flags
if(NOT WIN32)
execute_process(COMMAND bash -c
"if test -w ${PYTHON_SYS_SITELIB} ; then echo 0; else echo 1; fi"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE HAS_NO_WRITE_PERMISSION_ON_PYTHON_SYS_SITELIB)
else()
set(HAS_NO_WRITE_PERMISSION_ON_PYTHON_SYS_SITELIB FALSE)
endif()

set(PYTHON_INSTALL_FLAGS "--use-feature=2020-resolver ")
if(${HAS_NO_WRITE_PERMISSION_ON_PYTHON_SYS_SITELIB})
set(PYTHON_INSTALL_FLAGS "${PYTHON_INSTALL_FLAGS} --user ")
set(PYTHON_SITELIB "${PYTHON_USER_SITELIB}")
message(STATUS "No right on Python system site-packages: ${PYTHON_SYS_SITELIB}. Installing on user site as fallback.")
else()
set(PYTHON_SITELIB "${PYTHON_SYS_SITELIB}")
endif()

# Get PYTHON_EXT_SUFFIX
set(PYTHON_EXT_SUFFIX "")
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
"from distutils.sysconfig import get_config_var; print(get_config_var('EXT_SUFFIX'))"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_EXT_SUFFIX)
if("${PYTHON_EXT_SUFFIX}" STREQUAL "")
if(NOT WIN32)
set(PYTHON_EXT_SUFFIX ".so")
else()
set(PYTHON_EXT_SUFFIX ".pyd")
endif()
ENDIF()

# Include Python headers
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c
"import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS)

# Add Python library directory to search path on Windows
if(WIN32)
get_filename_component(PYTHON_ROOT ${PYTHON_SYS_SITELIB} DIRECTORY)
get_filename_component(PYTHON_ROOT ${PYTHON_ROOT} DIRECTORY)
link_directories("${PYTHON_ROOT}/libs/")
message(STATUS "Found PythonLibraryDirs: ${PYTHON_ROOT}/libs/")
endif()

# Define NUMPY_INCLUDE_DIRS
find_package(NumPy REQUIRED)

# Define BOOST_PYTHON_LIB
find_package(Boost QUIET REQUIRED)
if(${Boost_MINOR_VERSION} GREATER_EQUAL 67)
# Make sure the shared library is found rather than the static one
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_LIB_PREFIX "")
unset(Boost_LIBRARIES)
find_package(Boost REQUIRED COMPONENTS
"python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}"
"numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
set(BOOST_PYTHON_LIB "${Boost_LIBRARIES}")
unset(Boost_LIBRARIES)
if(WIN32)
set(Boost_LIB_PREFIX "lib")
endif()
set(Boost_USE_STATIC_LIBS ON)
else()
set(BOOST_PYTHON_LIB "boost_numpy3;boost_python3")
endif()
message(STATUS "Boost Python Libs: ${BOOST_PYTHON_LIB}")

# Define Python install helpers
function(deployPythonPackage)
# The input arguments are [TARGET_NAME...]
foreach(TARGET_NAME IN LISTS ARGN)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_INSTALL_FLAGS} .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pypi/${TARGET_NAME})
execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_INSTALL_FLAGS} --upgrade --no-deps --force-reinstall .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/pypi/${TARGET_NAME})")
endforeach()
endfunction()

function(deployPythonPackageDevelop)
# The input arguments are [TARGET_NAME...]
foreach(TARGET_NAME IN LISTS ARGN)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_INSTALL_FLAGS} -e .
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/${TARGET_NAME})")
endforeach()
endfunction()
endif()

# Due to license considerations, we will only use the MPL2 parts of Eigen.
set(EIGEN_MPL2_ONLY 1)

Expand Down
Loading

0 comments on commit c469a1f

Please sign in to comment.