diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ba6a05c2..c72a6f295 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,17 +115,17 @@ link_directories(${Boost_LIBRARY_DIRS}) # Build CppUnitLite add_subdirectory(CppUnitLite) +# Build wrap +if (GTSAM_BUILD_WRAP) + add_subdirectory(wrap) +endif(GTSAM_BUILD_WRAP) + # Build GTSAM library add_subdirectory(gtsam) # Build Tests add_subdirectory(tests) -# Build wrap -if (GTSAM_BUILD_WRAP) - add_subdirectory(wrap) -endif(GTSAM_BUILD_WRAP) - # Build examples if (GTSAM_BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9f799d294..c9b3e4d8b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,3 +30,21 @@ foreach(example_src ${example_srcs} ) endforeach(example_src) +# Install matlab components +if (GTSAM_BUILD_WRAP) + if (GTSAM_INSTALL_MATLAB_TOOLBOX) + # Examples + if (GTSAM_INSTALL_MATLAB_EXAMPLES) + message(STATUS "Installing Matlab Toolbox Examples") + file(GLOB matlab_examples "${GTSAM_SOURCE_ROOT_DIR}/examples/matlab/*.m") + install(FILES ${matlab_examples} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/examples) + + message(STATUS "Installing Matlab Toolbox Examples (Data)") + # Data files: *.graph and *.txt + file(GLOB matlab_examples_data_graph "${GTSAM_SOURCE_ROOT_DIR}/examples/Data/*.graph") + file(GLOB matlab_examples_data_txt "${GTSAM_SOURCE_ROOT_DIR}/examples/Data/*.txt") + set(matlab_examples_data ${matlab_examples_data_graph} ${matlab_examples_data_txt}) + install(FILES ${matlab_examples_data} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/Data) + endif (GTSAM_INSTALL_MATLAB_EXAMPLES) + endif (GTSAM_INSTALL_MATLAB_TOOLBOX) +endif () \ No newline at end of file diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 80c57c15c..45d14263d 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -114,3 +114,24 @@ if (GTSAM_BUILD_SHARED_LIBRARY) install(TARGETS gtsam-shared LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) endif(GTSAM_BUILD_SHARED_LIBRARY) +# Create the matlab toolbox for the gtsam library +if (GTSAM_BUILD_WRAP) + # Set up codegen + include(GtsamMatlabWrap) + + # TODO: generate these includes programmatically + # Choose include flags depending on build process + if (GTSAM_BUILD_MEX_BIN) + set(MEX_INCLUDE_ROOT ${GTSAM_SOURCE_ROOT_DIR}) + set(MEX_LIB_ROOT ${CMAKE_BINARY_DIR}) + else() + set(MEX_INCLUDE_ROOT ${CMAKE_INSTALL_PREFIX}/include) + set(MEX_LIB_ROOT ${CMAKE_INSTALL_PREFIX}/lib) + endif() + + # Generate, build and install toolbox + set(mexFlags "-I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam -I${MEX_INCLUDE_ROOT}/gtsam/base -I${MEX_INCLUDE_ROOT}/gtsam/geometry -I${MEX_INCLUDE_ROOT}/gtsam/linear -I${MEX_INCLUDE_ROOT}/gtsam/discrete -I${MEX_INCLUDE_ROOT}/gtsam/inference -I${MEX_INCLUDE_ROOT}/gtsam/nonlinear -I${MEX_INCLUDE_ROOT}/gtsam/slam -L${MEX_LIB_ROOT}/gtsam -lgtsam") + + # Macro to handle details of setting up targets + wrap_library(gtsam "${mexFlags}" "../") +endif () diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 179ffc6e6..8c3b220c6 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -70,15 +70,6 @@ if (GTSAM_BUILD_WRAP) # Set up codegen include(GtsamMatlabWrap) - # Wrap codegen - #usage: wrap mexExecutable mexExtension interfacePath moduleName toolboxPath [mexFlags] - # mexExecutable : command to execute mex if on path, use 'mex' - # mexExtension : OS/CPU-dependent extension for MEX binaries - # interfacePath : *absolute* path to directory of module interface file - # moduleName : the name of the module, interface file must be called moduleName.h - # toolboxPath : the directory in which to generate the wrappers - # [mexFlags] : extra flags for the mex command - # TODO: generate these includes programmatically # Choose include flags depending on build process if (GTSAM_BUILD_MEX_BIN) @@ -89,48 +80,10 @@ if (GTSAM_BUILD_WRAP) set(MEX_LIB_ROOT ${CMAKE_INSTALL_PREFIX}/lib) endif() + # Generate, build and install toolbox set(mexFlags "-I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam_unstable -I${MEX_INCLUDE_ROOT}/gtsam_unstable/dynamics -I${MEX_INCLUDE_ROOT}/gtsam_unstable/discrete -L${MEX_LIB_ROOT}/gtsam_unstable -L${MEX_LIB_ROOT}/gtsam -lgtsam -lgtsam_unstable") - if(MSVC OR CYGWIN OR WINGW) - set(mexFlags "${mexFlags} LINKFLAGS='$LINKFLAGS /LIBPATH:${Boost_LIBRARY_DIRS}'") - endif() - set(toolbox_path ${CMAKE_BINARY_DIR}/wrap/gtsam_unstable) - set(moduleName gtsam_unstable) - - find_mexextension() - - # Code generation command - add_custom_target(wrap_gtsam_unstable ALL COMMAND - ${CMAKE_BINARY_DIR}/wrap/wrap - ${MEX_COMMAND} - ${GTSAM_MEX_BIN_EXTENSION} - ${CMAKE_CURRENT_SOURCE_DIR} - ${moduleName} - ${toolbox_path} - "${mexFlags}" - DEPENDS wrap) - - # Build command - if (GTSAM_BUILD_MEX_BIN) - # Actually compile the mex files when building the library - if (GTSAM_INSTALL_MEX_BIN) - add_custom_target(wrap_gtsam_unstable_build ALL - COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} - WORKING_DIRECTORY ${toolbox_path} - DEPENDS wrap_gtsam_unstable) - else() - add_custom_target(wrap_gtsam_unstable_build - COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} - WORKING_DIRECTORY ${toolbox_path} - DEPENDS wrap_gtsam_unstable) - endif() - endif () - - if (GTSAM_INSTALL_MATLAB_TOOLBOX) - # Primary toolbox files - message(STATUS "Installing Matlab Toolbox to ${GTSAM_TOOLBOX_INSTALL_PATH}") - install(DIRECTORY DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}) # make an empty folder - # exploit need for trailing slash to specify a full folder, rather than just its contents to copy - install(DIRECTORY ${toolbox_path} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}) - endif (GTSAM_INSTALL_MATLAB_TOOLBOX) + # Macro to handle details of setting up targets + wrap_library(gtsam_unstable "${mexFlags}" "./") + endif(GTSAM_BUILD_WRAP) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4d29dd557..ef9660c90 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,3 +40,15 @@ if (GTSAM_BUILD_TIMING) "${tests_local_libs}" "gtsam-static;CppUnitLite" "${tests_exclude}" # Pass in linking and exclusion lists ${is_test}) endif (GTSAM_BUILD_TIMING) + +# Install matlab components +if (GTSAM_BUILD_WRAP) + if (GTSAM_INSTALL_MATLAB_TOOLBOX) + # Tests + if (GTSAM_INSTALL_MATLAB_TESTS) + message(STATUS "Installing Matlab Toolbox Tests") + file(GLOB matlab_tests "${GTSAM_SOURCE_ROOT_DIR}/tests/matlab/*.m") + install(FILES ${matlab_tests} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/tests) + endif () + endif () +endif () \ No newline at end of file diff --git a/wrap/CMakeLists.txt b/wrap/CMakeLists.txt index 9c0501af6..4972e1ee2 100644 --- a/wrap/CMakeLists.txt +++ b/wrap/CMakeLists.txt @@ -22,96 +22,4 @@ if (GTSAM_BUILD_TESTS) gtsam_add_subdir_tests("wrap" "${wrap_local_libs}" "${wrap_local_libs}" "") endif(GTSAM_BUILD_TESTS) -# Wrap codegen -#usage: wrap mexExecutable mexExtension interfacePath moduleName toolboxPath [mexFlags] -# mexExecutable : command to execute mex if on path, use 'mex' -# mexExtension : OS/CPU-dependent extension for MEX binaries -# interfacePath : *absolute* path to directory of module interface file -# moduleName : the name of the module, interface file must be called moduleName.h -# toolboxPath : the directory in which to generate the wrappers -# [mexFlags] : extra flags for the mex command -# Choose include flags depending on build process -if (GTSAM_BUILD_MEX_BIN) - set(MEX_INCLUDE_ROOT ${GTSAM_SOURCE_ROOT_DIR}) - set(MEX_LIB_ROOT ${CMAKE_BINARY_DIR}) -else() - set(MEX_INCLUDE_ROOT ${CMAKE_INSTALL_PREFIX}/include) - set(MEX_LIB_ROOT ${CMAKE_INSTALL_PREFIX}/lib) -endif() - -set(mexFlags "-I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam -I${MEX_INCLUDE_ROOT}/gtsam/base -I${MEX_INCLUDE_ROOT}/gtsam/geometry -I${MEX_INCLUDE_ROOT}/gtsam/linear -I${MEX_INCLUDE_ROOT}/gtsam/discrete -I${MEX_INCLUDE_ROOT}/gtsam/inference -I${MEX_INCLUDE_ROOT}/gtsam/nonlinear -I${MEX_INCLUDE_ROOT}/gtsam/slam -L${MEX_LIB_ROOT}/gtsam -lgtsam") -if(MSVC OR CYGWIN OR WINGW) - set(mexFlags "${mexFlags} LINKFLAGS='$LINKFLAGS /LIBPATH:${Boost_LIBRARY_DIRS}'") -endif() -set(toolbox_path ${CMAKE_BINARY_DIR}/wrap/gtsam) -set(moduleName gtsam) - -include(GtsamMatlabWrap) -find_mexextension() - -# get binary path for wrap executable to allow for different build configurations (e.g., ROS) -if (NOT EXECUTABLE_OUTPUT_PATH) - set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) -endif() - -# Code generation command -get_property(WRAP_EXE TARGET wrap PROPERTY LOCATION) -add_custom_target(wrap_gtsam ALL COMMAND - ${WRAP_EXE} - ${MEX_COMMAND} - ${GTSAM_MEX_BIN_EXTENSION} - ${CMAKE_CURRENT_SOURCE_DIR}/../ - ${moduleName} - ${toolbox_path} - "${mexFlags}" - DEPENDS wrap) - -# Build command -if (GTSAM_BUILD_MEX_BIN) - # Actually compile the mex files when building the library - # TODO: pass correct make flags from parent process - message(STATUS "Building Matlab MEX binaries for toolbox with flags ${GTSAM_BUILD_MEX_BINARY_FLAGS}") - if (GTSAM_INSTALL_MEX_BIN) - add_custom_target(wrap_gtsam_build ALL - COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} - WORKING_DIRECTORY ${toolbox_path} - DEPENDS wrap_gtsam) - else() - add_custom_target(wrap_gtsam_build - COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} - WORKING_DIRECTORY ${toolbox_path} - DEPENDS wrap_gtsam) - endif() -endif () - -if (GTSAM_INSTALL_MATLAB_TOOLBOX) - # Primary toolbox files - # Note that we copy the entire contents of the folder blindly - this is because - # the generated files won't exist at configuration time - message(STATUS "Installing Matlab Toolbox to ${GTSAM_TOOLBOX_INSTALL_PATH}") - install(DIRECTORY DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}) # make an empty folder - # exploit need for trailing slash to specify a full folder, rather than just its contents to copy - install(DIRECTORY ${toolbox_path} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}) - - # Examples - if (GTSAM_INSTALL_MATLAB_EXAMPLES) - message(STATUS "Installing Matlab Toolbox Examples") - file(GLOB matlab_examples "${CMAKE_SOURCE_DIR}/examples/matlab/*.m") - install(FILES ${matlab_examples} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/examples) - - message(STATUS "Installing Matlab Toolbox Examples (Data)") - # Data files: *.graph and *.txt - file(GLOB matlab_examples_data_graph "${CMAKE_SOURCE_DIR}/examples/Data/*.graph") - file(GLOB matlab_examples_data_txt "${CMAKE_SOURCE_DIR}/examples/Data/*.txt") - set(matlab_examples_data ${matlab_examples_data_graph} ${matlab_examples_data_txt}) - install(FILES ${matlab_examples_data} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/Data) - endif (GTSAM_INSTALL_MATLAB_EXAMPLES) - - # Tests - if (GTSAM_INSTALL_MATLAB_TESTS) - message(STATUS "Installing Matlab Toolbox Tests") - file(GLOB matlab_tests "${CMAKE_SOURCE_DIR}/tests/matlab/*.m") - install(FILES ${matlab_tests} DESTINATION ${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam/tests) - endif (GTSAM_INSTALL_MATLAB_TESTS) -endif (GTSAM_INSTALL_MATLAB_TOOLBOX)