Skip to content
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
14 changes: 13 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ jobs:
python-version: '3.7'

- name: Install requirements
shell: bash
run: |
brew install eigen boost
brew install ccache ninja
brew list | grep python | while read package; do
brew unlink $package
done
python3 -m pip install numpy scipy

- name: pybind11 cache files
Expand Down Expand Up @@ -93,6 +97,9 @@ jobs:
CCACHE_COMPRESSLEVEL: 6
CCACHE_MAXSIZE: "500M"
run: |
echo "RUNNER_TOOL_CACHE = $RUNNER_TOOL_CACHE"
python_root="$(find $RUNNER_TOOL_CACHE -maxdepth 3 -type d -path '**/Python/3.7*/x64')"
echo "python_root = $python_root"
export CCACHE_BASEDIR=$GITHUB_WORKSPACE
export CCACHE_DIR=$GITHUB_WORKSPACE/.ccache
ccache -z
Expand All @@ -102,7 +109,8 @@ jobs:
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake \
-DCMAKE_BUILD_TYPE=Release \
-DPYTHON_EXECUTABLE=$(which python3.7) \
-DPython_EXECUTABLE=$(which python3.7) \
-DPython_ROOT=$python_root \
.
ninja install
echo ${CCACHE_BASEDIR}
Expand Down Expand Up @@ -152,8 +160,12 @@ jobs:
python-version: '3.7'

- name: Install requirements
shell: bash
run: |
brew install boost
brew list | grep python | while read package; do
brew unlink $package
done
python3 -m pip install numpy scipy

- name: Download and install the latest SOFA ${{ matrix.sofa_branch }} binaries
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ jobs:
CCACHE_COMPRESSLEVEL: 6
CCACHE_MAXSIZE: "500M"
run: |
echo "RUNNER_TOOL_CACHE = $RUNNER_TOOL_CACHE"
python_root="$(find $RUNNER_TOOL_CACHE -maxdepth 3 -type d -path '**/Python/3.7*/x64')"
echo "python_root = $python_root"
export CCACHE_BASEDIR=$GITHUB_WORKSPACE
export CCACHE_DIR=$GITHUB_WORKSPACE/.ccache
ccache -z
Expand All @@ -102,7 +105,8 @@ jobs:
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake \
-DCMAKE_BUILD_TYPE=Release \
-DPYTHON_EXECUTABLE=$(which python3.7) \
-DPython_EXECUTABLE=$(which python3.7) \
-DPython_ROOT=$python_root \
.
ninja install
echo ${CCACHE_BASEDIR}
Expand Down
52 changes: 34 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,36 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set the minimum python version to 3.7
set(PYBIND11_PYTHON_VERSION 3.7)

# Find Python3 executable and set PYTHON_EXECUTABLE before finding pybind11
# to be sure that pybind11 relies on the right Python version
set(python_version "${PYBIND11_PYTHON_VERSION}")
set(python_version_flag "")
if(PYTHON_EXECUTABLE)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "--version"
OUTPUT_VARIABLE cmd_output
)
string(REGEX MATCH "[0-9]+\.[0-9]+" python_exec_version "${cmd_output}")
if(python_exec_version VERSION_GREATER_EQUAL PYBIND11_PYTHON_VERSION)
set(python_version "${python_exec_version}")
set(python_version_flag "EXACT")
endif()
endif()
find_package(Python ${python_version} ${python_version_flag} COMPONENTS Interpreter Development REQUIRED)
# Find Python3
find_package(Python ${PYBIND11_PYTHON_VERSION} COMPONENTS Interpreter Development REQUIRED)

# Save PYTHON_* vars
set(PYTHON_VERSION_RESET "${PYTHON_VERSION}")
set(PYTHON_EXECUTABLE_RESET "${PYTHON_EXECUTABLE}")
set(PYTHON_LIBRARIES_RESET "${PYTHON_LIBRARIES}")
set(PYTHON_INCLUDE_DIRS_RESET "${PYTHON_INCLUDE_DIRS}")
set(PYTHON_LIBRARY_RESET "${PYTHON_LIBRARY}")
set(PYTHON_INCLUDE_DIR_RESET "${PYTHON_INCLUDE_DIR}")

# Change PYTHON_* vars before pybind11 find_package
# to be sure that pybind11 relies on the right Python version
set(PYTHON_VERSION "${Python_VERSION}" CACHE STRING "" FORCE)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}" CACHE FILEPATH "" FORCE)
set(PYTHON_LIBRARIES "${Python_LIBRARIES}" CACHE STRING "" FORCE)
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}" CACHE STRING "" FORCE)
if(EXISTS "${Python_LIBRARY}")
set(PYTHON_LIBRARY "${Python_LIBRARY}" CACHE INTERNAL "" FORCE)
elseif(EXISTS "${Python_LIBRARIES}")
set(PYTHON_LIBRARY "${Python_LIBRARIES}" CACHE INTERNAL "" FORCE)
endif()
if(EXISTS "${Python_INCLUDE_DIR}")
set(PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIR}" CACHE INTERNAL "" FORCE)
elseif(EXISTS "${Python_INCLUDE_DIRS}")
set(PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
endif()

# Set the minimum pybind11 version to 2.3 (before that the pybind11::embed target did not exist)
find_package(pybind11 2.3 CONFIG QUIET REQUIRED)
set(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE_RESET}" CACHE FILEPATH "" FORCE)

set(SP3_PYTHON_PACKAGES_DIRECTORY
"python3/site-packages"
Expand Down Expand Up @@ -138,7 +146,7 @@ message(STATUS "Python:
Executable: ${Python_EXECUTABLE}
Headers: ${Python_INCLUDE_DIRS}
Libraries: ${Python_LIBRARIES}
User site: ${Python_USER_SITE}"
User site: ${PYTHON_USER_SITE}"
)
message(STATUS "pybind11:
Version: ${pybind11_VERSION}
Expand Down Expand Up @@ -224,3 +232,11 @@ if (SP3_LINK_TO_USER_SITE AND SP3_PYTHON_PACKAGES_LINK_DIRECTORY)
endif()
endforeach()
endif()

# Reset PYTHON_* vars
set(PYTHON_VERSION "${PYTHON_VERSION_RESET}" CACHE STRING "" FORCE)
set(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE_RESET}" CACHE FILEPATH "" FORCE)
set(PYTHON_LIBRARIES "${PYTHON_LIBRARIES_RESET}" CACHE STRING "" FORCE)
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS_RESET}" CACHE STRING "" FORCE)
set(PYTHON_LIBRARY "${PYTHON_LIBRARY_RESET}" CACHE INTERNAL "" FORCE)
set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR_RESET}" CACHE INTERNAL "" FORCE)
44 changes: 33 additions & 11 deletions SofaPython3Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,45 @@ set(SP3_PYTHON_PACKAGES_DIRECTORY @SP3_PYTHON_PACKAGES_DIRECTORY@)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
include(SofaPython3Tools)

# Find Python3 executable and set PYTHON_EXECUTABLE before finding pybind11
# to be sure that pybind11 relies on the right Python version
set(python_version @PYTHON_VERSION@)
set(python_version_flag @python_version_flag@)
# Find Python3
find_package(Python @PYBIND11_PYTHON_VERSION@ COMPONENTS Interpreter Development REQUIRED)

find_package(Python ${python_version} ${python_version_flag} COMPONENTS Interpreter Development REQUIRED)
# Save PYTHON_* vars
set(PYTHON_VERSION_RESET "${PYTHON_VERSION}")
set(PYTHON_EXECUTABLE_RESET "${PYTHON_EXECUTABLE}")
set(PYTHON_LIBRARIES_RESET "${PYTHON_LIBRARIES}")
set(PYTHON_INCLUDE_DIRS_RESET "${PYTHON_INCLUDE_DIRS}")
set(PYTHON_LIBRARY_RESET "${PYTHON_LIBRARY}")
set(PYTHON_INCLUDE_DIR_RESET "${PYTHON_INCLUDE_DIR}")

set(PYTHON_VERSION ${Python_VERSION})
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(PYTHON_LIBRARIES ${Python_LIBRARIES})
set(PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
set(PYTHON_LIBRARY ${Python_LIBRARY})
set(PYTHON_INCLUDE_DIR ${Python_INCLUDE_DIR})
# Change PYTHON_* vars before pybind11 find_package
# to be sure that pybind11 relies on the right Python version
set(PYTHON_VERSION "${Python_VERSION}" CACHE STRING "" FORCE)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}" CACHE FILEPATH "" FORCE)
set(PYTHON_LIBRARIES "${Python_LIBRARIES}" CACHE STRING "" FORCE)
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}" CACHE STRING "" FORCE)
if(EXISTS "${Python_LIBRARY}")
set(PYTHON_LIBRARY "${Python_LIBRARY}" CACHE INTERNAL "" FORCE)
elseif(EXISTS "${Python_LIBRARIES}")
set(PYTHON_LIBRARY "${Python_LIBRARIES}" CACHE INTERNAL "" FORCE)
endif()
if(EXISTS "${Python_INCLUDE_DIR}")
set(PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIR}" CACHE INTERNAL "" FORCE)
elseif(EXISTS "${Python_INCLUDE_DIRS}")
set(PYTHON_INCLUDE_DIR "${Python_INCLUDE_DIRS}" CACHE INTERNAL "" FORCE)
endif()

# Set the minimum pybind11 version to 2.3 (before that the pybind11::embed target did not exist)
find_package(pybind11 2.3 CONFIG QUIET REQUIRED)

# Reset PYTHON_* vars
set(PYTHON_VERSION "${PYTHON_VERSION_RESET}" CACHE STRING "" FORCE)
set(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE_RESET}" CACHE FILEPATH "" FORCE)
set(PYTHON_LIBRARIES "${PYTHON_LIBRARIES_RESET}" CACHE STRING "" FORCE)
set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS_RESET}" CACHE STRING "" FORCE)
set(PYTHON_LIBRARY "${PYTHON_LIBRARY_RESET}" CACHE INTERNAL "" FORCE)
set(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_DIR_RESET}" CACHE INTERNAL "" FORCE)

if(NOT SofaPython3_FIND_COMPONENTS)
set(SofaPython3_FIND_COMPONENTS Plugin Bindings)
endif()
Expand Down