Skip to content
Closed
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
45 changes: 37 additions & 8 deletions CMake/SofaPython3Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ function(SP3_configure_directory input_folder output_folder)
endforeach()
endfunction()

# - Recursively configure files inside a directory. Takes the same argument as configure_file, but here the input
# parameter is a path to a directory.
function(SP3_make_link target_folder symbolic_link_folder)
get_filename_component(relative_directory ${symbolic_link_folder} DIRECTORY)
make_directory("${relative_directory}")
message(" -- Link: ${target_folder} ${symbolic_link_folder}")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${target_folder} ${symbolic_link_folder})
endfunction()



# - Get the path to the Python's user site packages directory (for example, $HOME/.local/lib/pythonX.Y/site-packages
# PYTHON_USER_SITE - (output) The path to Python's site packages directory, or FALSE if not found
macro(SP3_get_python_user_site)
Expand All @@ -38,7 +49,8 @@ endmacro()
# SP3_add_python_package(PACKAGE_NAME SOURCE_DIRECTORY TARGET_DIRECTORY)
# SOURCE_DIRECTORY - (input) the source path of the directory to be configured and copied to the target directory.
# TARGET_DIRECTORY - (input) the target path of the directory that will contain the configured files.
# Files will be at LIBRARY_OUTPUT_DIRECTORY/SP3_PYTHON_PACKAGES_DIRECTORY/TARGET_DIRECTORY.
#
# Files will be at LIBRARY_OUTPUT_DIRECTORY/SP3_PYTHON_PACKAGES_DIRECTORY/TARGET_DIRECTORY.
function(SP3_add_python_package)
set(options)
set(oneValueArgs PACKAGE_NAME SOURCE_DIRECTORY TARGET_DIRECTORY )
Expand All @@ -47,20 +59,37 @@ function(SP3_add_python_package)
cmake_parse_arguments(A "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

file(GLOB_RECURSE files RELATIVE ${A_SOURCE_DIRECTORY} ${A_SOURCE_DIRECTORY}/*)
set(abs_files "")

file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY})
message("Creating directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}" )

set(python3_dist_package ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python3/dist-packages/ )
set(python3_site_package ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/ )

foreach(file_relative_path ${files})
if(${file_relative_path} MATCHES "\.pyc$")
continue()
endif()
set(file_absolute_path ${A_SOURCE_DIRECTORY}/${file_relative_path})
configure_file(
${file_absolute_path}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}/${file_relative_path}
@ONLY
)
list(APPEND abs_files ${file_absolute_path})
get_filename_component(relative_directory ${file_relative_path} DIRECTORY)

file(MAKE_DIRECTORY "${python3_site_package}/${A_TARGET_DIRECTORY}/${relative_directory}")
file(MAKE_DIRECTORY "${python3_dist_package}/${A_TARGET_DIRECTORY}/${relative_directory}")

SP3_make_link(${file_absolute_path} "${python3_site_package}/${A_TARGET_DIRECTORY}/${file_relative_path}")

#message(" -- copy ${file_absolute_path} to ${python3_dist_package}/${A_TARGET_DIRECTORY}/${file_relative_path}")
file(COPY ${file_absolute_path} DESTINATION ${python3_dist_package}/${A_TARGET_DIRECTORY}/${relative_directory})

install(
FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}/${file_relative_path}"
FILES "${python3_dist_package}${A_TARGET_DIRECTORY}/${file_relative_path}"
DESTINATION "${LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}/${relative_directory}"
)
endforeach()

string(REPLACE "/" "." OUTDIR ${A_TARGET_DIRECTORY})
add_custom_target(PythonPackage_${OUTDIR} SOURCES ${abs_files})
message(STATUS "Python package ${A_SOURCE_DIRECTORY} added to directory ${SP3_PYTHON_PACKAGES_DIRECTORY}/${A_TARGET_DIRECTORY}")
endfunction()

Expand Down
21 changes: 10 additions & 11 deletions bindings/Sofa/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ find_package(SofaFramework REQUIRED)
enable_testing()
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES} ${PYTHON_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaHelper SofaPython3::Plugin SofaPython3::Bindings.Sofa SofaPython3::Bindings.SofaTypes SofaPython3::Bindings.SofaRuntime)
target_compile_definitions(${PROJECT_NAME} PRIVATE "PYTHON_TESTFILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"")

set(RPATH "$ORIGIN/../lib")
if (APPLE)
Expand All @@ -54,20 +53,20 @@ set_target_properties(

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/Components ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Components)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Components DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/Components ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/Components)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Components DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa)

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/Core ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Core)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Core DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/Core ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/Core)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Core DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa)

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/Helper ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Helper)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Helper DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/Helper ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/Helper)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Helper DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/)

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/Simulation ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Simulation)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Simulation DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/Simulation ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/Simulation)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Simulation DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa)

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/Types ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Types)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/Types DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/Types ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa/Types)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Types DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/Sofa)

install(
TARGETS ${PROJECT_NAME}
Expand Down
10 changes: 5 additions & 5 deletions bindings/Sofa/tests/PythonModule_Sofa_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ static struct PythonModule_Sofa_tests : public PythonTestList
PythonModule_Sofa_tests()
{
const std::string executable_directory = sofa::helper::Utils::getExecutableDirectory();
addTestDir(executable_directory+"/Components", "Sofa_Components_");
addTestDir(executable_directory+"/Core", "Sofa_Core_");
addTestDir(executable_directory+"/Helper", "Sofa_Helper_");
addTestDir(executable_directory+"/Simulation", "Sofa_Simulation_");
addTestDir(executable_directory+"/Types", "Sofa_Types_");
addTestDir(executable_directory+"/tests/Sofa/Components", "Sofa_Components_");
addTestDir(executable_directory+"/tests/Sofa/Core", "Sofa_Core_");
addTestDir(executable_directory+"/tests/Sofa/Helper", "Sofa_Helper_");
addTestDir(executable_directory+"/tests/Sofa/Simulation", "Sofa_Simulation_");
addTestDir(executable_directory+"/tests/Sofa/Types", "Sofa_Types_");
}
} python_tests;

Expand Down
9 changes: 4 additions & 5 deletions bindings/SofaExporter/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ set(SOURCE_FILES
)

set(PYTHON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/tests/STLExporter.py
${CMAKE_CURRENT_SOURCE_DIR}/test-files/STLExporter.py
)

find_package(SofaGTestMain REQUIRED)
find_package(SofaFramework REQUIRED)

add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${PYTHON_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaHelper SofaPython3::Plugin SofaPython3::Bindings.SofaExporter)
target_compile_definitions(${PROJECT_NAME} PRIVATE "PYTHON_TESTFILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\"")

set_target_properties(
${PROJECT_NAME}
Expand All @@ -24,10 +23,10 @@ set_target_properties(

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/tests ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/test-files ${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaExporter)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test-files DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaExporter)

install(
TARGETS ${PROJECT_NAME}
EXPORT BindingsTargets
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static struct PythonModule_SofaExporter_tests : public PythonTestList
PythonModule_SofaExporter_tests()
{
const std::string executable_directory = sofa::helper::Utils::getExecutableDirectory();
addTestDir(executable_directory+"/tests", "SofaExporter_");
addTestDir(executable_directory+"/tests/SofaExporter", "SofaExporter_");
}
} python_tests;

Expand Down
7 changes: 3 additions & 4 deletions bindings/SofaRuntime/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(SOURCE_FILES
)

set(PYTHON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/tests/Base.py
${CMAKE_CURRENT_SOURCE_DIR}/test-files/Base.py
)

find_package(SofaGTestMain REQUIRED)
Expand All @@ -14,7 +14,6 @@ find_package(SofaFramework REQUIRED)
enable_testing()
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${PYTHON_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaHelper SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core)
target_compile_definitions(${PROJECT_NAME} PRIVATE "PYTHON_TESTFILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")

set(RPATH "$ORIGIN/../lib")
if (APPLE)
Expand All @@ -30,8 +29,8 @@ set_target_properties(

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/tests ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/test-files ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaRuntime)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test-files DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaRuntime)

install(
TARGETS ${PROJECT_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static struct PythonModule_Sofa_tests : public PythonTestList
PythonModule_Sofa_tests()
{
const std::string executable_directory = sofa::helper::Utils::getExecutableDirectory();
addTestDir(executable_directory+"/tests", "SofaRuntime_");
addTestDir(executable_directory+"/tests/SofaRuntime", "SofaRuntime_");
}
} python_tests;

Expand Down
7 changes: 3 additions & 4 deletions bindings/SofaTypes/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(SOURCE_FILES
)

set(PYTHON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/pyfiles/vector_test.py
${CMAKE_CURRENT_SOURCE_DIR}/test-files/vector_test.py
)

find_package(SofaGTestMain REQUIRED)
Expand All @@ -14,7 +14,6 @@ find_package(SofaFramework REQUIRED)
enable_testing()
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${PYTHON_FILES})
target_link_libraries(${PROJECT_NAME} SofaGTestMain SofaHelper SofaPython3::Plugin)
target_compile_definitions(${PROJECT_NAME} PRIVATE "PYTHON_TESTFILES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/pyfiles/\"")

set(RPATH "$ORIGIN/../lib")
if (APPLE)
Expand All @@ -30,8 +29,8 @@ set_target_properties(

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

SP3_configure_directory(${CMAKE_CURRENT_SOURCE_DIR}/pyfiles ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/pyfiles)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/pyfiles DESTINATION ${RUNTIME_OUTPUT_DIRECTORY})
SP3_make_link(${CMAKE_CURRENT_SOURCE_DIR}/test-files ${CMAKE_BINARY_DIR}/${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaTypes)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test-files DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/tests/SofaTypes)

install(
TARGETS ${PROJECT_NAME}
Expand Down
2 changes: 1 addition & 1 deletion bindings/SofaTypes/tests/PythonModule_SofaTypes_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace
PythonModule_SofaTypes_test()
{
const std::string executable_directory = sofa::helper::Utils::getExecutableDirectory();
addTestDir(executable_directory+"/pyfiles", "SofaTypes_");
addTestDir(executable_directory+"/tests/SofaTypes", "SofaTypes_");
}
} python_tests;

Expand Down