diff --git a/cmake/GtsamCythonWrap.cmake b/cmake/GtsamCythonWrap.cmake index d4bff5537..6f378f77d 100644 --- a/cmake/GtsamCythonWrap.cmake +++ b/cmake/GtsamCythonWrap.cmake @@ -84,14 +84,18 @@ endfunction() # - output_dir: The output directory # - include_dirs: Directories to include when executing cython # - libs: Libraries to link with -# - dependencies: Other target dependencies -function(cythonize target pyx_file output_lib_we output_dir include_dirs libs dependencies) +# - interface_header: For dependency. Any update in interface header will re-trigger cythonize +function(cythonize target pyx_file output_lib_we output_dir include_dirs libs interface_header dependencies) get_filename_component(pyx_path "${pyx_file}" DIRECTORY) get_filename_component(pyx_name "${pyx_file}" NAME_WE) set(generated_cpp "${output_dir}/${pyx_name}.cpp") set_up_required_cython_packages() pyx_to_cpp(${target}_pyx2cpp ${pyx_file} ${generated_cpp} "${include_dirs}") + + # Late dependency injection, to make sure this gets called whenever the interface header is updated + # See: https://stackoverflow.com/questions/40032593/cmake-does-not-rebuild-dependent-after-prerequisite-changes + add_custom_command(OUTPUT ${generated_cpp} DEPENDS ${interface_header} APPEND) if (NOT "${dependencies}" STREQUAL "") add_dependencies(${target}_pyx2cpp "${dependencies}") endif() @@ -130,8 +134,8 @@ function(wrap_library_cython interface_header generated_files_path extra_imports message(STATUS "Cythonize and build ${module_name}.pyx") get_property(include_dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) - cythonize(${module_name}_cython ${generated_pyx} ${module_name} - ${generated_files_path} "${include_dirs}" "${libs}" cython_wrap_${module_name}_pyx) + cythonize(cythonize_${module_name} ${generated_pyx} ${module_name} + ${generated_files_path} "${include_dirs}" "${libs}" ${interface_header} cython_wrap_${module_name}_pyx) # distclean add_custom_target(wrap_${module_name}_cython_distclean diff --git a/cython/CMakeLists.txt b/cython/CMakeLists.txt index c264b8f37..bc21b91d1 100644 --- a/cython/CMakeLists.txt +++ b/cython/CMakeLists.txt @@ -24,7 +24,7 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX) "from gtsam.gtsam cimport *" # extra imports "${GTSAM_CYTHON_INSTALL_PATH}/gtsam" # install path gtsam_unstable # library to link with - "gtsam_unstable;gtsam_unstable_header;gtsam_cython" # dependencies to be built before wrapping + "gtsam_unstable;gtsam_unstable_header;cythonize_gtsam" # dependencies to be built before wrapping ) # for some reasons cython gtsam_unstable can't find gtsam/gtsam.pxd without doing this file(WRITE ${PROJECT_BINARY_DIR}/cython/gtsam_unstable/__init__.py "") diff --git a/cython/gtsam_eigency/CMakeLists.txt b/cython/gtsam_eigency/CMakeLists.txt index 5fa9e7cc0..54b7de9aa 100644 --- a/cython/gtsam_eigency/CMakeLists.txt +++ b/cython/gtsam_eigency/CMakeLists.txt @@ -19,9 +19,9 @@ message(STATUS "Cythonize and build eigency") # a part of the gtsam_eigency package and generate the function call import_gtsam_igency__conversions() # in conversions_api.h correctly!!! cythonize(cythonize_eigency_conversions "../gtsam_eigency/conversions.pyx" "conversions" - "${OUTPUT_DIR}" "${EIGENCY_INCLUDE_DIR}" "" "") + "${OUTPUT_DIR}" "${EIGENCY_INCLUDE_DIR}" "" "" "") cythonize(cythonize_eigency_core "../gtsam_eigency/core.pyx" "core" - ${OUTPUT_DIR} "${EIGENCY_INCLUDE_DIR}" "" "") + ${OUTPUT_DIR} "${EIGENCY_INCLUDE_DIR}" "" "" "") add_dependencies(cythonize_eigency_core cythonize_eigency_conversions) add_custom_target(cythonize_eigency) add_dependencies(cythonize_eigency cythonize_eigency_conversions cythonize_eigency_core)