Configure __init__.py based on setting of GTSAM_BUILD_UNSTABLE.

release/4.3a0
chrisbeall 2017-04-07 00:29:27 -07:00
parent 6824ee0487
commit c42cebc037
5 changed files with 40 additions and 5 deletions

View File

@ -145,3 +145,30 @@ function(install_cython_scripts source_directory dest_directory patterns)
endfunction()
# Helper function to install specific files and handle multiple build types where the scripts
# should be installed to all build type toolboxes
#
# Arguments:
# source_files: The source files to be installed.
# dest_directory: The destination directory to install to.
function(install_cython_files source_files dest_directory)
if(GTSAM_BUILD_TYPE_POSTFIXES)
foreach(build_type ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${build_type}" build_type_upper)
if(${build_type_upper} STREQUAL "RELEASE")
set(build_type_tag "") # Don't create release mode tag on installed directory
else()
set(build_type_tag "${build_type}")
endif()
# Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one
get_filename_component(location "${dest_directory}" PATH)
get_filename_component(name "${dest_directory}" NAME)
install(FILES "${source_files}" DESTINATION "${location}/${name}${build_type_tag}")
endforeach()
else()
install(FILES "${source_files}" DESTINATION "${dest_directory}")
endif()
endfunction()

View File

@ -2,3 +2,14 @@
include(GtsamCythonWrap)
# install scripts and tests
install_cython_scripts("${CMAKE_SOURCE_DIR}/cython/gtsam" "${GTSAM_CYTHON_INSTALL_PATH}" "*.py")
# generate __init__.py into build folder (configured with or without gtsam_unstable import line)
# This also makes the build/cython/gtsam folder a python package, so gtsam can be found while wrapping gtsam_unstable
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)
# Install the custom-generated __init__.py
install_cython_files("${PROJECT_BINARY_DIR}/cython/gtsam/__init__.py" "${GTSAM_CYTHON_INSTALL_PATH}/gtsam")

View File

@ -1,2 +0,0 @@
from gtsam import *
from gtsam_unstable import *

View File

@ -0,0 +1,2 @@
from gtsam import *
${GTSAM_UNSTABLE_IMPORT}

View File

@ -131,9 +131,6 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX)
"${GTSAM_CYTHON_INSTALL_PATH}/gtsam" # install path
)
add_dependencies(gtsam_unstable_cython_wrapper gtsam_cython_wrapper)
# making the build/cython/gtsam folder a python package, so gtsam can be found while wrapping gtsam_unstable
add_custom_target(copy_gtsam_init COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/cython/gtsam/__init__.py" "${CMAKE_BINARY_DIR}/cython/gtsam")
add_dependencies(gtsam_unstable_cython_wrapper copy_gtsam_init)
endif ()
# Build examples