167 lines
6.1 KiB
CMake
167 lines
6.1 KiB
CMake
# We split the library in to separate subfolders, each containing
|
|
# tests, timing, and an optional convenience library.
|
|
# The following variable is the master list of subdirs to add
|
|
set (gtsam_subdirs
|
|
base
|
|
geometry
|
|
inference
|
|
symbolic
|
|
#discrete
|
|
linear
|
|
nonlinear
|
|
slam
|
|
navigation
|
|
)
|
|
|
|
set(gtsam_srcs)
|
|
|
|
# Build 3rdparty separately
|
|
message(STATUS "Building 3rdparty")
|
|
add_subdirectory(3rdparty)
|
|
|
|
# build convenience library
|
|
set (3rdparty_srcs
|
|
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/CCOLAMD/Source/ccolamd.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/CCOLAMD/Source/ccolamd_global.c
|
|
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/UFconfig/UFconfig.c)
|
|
gtsam_assign_source_folders("${3rdparty_srcs}") # Create MSVC structure
|
|
|
|
# To exclude a source from the library build (in any subfolder)
|
|
# Add the full name to this list, as in the following example
|
|
# Sources to remove from builds
|
|
set (excluded_sources #"")
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/slam/serialization.cpp"
|
|
)
|
|
|
|
set (excluded_headers #"")
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/slam/serialization.h"
|
|
)
|
|
|
|
if(GTSAM_USE_QUATERNIONS)
|
|
set(excluded_sources ${excluded_sources} "${CMAKE_CURRENT_SOURCE_DIR}/geometry/Rot3M.cpp")
|
|
else()
|
|
set(excluded_sources ${excluded_sources} "${CMAKE_CURRENT_SOURCE_DIR}/geometry/Rot3Q.cpp")
|
|
endif()
|
|
|
|
# Common headers
|
|
file(GLOB gtsam_core_headers "*.h")
|
|
install(FILES ${gtsam_core_headers} DESTINATION include/gtsam)
|
|
|
|
# assemble core libaries
|
|
foreach(subdir ${gtsam_subdirs})
|
|
# Build convenience libraries
|
|
file(GLOB subdir_cpp_srcs "${subdir}/*.cpp")
|
|
file(GLOB subdir_headers "${subdir}/*.h")
|
|
list(REMOVE_ITEM subdir_cpp_srcs ${excluded_sources})
|
|
list(REMOVE_ITEM subdir_headers ${excluded_headers})
|
|
set(subdir_srcs ${subdir_cpp_srcs} ${subdir_headers}) # Include header files so they show up in Visual Studio
|
|
gtsam_assign_source_folders("${subdir_srcs}") # Create MSVC structure
|
|
set(${subdir}_srcs ${subdir_srcs})
|
|
|
|
# Build local library and tests
|
|
message(STATUS "Building ${subdir}")
|
|
add_subdirectory(${subdir})
|
|
endforeach(subdir)
|
|
|
|
# To add additional sources to gtsam when building the full library (static or shared)
|
|
# Add the subfolder with _srcs appended to the end to this list
|
|
set(gtsam_srcs
|
|
${3rdparty_srcs}
|
|
${base_srcs}
|
|
${geometry_srcs}
|
|
${inference_srcs}
|
|
${symbolic_srcs}
|
|
#${discrete_srcs}
|
|
${linear_srcs}
|
|
${nonlinear_srcs}
|
|
${slam_srcs}
|
|
${navigation_srcs}
|
|
${gtsam_core_headers}
|
|
)
|
|
|
|
# Generate and install config and dllexport files
|
|
configure_file(config.h.in config.h)
|
|
set(library_name GTSAM) # For substitution in dllexport.h.in
|
|
configure_file("${PROJECT_SOURCE_DIR}/cmake/dllexport.h.in" "dllexport.h")
|
|
list(APPEND gtsam_srcs "${CMAKE_BINARY_DIR}/gtsam/config.h" "${CMAKE_BINARY_DIR}/gtsam/dllexport.h")
|
|
install(FILES "${CMAKE_BINARY_DIR}/gtsam/config.h" "${CMAKE_BINARY_DIR}/gtsam/dllexport.h" DESTINATION include/gtsam)
|
|
|
|
# Versions
|
|
set(gtsam_version ${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}.${GTSAM_VERSION_PATCH})
|
|
set(gtsam_soversion ${GTSAM_VERSION_MAJOR})
|
|
message(STATUS "GTSAM Version: ${gtsam_version}")
|
|
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
|
|
|
|
# build shared and static versions of the library
|
|
if (GTSAM_BUILD_STATIC_LIBRARY)
|
|
message(STATUS "Building GTSAM - static")
|
|
add_library(gtsam-static STATIC ${gtsam_srcs})
|
|
target_link_libraries(gtsam-static ${GTSAM_BOOST_LIBRARIES} ${GTSAM_TBB_LIBRARIES})
|
|
set_target_properties(gtsam-static PROPERTIES
|
|
OUTPUT_NAME gtsam
|
|
CLEAN_DIRECT_OUTPUT 1
|
|
VERSION ${gtsam_version}
|
|
SOVERSION ${gtsam_soversion})
|
|
if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with shared library
|
|
set_target_properties(gtsam-static PROPERTIES
|
|
PREFIX "lib"
|
|
COMPILE_DEFINITIONS GTSAM_IMPORT_STATIC)
|
|
endif()
|
|
install(TARGETS gtsam-static EXPORT GTSAM-exports ARCHIVE DESTINATION lib)
|
|
list(APPEND GTSAM_EXPORTED_TARGETS gtsam-static)
|
|
set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE)
|
|
endif ()
|
|
|
|
if (GTSAM_BUILD_SHARED_LIBRARY)
|
|
message(STATUS "Building GTSAM - shared")
|
|
add_library(gtsam-shared SHARED ${gtsam_srcs})
|
|
target_link_libraries(gtsam-shared ${GTSAM_BOOST_LIBRARIES} ${GTSAM_TBB_LIBRARIES})
|
|
set_target_properties(gtsam-shared PROPERTIES
|
|
OUTPUT_NAME gtsam
|
|
CLEAN_DIRECT_OUTPUT 1
|
|
VERSION ${gtsam_version}
|
|
SOVERSION ${gtsam_soversion})
|
|
if(WIN32)
|
|
set_target_properties(gtsam-shared PROPERTIES
|
|
PREFIX ""
|
|
DEFINE_SYMBOL GTSAM_EXPORTS
|
|
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
|
endif()
|
|
install(TARGETS gtsam-shared EXPORT GTSAM-exports LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)
|
|
list(APPEND GTSAM_EXPORTED_TARGETS gtsam-shared)
|
|
set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE)
|
|
endif(GTSAM_BUILD_SHARED_LIBRARY)
|
|
|
|
# Set dataset paths
|
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/slam/dataset.cpp"
|
|
APPEND PROPERTY COMPILE_DEFINITIONS
|
|
"SOURCE_TREE_DATASET_DIR=\"${CMAKE_SOURCE_DIR}/examples/Data\""
|
|
"INSTALLED_DATASET_DIR=\"${GTSAM_TOOLBOX_INSTALL_PATH}/gtsam_examples/Data\"")
|
|
|
|
# Special cases
|
|
if(MSVC)
|
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/slam/serialization.cpp"
|
|
APPEND PROPERTY COMPILE_FLAGS "/bigobj")
|
|
endif()
|
|
|
|
# Create the matlab toolbox for the gtsam library
|
|
if (GTSAM_INSTALL_MATLAB_TOOLBOX)
|
|
# Set up codegen
|
|
include(GtsamMatlabWrap)
|
|
|
|
# Choose include flags depending on build process
|
|
set(MEX_INCLUDE_ROOT ${GTSAM_SOURCE_ROOT_DIR})
|
|
set(MEX_LIB_ROOT ${CMAKE_BINARY_DIR}) # FIXME: is this used?
|
|
set(GTSAM_LIB_DIR ${MEX_LIB_ROOT}/gtsam) # FIXME: is this used?
|
|
|
|
# Generate, build and install toolbox
|
|
set(mexFlags ${GTSAM_BUILD_MEX_BINARY_FLAGS} -I${MEX_INCLUDE_ROOT} -I${Boost_INCLUDE_DIR} -I${CMAKE_BINARY_DIR})
|
|
if("${gtsam-default}" STREQUAL "gtsam-static")
|
|
list(APPEND mexFlags -DGTSAM_IMPORT_STATIC)
|
|
endif()
|
|
|
|
# Macro to handle details of setting up targets
|
|
# FIXME: issue with dependency between wrap_gtsam and wrap_gtsam_build, only shows up on CMake 2.8.3
|
|
wrap_library(gtsam "${mexFlags}" "../" "${GTSAM_TBB_LIBRARIES}")
|
|
endif ()
|