From 265e8773bac55acecb388cbc668d41d52f62b8bb Mon Sep 17 00:00:00 2001 From: cbeall Date: Fri, 7 Apr 2017 18:43:08 -0700 Subject: [PATCH] Fix cython build when GTSAM_BUILD_TYPE_POSTFIXES is enabled. And fix cython build when gtsam is built as part of a larger project, i.e. it is not the top-level project. --- cmake/GtsamCythonWrap.cmake | 8 ++++++++ cython/CMakeLists.txt | 4 ++-- cython/gtsam/setup.py.in | 8 ++++---- cython/gtsam_unstable/setup.py.in | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cmake/GtsamCythonWrap.cmake b/cmake/GtsamCythonWrap.cmake index d785b4ef8..a1ebd3ef2 100644 --- a/cmake/GtsamCythonWrap.cmake +++ b/cmake/GtsamCythonWrap.cmake @@ -48,6 +48,14 @@ function(wrap_library_cython interface_header generated_files_path extra_imports message(STATUS "Building wrap module ${module_name}") + # Get build type postfix - gtsam_library_postfix is used in setup.py.in + # to link cythonized library to appropriate version of gtsam library + set(gtsam_library_postfix "") + if(GTSAM_BUILD_TYPE_POSTFIXES) + string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type_upper) + set(gtsam_library_postfix ${CMAKE_${build_type_upper}_POSTFIX}) + endif() + # Set up generation of module source file file(MAKE_DIRECTORY "${generated_files_path}") configure_file(${setup_py_in_path}/setup.py.in ${generated_files_path}/setup.py) diff --git a/cython/CMakeLists.txt b/cython/CMakeLists.txt index 209c85f54..e04f29608 100644 --- a/cython/CMakeLists.txt +++ b/cython/CMakeLists.txt @@ -1,7 +1,7 @@ # Install cython components include(GtsamCythonWrap) # install scripts and tests -install_cython_scripts("${CMAKE_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py") +install_cython_scripts("${PROJECT_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py") # generate __init__.py into build folder (configured with or without gtsam_unstable import line) @@ -9,7 +9,7 @@ install_cython_scripts("${CMAKE_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTAL if(GTSAM_BUILD_UNSTABLE) set(GTSAM_UNSTABLE_IMPORT "from gtsam_unstable import *") endif() -configure_file(${CMAKE_SOURCE_DIR}/cython/gtsam/__init__.py.in ${PROJECT_BINARY_DIR}/cython/gtsam/__init__.py) +configure_file(${PROJECT_SOURCE_DIR}/cython/gtsam/__init__.py.in ${PROJECT_BINARY_DIR}/cython/gtsam/__init__.py) # Install the custom-generated __init__.py install_cython_files("${PROJECT_BINARY_DIR}/cython/gtsam/__init__.py" "${GTSAM_CYTHON_INSTALL_PATH}/gtsam") diff --git a/cython/gtsam/setup.py.in b/cython/gtsam/setup.py.in index 1e97567c9..1ae067690 100644 --- a/cython/gtsam/setup.py.in +++ b/cython/gtsam/setup.py.in @@ -12,12 +12,12 @@ setup( ext_modules = cythonize(Extension( "gtsam", sources=["gtsam.pyx"], - include_dirs = ["${CMAKE_SOURCE_DIR}", "${CMAKE_BINARY_DIR}", - "${CMAKE_SOURCE_DIR}/gtsam/3rdparty/Eigen", + include_dirs = ["${PROJECT_SOURCE_DIR}", "${CMAKE_BINARY_DIR}", + "${PROJECT_SOURCE_DIR}/gtsam/3rdparty/Eigen", "${Boost_INCLUDE_DIR}" ] + eigency.get_includes(include_eigen=False), - libraries = ['gtsam'], - library_dirs = ["${CMAKE_BINARY_DIR}/gtsam"], + libraries = ['gtsam${gtsam_library_postfix}'], + library_dirs = ["${CMAKE_CURRENT_BINARY_DIR}"], language="c++", extra_compile_args="${CMAKE_CXX_FLAGS}".split(), extra_link_args="${CMAKE_SHARED_LINKER_FLAGS}".split())) diff --git a/cython/gtsam_unstable/setup.py.in b/cython/gtsam_unstable/setup.py.in index bd3202c8d..d7057cec7 100644 --- a/cython/gtsam_unstable/setup.py.in +++ b/cython/gtsam_unstable/setup.py.in @@ -19,7 +19,7 @@ setup( "${CMAKE_SOURCE_DIR}/gtsam/3rdparty/Eigen", "${Boost_INCLUDE_DIR}" ] + eigency.get_includes(include_eigen=False), - libraries=['gtsam', 'gtsam_unstable'], + libraries=['gtsam${gtsam_library_postfix}', 'gtsam_unstable${gtsam_library_postfix}'], library_dirs = ["${CMAKE_BINARY_DIR}/gtsam", "${CMAKE_BINARY_DIR}/gtsam_unstable"], language="c++",