In-place cython build
Build everything inside the build/cython{BuildType} directory directly, so we can bypass the `make install` step and introduce the `make python-install` step which allows cmake to handle all dependencies.release/4.3a0
parent
54f2acd521
commit
8859b963a2
|
@ -454,15 +454,13 @@ endif()
|
||||||
if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
||||||
set(GTSAM_INSTALL_CYTHON_TOOLBOX 1)
|
set(GTSAM_INSTALL_CYTHON_TOOLBOX 1)
|
||||||
# Set up cache options
|
# Set up cache options
|
||||||
set(GTSAM_CYTHON_PATH "${PROJECT_BINARY_DIR}/cython" CACHE PATH "Cython source files directory path")
|
|
||||||
# Cython install path appended with Build type (e.g. cython, cythonDebug, etc).
|
# Cython install path appended with Build type (e.g. cython, cythonDebug, etc).
|
||||||
set(GTSAM_CYTHON_INSTALL_PATH "" CACHE PATH "Cython toolbox destination, blank defaults to PROJECT_BINARY_DIR/cython.build<GTSAM_BUILD_TAG>")
|
set(GTSAM_CYTHON_INSTALL_PATH "" CACHE PATH "Cython toolbox destination, blank defaults to PROJECT_BINARY_DIR/cython<GTSAM_BUILD_TAG>")
|
||||||
if(NOT GTSAM_CYTHON_INSTALL_PATH)
|
if(NOT GTSAM_CYTHON_INSTALL_PATH)
|
||||||
set(GTSAM_CYTHON_INSTALL_PATH "${PROJECT_BINARY_DIR}/cython.build${GTSAM_BUILD_TAG}")
|
set(GTSAM_CYTHON_INSTALL_PATH "${PROJECT_BINARY_DIR}/cython${GTSAM_BUILD_TAG}" CACHE PATH "")
|
||||||
endif()
|
endif()
|
||||||
set(GTSAM_EIGENCY_PATH ${GTSAM_CYTHON_PATH}/gtsam_eigency)
|
|
||||||
set(GTSAM_EIGENCY_INSTALL_PATH ${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency)
|
set(GTSAM_EIGENCY_INSTALL_PATH ${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency)
|
||||||
add_subdirectory(cython)
|
add_subdirectory(cython ${GTSAM_CYTHON_INSTALL_PATH})
|
||||||
else()
|
else()
|
||||||
set(GTSAM_INSTALL_CYTHON_TOOLBOX 0) # This will go into config.h
|
set(GTSAM_INSTALL_CYTHON_TOOLBOX 0) # This will go into config.h
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -41,9 +41,9 @@ execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
|
||||||
function(wrap_and_install_library_cython interface_header extra_imports install_path libs dependencies)
|
function(wrap_and_install_library_cython interface_header extra_imports install_path libs dependencies)
|
||||||
# Paths for generated files
|
# Paths for generated files
|
||||||
get_filename_component(module_name "${interface_header}" NAME_WE)
|
get_filename_component(module_name "${interface_header}" NAME_WE)
|
||||||
set(generated_files_path "${PROJECT_BINARY_DIR}/cython/${module_name}")
|
set(generated_files_path "${GTSAM_CYTHON_INSTALL_PATH}/${module_name}")
|
||||||
wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${libs}" "${dependencies}")
|
wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${libs}" "${dependencies}")
|
||||||
install_cython_wrapped_library("${interface_header}" "${generated_files_path}" "${install_path}")
|
# install_cython_wrapped_library("${interface_header}" "${generated_files_path}" "${install_path}")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(set_up_required_cython_packages)
|
function(set_up_required_cython_packages)
|
||||||
|
@ -214,7 +214,7 @@ function(install_cython_scripts source_directory dest_directory patterns)
|
||||||
list(APPEND patterns_args PATTERN "${pattern}")
|
list(APPEND patterns_args PATTERN "${pattern}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
install(DIRECTORY "${source_directory}" DESTINATION "${dest_directory}" CONFIGURATIONS "${CMAKE_BUILD_TYPE}"
|
file(COPY "${source_directory}" DESTINATION "${dest_directory}"
|
||||||
FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE)
|
FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,37 @@
|
||||||
# Create directory where cython build files will be placed
|
|
||||||
file(MAKE_DIRECTORY ${GTSAM_CYTHON_INSTALL_PATH})
|
|
||||||
|
|
||||||
# Install cython components
|
# Install cython components
|
||||||
include(GtsamCythonWrap)
|
include(GtsamCythonWrap)
|
||||||
|
|
||||||
# Create the cython toolbox for the gtsam library
|
# Create the cython toolbox for the gtsam library
|
||||||
if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
||||||
|
# Add the new make target command
|
||||||
|
add_custom_target(python-install
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} ${GTSAM_CYTHON_INSTALL_PATH}/setup.py install
|
||||||
|
WORKING_DIRECTORY ${GTSAM_CYTHON_INSTALL_FULLPATH})
|
||||||
|
|
||||||
# build and include the eigency version of eigency
|
# build and include the eigency version of eigency
|
||||||
add_subdirectory(gtsam_eigency)
|
add_subdirectory(gtsam_eigency)
|
||||||
include_directories(${GTSAM_EIGENCY_PATH})
|
include_directories(${GTSAM_EIGENCY_INSTALL_PATH})
|
||||||
|
|
||||||
# Fix for error "C1128: number of sections exceeded object file format limit"
|
# Fix for error "C1128: number of sections exceeded object file format limit"
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_compile_options(/bigobj)
|
add_compile_options(/bigobj)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# wrap gtsam
|
# First set up all the package related files.
|
||||||
|
# This also ensures the below wrap operations work correctly.
|
||||||
|
set(CYTHON_INSTALL_REQUIREMENTS_FILE "${PROJECT_SOURCE_DIR}/cython/requirements.txt")
|
||||||
|
|
||||||
|
# Install the custom-generated __init__.py
|
||||||
|
# This makes the cython (sub-)directories into python packages, so gtsam can be found while wrapping gtsam_unstable
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cython/gtsam/__init__.py ${GTSAM_CYTHON_INSTALL_PATH}/gtsam/__init__.py COPYONLY)
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cython/gtsam_unstable/__init__.py ${GTSAM_CYTHON_INSTALL_PATH}/gtsam_unstable/__init__.py COPYONLY)
|
||||||
|
configure_file(${PROJECT_SOURCE_DIR}/cython/setup.py.in ${GTSAM_CYTHON_INSTALL_PATH}/setup.py)
|
||||||
|
install_cython_files("${PROJECT_BINARY_DIR}/cython/setup.py" "${GTSAM_CYTHON_INSTALL_PATH}")
|
||||||
|
# install scripts and tests
|
||||||
|
install_cython_scripts("${PROJECT_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py")
|
||||||
|
install_cython_scripts("${PROJECT_SOURCE_DIR}/cython/gtsam_unstable" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py")
|
||||||
|
|
||||||
|
# Wrap gtsam
|
||||||
add_custom_target(gtsam_header DEPENDS "../gtsam.h")
|
add_custom_target(gtsam_header DEPENDS "../gtsam.h")
|
||||||
wrap_and_install_library_cython("../gtsam.h" # interface_header
|
wrap_and_install_library_cython("../gtsam.h" # interface_header
|
||||||
"" # extra imports
|
"" # extra imports
|
||||||
|
@ -23,8 +39,9 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
||||||
gtsam # library to link with
|
gtsam # library to link with
|
||||||
"wrap;cythonize_eigency;gtsam;gtsam_header" # dependencies which need to be built before wrapping
|
"wrap;cythonize_eigency;gtsam;gtsam_header" # dependencies which need to be built before wrapping
|
||||||
)
|
)
|
||||||
|
add_dependencies(python-install gtsam gtsam_header)
|
||||||
|
|
||||||
# wrap gtsam_unstable
|
# Wrap gtsam_unstable
|
||||||
if(GTSAM_BUILD_UNSTABLE)
|
if(GTSAM_BUILD_UNSTABLE)
|
||||||
add_custom_target(gtsam_unstable_header DEPENDS "../gtsam_unstable/gtsam_unstable.h")
|
add_custom_target(gtsam_unstable_header DEPENDS "../gtsam_unstable/gtsam_unstable.h")
|
||||||
wrap_and_install_library_cython("../gtsam_unstable/gtsam_unstable.h" # interface_header
|
wrap_and_install_library_cython("../gtsam_unstable/gtsam_unstable.h" # interface_header
|
||||||
|
@ -33,27 +50,7 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX)
|
||||||
gtsam_unstable # library to link with
|
gtsam_unstable # library to link with
|
||||||
"gtsam_unstable;gtsam_unstable_header;cythonize_gtsam" # dependencies to be built before wrapping
|
"gtsam_unstable;gtsam_unstable_header;cythonize_gtsam" # dependencies to be built before wrapping
|
||||||
)
|
)
|
||||||
|
add_dependencies(python-install gtsam_unstable gtsam_unstable_header)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CYTHON_INSTALL_REQUIREMENTS_FILE "${PROJECT_SOURCE_DIR}/cython/requirements.txt")
|
|
||||||
|
|
||||||
# Install the custom-generated __init__.py
|
|
||||||
# This is to make the build/cython/gtsam folder a python package, so gtsam can be found while wrapping gtsam_unstable
|
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/cython/gtsam/__init__.py ${PROJECT_BINARY_DIR}/cython/gtsam/__init__.py COPYONLY)
|
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/cython/gtsam_unstable/__init__.py ${PROJECT_BINARY_DIR}/cython/gtsam_unstable/__init__.py COPYONLY)
|
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/cython/setup.py.in ${PROJECT_BINARY_DIR}/cython/setup.py)
|
|
||||||
install_cython_files("${PROJECT_BINARY_DIR}/cython/setup.py" "${GTSAM_CYTHON_INSTALL_PATH}")
|
|
||||||
# install scripts and tests
|
|
||||||
install_cython_scripts("${PROJECT_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py")
|
|
||||||
install_cython_scripts("${PROJECT_SOURCE_DIR}/cython/gtsam_unstable" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py")
|
|
||||||
|
|
||||||
# Install gtsam_eigency.
|
|
||||||
# The paths are picked up directly from the parent CMakeLists.txt.
|
|
||||||
install_gtsam_eigency()
|
|
||||||
|
|
||||||
# Automatically run the python installation via the setup.py
|
|
||||||
install(CODE
|
|
||||||
"execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py install
|
|
||||||
WORKING_DIRECTORY ${GTSAM_CYTHON_INSTALL_PATH})")
|
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -4,7 +4,7 @@ include(GtsamCythonWrap)
|
||||||
# so that the cython-generated header "conversions_api.h" can be found when cythonizing eigency's core
|
# so that the cython-generated header "conversions_api.h" can be found when cythonizing eigency's core
|
||||||
# and eigency's cython pxd headers can be found when cythonizing gtsam
|
# and eigency's cython pxd headers can be found when cythonizing gtsam
|
||||||
file(COPY "." DESTINATION ".")
|
file(COPY "." DESTINATION ".")
|
||||||
set(OUTPUT_DIR "${GTSAM_CYTHON_PATH}/gtsam_eigency")
|
set(OUTPUT_DIR "${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency")
|
||||||
set(EIGENCY_INCLUDE_DIR ${OUTPUT_DIR})
|
set(EIGENCY_INCLUDE_DIR ${OUTPUT_DIR})
|
||||||
|
|
||||||
# This is to make the build/cython/gtsam_eigency folder a python package
|
# This is to make the build/cython/gtsam_eigency folder a python package
|
||||||
|
@ -36,18 +36,3 @@ target_include_directories(cythonize_eigency_core PUBLIC
|
||||||
add_dependencies(cythonize_eigency_core cythonize_eigency_conversions)
|
add_dependencies(cythonize_eigency_core cythonize_eigency_conversions)
|
||||||
add_custom_target(cythonize_eigency)
|
add_custom_target(cythonize_eigency)
|
||||||
add_dependencies(cythonize_eigency cythonize_eigency_conversions cythonize_eigency_core)
|
add_dependencies(cythonize_eigency cythonize_eigency_conversions cythonize_eigency_core)
|
||||||
|
|
||||||
# install
|
|
||||||
function(install_gtsam_eigency)
|
|
||||||
install(DIRECTORY ${GTSAM_EIGENCY_PATH}
|
|
||||||
DESTINATION "${GTSAM_CYTHON_INSTALL_PATH}"
|
|
||||||
PATTERN "CMakeLists.txt" EXCLUDE
|
|
||||||
PATTERN "__init__.py.in" EXCLUDE
|
|
||||||
PATTERN "*.dir" EXCLUDE
|
|
||||||
PATTERN "*.make" EXCLUDE)
|
|
||||||
install(TARGETS cythonize_eigency_core cythonize_eigency_conversions
|
|
||||||
DESTINATION "${GTSAM_EIGENCY_INSTALL_PATH}")
|
|
||||||
install(FILES ${GTSAM_EIGENCY_PATH}/conversions_api.h DESTINATION ${GTSAM_EIGENCY_INSTALL_PATH})
|
|
||||||
install(FILES ${GTSAM_EIGENCY_PATH}/__init__.py DESTINATION ${GTSAM_EIGENCY_INSTALL_PATH})
|
|
||||||
|
|
||||||
endfunction()
|
|
||||||
|
|
Loading…
Reference in New Issue