tabs -> spaces

release/4.3a0
Duy-Nguyen Ta 2017-05-16 17:01:45 -04:00
parent b53a901922
commit 673806553b
1 changed files with 106 additions and 106 deletions

View File

@ -21,99 +21,99 @@ endif()
# interface_header: The relative path to the wrapper interface definition file. # interface_header: The relative path to the wrapper interface definition file.
# extra_imports: extra header to import in the Cython pxd file. # extra_imports: extra header to import in the Cython pxd file.
# For example, to use Cython gtsam.pxd in your own module, # For example, to use Cython gtsam.pxd in your own module,
# use "from gtsam cimport *" # use "from gtsam cimport *"
# setup_py_in_path: Path to the setup.py.in config file, which will be converted # setup_py_in_path: Path to the setup.py.in config file, which will be converted
# to setup.py file by cmake and used to compile the Cython module # to setup.py file by cmake and used to compile the Cython module
# by invoking "python setup.py build_ext --inplace" # by invoking "python setup.py build_ext --inplace"
# install_path: destination to install the library # install_path: destination to install the library
function(wrap_and_install_library_cython interface_header extra_imports setup_py_in_path install_path) function(wrap_and_install_library_cython interface_header extra_imports setup_py_in_path install_path)
# 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 "${PROJECT_BINARY_DIR}/cython/${module_name}")
wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${setup_py_in_path}") wrap_library_cython("${interface_header}" "${generated_files_path}" "${extra_imports}" "${setup_py_in_path}")
install_cython_wrapped_library("${interface_header}" "${generated_files_path}" "${install_path}") install_cython_wrapped_library("${interface_header}" "${generated_files_path}" "${install_path}")
endfunction() endfunction()
# Internal function that wraps a library and compiles the wrapper # Internal function that wraps a library and compiles the wrapper
function(wrap_library_cython interface_header generated_files_path extra_imports setup_py_in_path) function(wrap_library_cython interface_header generated_files_path extra_imports setup_py_in_path)
# Wrap codegen interface # Wrap codegen interface
# Extract module path and name from interface header file name # Extract module path and name from interface header file name
# wrap requires interfacePath to be *absolute* # wrap requires interfacePath to be *absolute*
get_filename_component(interface_header "${interface_header}" ABSOLUTE) get_filename_component(interface_header "${interface_header}" ABSOLUTE)
get_filename_component(module_path "${interface_header}" PATH) get_filename_component(module_path "${interface_header}" PATH)
get_filename_component(module_name "${interface_header}" NAME_WE) get_filename_component(module_name "${interface_header}" NAME_WE)
set(generated_cpp_file "${generated_files_path}/${module_name}.cpp") set(generated_cpp_file "${generated_files_path}/${module_name}.cpp")
message(STATUS "Building wrap module ${module_name}") message(STATUS "Building wrap module ${module_name}")
# Get build type postfix - gtsam_library_postfix is used in setup.py.in # Get build type postfix - gtsam_library_postfix is used in setup.py.in
# to link cythonized library to appropriate version of gtsam library # to link cythonized library to appropriate version of gtsam library
set(gtsam_library_postfix "") set(gtsam_library_postfix "")
if(GTSAM_BUILD_TYPE_POSTFIXES) if(GTSAM_BUILD_TYPE_POSTFIXES)
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type_upper) string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type_upper)
set(gtsam_library_postfix ${CMAKE_${build_type_upper}_POSTFIX}) set(gtsam_library_postfix ${CMAKE_${build_type_upper}_POSTFIX})
endif() endif()
# Set up generation of module source file # Set up generation of module source file
file(MAKE_DIRECTORY "${generated_files_path}") file(MAKE_DIRECTORY "${generated_files_path}")
configure_file(${setup_py_in_path}/setup.py.in ${generated_files_path}/setup.py) configure_file(${setup_py_in_path}/setup.py.in ${generated_files_path}/setup.py)
add_custom_command( add_custom_command(
OUTPUT ${generated_cpp_file} OUTPUT ${generated_cpp_file}
DEPENDS ${interface_header} wrap DEPENDS ${interface_header} wrap
COMMAND COMMAND
wrap --cython wrap --cython
${module_path} ${module_path}
${module_name} ${module_name}
${generated_files_path} ${generated_files_path}
"${extra_imports}" "${extra_imports}"
&& python setup.py build_ext --inplace && python setup.py build_ext --inplace
VERBATIM VERBATIM
WORKING_DIRECTORY ${generated_files_path}) WORKING_DIRECTORY ${generated_files_path})
# Set up building of mex module # Set up building of mex module
add_custom_target(${module_name}_cython_wrapper ALL DEPENDS ${generated_cpp_file} ${interface_header}) add_custom_target(${module_name}_cython_wrapper ALL DEPENDS ${generated_cpp_file} ${interface_header})
add_custom_target(wrap_${module_name}_cython_distclean add_custom_target(wrap_${module_name}_cython_distclean
COMMAND cmake -E remove_directory ${generated_files_path}) COMMAND cmake -E remove_directory ${generated_files_path})
endfunction() endfunction()
# Internal function that installs a wrap toolbox # Internal function that installs a wrap toolbox
function(install_cython_wrapped_library interface_header generated_files_path install_path) function(install_cython_wrapped_library interface_header generated_files_path install_path)
get_filename_component(module_name "${interface_header}" NAME_WE) get_filename_component(module_name "${interface_header}" NAME_WE)
# NOTE: only installs .pxd and .pyx and binary files (not .cpp) - the trailing slash on the directory name # NOTE: only installs .pxd and .pyx and binary files (not .cpp) - the trailing slash on the directory name
# here prevents creating the top-level module name directory in the destination. # here prevents creating the top-level module name directory in the destination.
message(STATUS "Installing Cython Toolbox to ${install_path}") #${GTSAM_CYTHON_INSTALL_PATH}") message(STATUS "Installing Cython Toolbox to ${install_path}") #${GTSAM_CYTHON_INSTALL_PATH}")
if(GTSAM_BUILD_TYPE_POSTFIXES) if(GTSAM_BUILD_TYPE_POSTFIXES)
foreach(build_type ${CMAKE_CONFIGURATION_TYPES}) foreach(build_type ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${build_type}" build_type_upper) string(TOUPPER "${build_type}" build_type_upper)
if(${build_type_upper} STREQUAL "RELEASE") if(${build_type_upper} STREQUAL "RELEASE")
set(build_type_tag "") # Don't create release mode tag on installed directory set(build_type_tag "") # Don't create release mode tag on installed directory
else() else()
set(build_type_tag "${build_type}") set(build_type_tag "${build_type}")
endif() endif()
# Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one # Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one
get_filename_component(location "${install_path}" PATH) get_filename_component(location "${install_path}" PATH)
get_filename_component(name "${install_path}" NAME) get_filename_component(name "${install_path}" NAME)
install(DIRECTORY "${generated_files_path}/" DESTINATION "${location}/${name}${build_type_tag}" install(DIRECTORY "${generated_files_path}/" DESTINATION "${location}/${name}${build_type_tag}"
CONFIGURATIONS "${build_type}" CONFIGURATIONS "${build_type}"
PATTERN "build" EXCLUDE PATTERN "build" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE PATTERN "CMakeFiles" EXCLUDE
PATTERN "Makefile" EXCLUDE PATTERN "Makefile" EXCLUDE
PATTERN "*.cmake" EXCLUDE PATTERN "*.cmake" EXCLUDE
PATTERN "*.cpp" EXCLUDE PATTERN "*.cpp" EXCLUDE
PATTERN "*.py" EXCLUDE) PATTERN "*.py" EXCLUDE)
endforeach() endforeach()
else() else()
install(DIRECTORY "${generated_files_path}/" DESTINATION ${install_path} install(DIRECTORY "${generated_files_path}/" DESTINATION ${install_path}
PATTERN "build" EXCLUDE PATTERN "build" EXCLUDE
PATTERN "CMakeFiles" EXCLUDE PATTERN "CMakeFiles" EXCLUDE
PATTERN "Makefile" EXCLUDE PATTERN "Makefile" EXCLUDE
PATTERN "*.cmake" EXCLUDE PATTERN "*.cmake" EXCLUDE
PATTERN "*.cpp" EXCLUDE PATTERN "*.cpp" EXCLUDE
PATTERN "*.py" EXCLUDE) PATTERN "*.py" EXCLUDE)
endif() endif()
endfunction() endfunction()
# Helper function to install Cython scripts and handle multiple build types where the scripts # Helper function to install Cython scripts and handle multiple build types where the scripts
@ -127,29 +127,29 @@ endfunction()
# dest_directory: The destination directory to install to. # dest_directory: The destination directory to install to.
# patterns: list of file patterns to install # patterns: list of file patterns to install
function(install_cython_scripts source_directory dest_directory patterns) function(install_cython_scripts source_directory dest_directory patterns)
set(patterns_args "") set(patterns_args "")
set(exclude_patterns "") set(exclude_patterns "")
foreach(pattern ${patterns}) foreach(pattern ${patterns})
list(APPEND patterns_args PATTERN "${pattern}") list(APPEND patterns_args PATTERN "${pattern}")
endforeach() endforeach()
if(GTSAM_BUILD_TYPE_POSTFIXES) if(GTSAM_BUILD_TYPE_POSTFIXES)
foreach(build_type ${CMAKE_CONFIGURATION_TYPES}) foreach(build_type ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${build_type}" build_type_upper) string(TOUPPER "${build_type}" build_type_upper)
if(${build_type_upper} STREQUAL "RELEASE") if(${build_type_upper} STREQUAL "RELEASE")
set(build_type_tag "") # Don't create release mode tag on installed directory set(build_type_tag "") # Don't create release mode tag on installed directory
else() else()
set(build_type_tag "${build_type}") set(build_type_tag "${build_type}")
endif() endif()
# Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one # 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(location "${dest_directory}" PATH)
get_filename_component(name "${dest_directory}" NAME) get_filename_component(name "${dest_directory}" NAME)
install(DIRECTORY "${source_directory}" DESTINATION "${location}/${name}${build_type_tag}" CONFIGURATIONS "${build_type}" install(DIRECTORY "${source_directory}" DESTINATION "${location}/${name}${build_type_tag}" CONFIGURATIONS "${build_type}"
FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE) FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE)
endforeach() endforeach()
else() else()
install(DIRECTORY "${source_directory}" DESTINATION "${dest_directory}" FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE) install(DIRECTORY "${source_directory}" DESTINATION "${dest_directory}" FILES_MATCHING ${patterns_args} PATTERN "${exclude_patterns}" EXCLUDE)
endif() endif()
endfunction() endfunction()
@ -161,22 +161,22 @@ endfunction()
# dest_directory: The destination directory to install to. # dest_directory: The destination directory to install to.
function(install_cython_files source_files dest_directory) function(install_cython_files source_files dest_directory)
if(GTSAM_BUILD_TYPE_POSTFIXES) if(GTSAM_BUILD_TYPE_POSTFIXES)
foreach(build_type ${CMAKE_CONFIGURATION_TYPES}) foreach(build_type ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${build_type}" build_type_upper) string(TOUPPER "${build_type}" build_type_upper)
if(${build_type_upper} STREQUAL "RELEASE") if(${build_type_upper} STREQUAL "RELEASE")
set(build_type_tag "") # Don't create release mode tag on installed directory set(build_type_tag "") # Don't create release mode tag on installed directory
else() else()
set(build_type_tag "${build_type}") set(build_type_tag "${build_type}")
endif() endif()
# Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one # 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(location "${dest_directory}" PATH)
get_filename_component(name "${dest_directory}" NAME) get_filename_component(name "${dest_directory}" NAME)
install(FILES "${source_files}" DESTINATION "${location}/${name}${build_type_tag}" CONFIGURATIONS "${build_type}") install(FILES "${source_files}" DESTINATION "${location}/${name}${build_type_tag}" CONFIGURATIONS "${build_type}")
endforeach() endforeach()
else() else()
install(FILES "${source_files}" DESTINATION "${dest_directory}") install(FILES "${source_files}" DESTINATION "${dest_directory}")
endif() endif()
endfunction() endfunction()