From 02ce40546f10962382e5716e50a0d23f84594082 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Tue, 5 Jun 2012 17:20:19 +0000 Subject: [PATCH] Changed names of cmake flags to be more intuitive, fixed include/library path issues for building the mex binaries --- CMakeLists.txt | 39 ++++++++++++++++------------------- examples/CMakeLists.txt | 2 +- gtsam_unstable/CMakeLists.txt | 21 +++++++++++++++---- wrap/CMakeLists.txt | 21 ++++++++++++------- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46e4a6f33..1ba6a05c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ set (GTSAM_VERSION_PATCH 0) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +# Record the root dir for gtsam - needed during external builds, e.g., ROS +set(GTSAM_SOURCE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +message(STATUS "GTSAM_SOURCE_ROOT_DIR: [${GTSAM_SOURCE_ROOT_DIR}]") + # Load build type flags and default to Debug mode include(GtsamBuildTypes) @@ -56,11 +60,13 @@ option(GTSAM_INSTALL_MATLAB_EXAMPLES "Enable/Disable installation of matlab option(GTSAM_INSTALL_MATLAB_TESTS "Enable/Disable installation of matlab tests" ON) option(GTSAM_INSTALL_WRAP "Enable/Disable installation of wrap utility" ON) +set(GTSAM_TOOLBOX_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/borg/toolbox CACHE DOCSTRING "Path to install matlab toolbox") + # TODO: Check for matlab mex binary before handling building of binaries # Flags for building/installing mex files -option(GTSAM_ENABLE_BUILD_MEX_BINARIES "Enable/Disable building of matlab mex files" OFF) -option(GTSAM_ENABLE_BUILD_MEX_BINARIES_ALL "Enable/Disable adding building of mex files to ALL target" OFF) +option(GTSAM_BUILD_MEX_BIN "Enable/Disable building of matlab mex files" OFF) +option(GTSAM_INSTALL_MEX_BIN "Enable/Disable installing matlab mex binaries" OFF) set(GTSAM_BUILD_MEX_BINARY_FLAGS "-j2" CACHE STRING "Flags for running make on toolbox MEX files") set(MEX_COMMAND "mex" CACHE STRING "Command to use for executing mex (if on path, 'mex' will work)") @@ -79,15 +85,10 @@ if (GTSAM_USE_QUATERNIONS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTSAM_DEFAULT_QUATERNIONS") endif(GTSAM_USE_QUATERNIONS) -# Avoid building non-installed exes and unit tests when installing -# FIXME: breaks generation and install of matlab toolbox -# FIXME: can't add install dependencies, so libraries never get built -#set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) - -# Alternative version to keep tests from building during make install -# Use the EXCLUDE_FROM_ALL property on test executables -option(GTSAM_ENABLE_INSTALL_TEST_FIX "Enable/Disable fix to remove dependency of tests on 'all' target" ON) -option(GTSAM_ENABLE_INSTALL_EXAMPLE_FIX "Enable/Disable fix to remove dependency of examples on 'all' target" OFF) +# Flags to determine whether tests and examples are build during 'make install' +# Note that these remove the targets from the 'all' +option(GTSAM_DISABLE_TESTS_ON_INSTALL "Disables building tests during install" ON) +option(GTSAM_DISABLE_EXAMPLES_ON_INSTALL "Disables buildint examples during install" OFF) # Pull in infrastructure if (GTSAM_BUILD_TESTS) @@ -100,7 +101,7 @@ endif() if(CYGWIN OR MSVC OR WIN32) set(Boost_USE_STATIC_LIBS 1) endif() -find_package(Boost 1.40 COMPONENTS serialization system filesystem thread REQUIRED) +find_package(Boost 1.42 COMPONENTS serialization system filesystem thread REQUIRED) # General build settings include_directories( @@ -155,10 +156,6 @@ set(CPACK_SOURCE_IGNORE_FILES "/build;/\\\\.;/makedoc.sh$;/gtsam_unstable/") set(CPACK_SOURCE_PACKAGE_FILE_NAME "gtsam-${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}.${GTSAM_VERSION_PATCH}") #set(CPACK_SOURCE_PACKAGE_FILE_NAME "gtsam-aspn${GTSAM_VERSION_PATCH}") # Used for creating ASPN tarballs -# Record the root dir for gtsam - needed during external builds, e.g., ROS -set(GTSAM_SOURCE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -message(STATUS "GTSAM_SOURCE_ROOT_DIR: [${GTSAM_SOURCE_ROOT_DIR}]") - # print configuration variables message(STATUS "===============================================================") message(STATUS "================ Configuration Options ======================") @@ -171,10 +168,10 @@ print_config_flag(${GTSAM_BUILD_SHARED_LIBRARY} "Build shared GTSAM Libra print_config_flag(${GTSAM_BUILD_STATIC_LIBRARY} "Build static GTSAM Library ") print_config_flag(${GTSAM_BUILD_CONVENIENCE_LIBRARIES} "Build Convenience Libraries ") if(GTSAM_UNSTABLE_AVAILABLE) - print_config_flag(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ") + print_config_flag(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ") endif() -print_config_flag(${GTSAM_ENABLE_INSTALL_TEST_FIX} "Tests excluded from all target ") -print_config_flag(${GTSAM_ENABLE_INSTALL_EXAMPLE_FIX} "Examples excluded from all target ") +print_config_flag(${GTSAM_DISABLE_TESTS_ON_INSTALL} "Tests excluded from all/install target ") +print_config_flag(${GTSAM_DISABLE_EXAMPLES_ON_INSTALL} "Examples excluded from all/install target ") string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper) message(STATUS " Build type : ${CMAKE_BUILD_TYPE}") message(STATUS " C compilation flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${cmake_build_type_toupper}}") @@ -192,8 +189,8 @@ print_config_flag(${GTSAM_INSTALL_MATLAB_TOOLBOX} "Install matlab toolbox print_config_flag(${GTSAM_INSTALL_MATLAB_EXAMPLES} "Install matlab examples ") print_config_flag(${GTSAM_INSTALL_MATLAB_TESTS} "Install matlab tests ") print_config_flag(${GTSAM_INSTALL_WRAP} "Install wrap utility ") -print_config_flag(${GTSAM_ENABLE_BUILD_MEX_BINARIES} "Build MEX binaries ") -print_config_flag(${GTSAM_ENABLE_BUILD_MEX_BINARIES_ALL} "Build MEX binaries on ALL target ") +print_config_flag(${GTSAM_BUILD_MEX_BIN} "Build MEX binaries ") +print_config_flag(${GTSAM_INSTALL_MEX_BIN} "Install MEX binaries ") message(STATUS "===============================================================") # Include CPack *after* all flags diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a54c8366c..9f799d294 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,7 +14,7 @@ foreach(example_src ${example_srcs} ) add_executable(${example_bin} ${example_src}) # Disable building during make all/install - if (GTSAM_ENABLE_INSTALL_EXAMPLE_FIX) + if (GTSAM_DISABLE_EXAMPLES_ON_INSTALL) set_target_properties(${example_bin} PROPERTIES EXCLUDE_FROM_ALL ON) endif() diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 54e95a599..179ffc6e6 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -80,7 +80,20 @@ if (GTSAM_BUILD_WRAP) # [mexFlags] : extra flags for the mex command # TODO: generate these includes programmatically - set(mexFlags "-I${Boost_INCLUDE_DIR} -I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/gtsam_unstable -I${CMAKE_INSTALL_PREFIX}/include/gtsam_unstable/dynamics -I${CMAKE_INSTALL_PREFIX}/include/gtsam_unstable/discrete -L${CMAKE_INSTALL_PREFIX}/lib -lgtsam -lgtsam_unstable") + # 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_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) @@ -98,9 +111,9 @@ if (GTSAM_BUILD_WRAP) DEPENDS wrap) # Build command - if (GTSAM_ENABLE_BUILD_MEX_BINARIES) + if (GTSAM_BUILD_MEX_BIN) # Actually compile the mex files when building the library - if (GTSAM_ENABLE_BUILD_MEX_BINARIES_ALL) + if (GTSAM_INSTALL_MEX_BIN) add_custom_target(wrap_gtsam_unstable_build ALL COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} WORKING_DIRECTORY ${toolbox_path} @@ -111,7 +124,7 @@ if (GTSAM_BUILD_WRAP) WORKING_DIRECTORY ${toolbox_path} DEPENDS wrap_gtsam_unstable) endif() - endif (GTSAM_ENABLE_BUILD_MEX_BINARIES) + endif () if (GTSAM_INSTALL_MATLAB_TOOLBOX) # Primary toolbox files diff --git a/wrap/CMakeLists.txt b/wrap/CMakeLists.txt index 8f44e24cf..9c0501af6 100644 --- a/wrap/CMakeLists.txt +++ b/wrap/CMakeLists.txt @@ -16,7 +16,7 @@ endif(GTSAM_INSTALL_WRAP) install(FILES matlab.h DESTINATION include/wrap) # Build tests -if (GTSAM_BUILD_TESTS) +if (GTSAM_BUILD_TESTS) add_definitions(-DTOPSRCDIR="${CMAKE_SOURCE_DIR}") set(wrap_local_libs wrap_lib) gtsam_add_subdir_tests("wrap" "${wrap_local_libs}" "${wrap_local_libs}" "") @@ -31,7 +31,16 @@ endif(GTSAM_BUILD_TESTS) # toolboxPath : the directory in which to generate the wrappers # [mexFlags] : extra flags for the mex command -set(mexFlags "-I${Boost_INCLUDE_DIR} -I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/gtsam -I${CMAKE_INSTALL_PREFIX}/include/gtsam/base -I${CMAKE_INSTALL_PREFIX}/include/gtsam/geometry -I${CMAKE_INSTALL_PREFIX}/include/gtsam/linear -I${CMAKE_INSTALL_PREFIX}/include/gtsam/discrete -I${CMAKE_INSTALL_PREFIX}/include/gtsam/inference -I${CMAKE_INSTALL_PREFIX}/include/gtsam/nonlinear -I${CMAKE_INSTALL_PREFIX}/include/gtsam/slam -L${CMAKE_INSTALL_PREFIX}/lib -lgtsam") +# 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() @@ -59,11 +68,11 @@ add_custom_target(wrap_gtsam ALL COMMAND DEPENDS wrap) # Build command -if (GTSAM_ENABLE_BUILD_MEX_BINARIES) +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_ENABLE_BUILD_MEX_BINARIES_ALL) + if (GTSAM_INSTALL_MEX_BIN) add_custom_target(wrap_gtsam_build ALL COMMAND make ${GTSAM_BUILD_MEX_BINARY_FLAGS} WORKING_DIRECTORY ${toolbox_path} @@ -74,9 +83,7 @@ if (GTSAM_ENABLE_BUILD_MEX_BINARIES) WORKING_DIRECTORY ${toolbox_path} DEPENDS wrap_gtsam) endif() -endif (GTSAM_ENABLE_BUILD_MEX_BINARIES) - -set(GTSAM_TOOLBOX_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/borg/toolbox CACHE DOCSTRING "Path to install matlab toolbox") +endif () if (GTSAM_INSTALL_MATLAB_TOOLBOX) # Primary toolbox files