From 6b1c96869f89a12be4ef0f4acb81b5c1af60ace1 Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Wed, 31 May 2017 08:45:54 +0800 Subject: [PATCH] specify libs to link with cython module for flexibility --- cmake/GtsamCythonWrap.cmake | 9 +++++---- cython/CMakeLists.txt | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmake/GtsamCythonWrap.cmake b/cmake/GtsamCythonWrap.cmake index 92f4981a7..024337f8a 100644 --- a/cmake/GtsamCythonWrap.cmake +++ b/cmake/GtsamCythonWrap.cmake @@ -23,18 +23,19 @@ endif() # For example, to use Cython gtsam.pxd in your own module, # use "from gtsam cimport *" # install_path: destination to install the library +# libs: libraries to link with # dependencies: Dependencies which need to be built before the wrapper -function(wrap_and_install_library_cython interface_header extra_imports install_path dependencies) +function(wrap_and_install_library_cython interface_header extra_imports install_path libs dependencies) # Paths for generated files get_filename_component(module_name "${interface_header}" NAME_WE) set(generated_files_path "${PROJECT_BINARY_DIR}/cython/${module_name}") - wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${dependencies}") + wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${libs}" "${dependencies}") install_cython_wrapped_library("${interface_header}" "${generated_files_path}" "${install_path}") endfunction() # Internal function that wraps a library and compiles the wrapper -function(wrap_library_cython interface_header generated_files_path extra_imports dependencies) +function(wrap_library_cython interface_header generated_files_path extra_imports libs dependencies) # Wrap codegen interface # Extract module path and name from interface header file name # wrap requires interfacePath to be *absolute* @@ -73,7 +74,7 @@ function(wrap_library_cython interface_header generated_files_path extra_imports add_library(${module_name}_cython MODULE ${generated_cpp_file}) set_target_properties(${module_name}_cython PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" OUTPUT_NAME ${module_name} PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${generated_files_path}) - target_link_libraries(${module_name}_cython ${module_name}) + target_link_libraries(${module_name}_cython ${libs}) add_dependencies(${module_name}_cython ${module_name}_cython_wrapper) # distclean diff --git a/cython/CMakeLists.txt b/cython/CMakeLists.txt index ea00e18d5..14073be82 100644 --- a/cython/CMakeLists.txt +++ b/cython/CMakeLists.txt @@ -6,6 +6,7 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX) wrap_and_install_library_cython("../gtsam.h" # interface_header "" # extra imports "${GTSAM_CYTHON_INSTALL_PATH}/gtsam" # install path + gtsam # library to link with gtsam # dependencies which need to be built before the wrapper ) @@ -15,6 +16,7 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX) wrap_and_install_library_cython("../gtsam_unstable/gtsam_unstable.h" # interface_header "from gtsam.gtsam cimport *" # extra imports "${GTSAM_CYTHON_INSTALL_PATH}/gtsam" # install path + gtsam_unstable # library to link with gtsam_unstable # dependencies which need to be built before the wrapper ) add_dependencies(gtsam_unstable_cython_wrapper gtsam_cython_wrapper)