diff --git a/CMakeLists.txt b/CMakeLists.txt index cf5a1a962..c6f5852b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -321,6 +321,9 @@ if (DOXYGEN_FOUND) add_subdirectory(doc) endif() +# CMake Tools +add_subdirectory(cmake) + ############################################################################### # Set up CPack diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt new file mode 100644 index 000000000..49069c57f --- /dev/null +++ b/cmake/CMakeLists.txt @@ -0,0 +1,26 @@ +# This file installs the scripts from this directory that may be used in other +# projects. See README.txt in this directory for documentation. + +# Set the install directory depending on the platform so it will be found by +# find_package(GTSAMCMakeTools) +if(WIN32 AND NOT CYGWIN) + set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/CMake") +else() + set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib/cmake") +endif() + +# Install scripts +install(FILES + GTSAMCMakeToolsConfig.cmake + Config.cmake.in + dllexport.h.in + GtsamBuildTypes.cmake + GtsamMakeConfigFile.cmake + GtsamMatlabWrap.cmake + GtsamPythonWrap.cmake + GtsamTesting.cmake + GtsamTestingObsolete.cmake + README.html + DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAMCMakeTools") + + diff --git a/cmake/GTSAMCMakeToolsConfig.cmake b/cmake/GTSAMCMakeToolsConfig.cmake new file mode 100644 index 000000000..c79a2f5c2 --- /dev/null +++ b/cmake/GTSAMCMakeToolsConfig.cmake @@ -0,0 +1,3 @@ +# This config file modifies CMAKE_MODULE_PATH so that the GTSAM-CMakeTools files may be included + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 51e66627d..64c616de5 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -45,8 +45,8 @@ if(NOT FIRST_PASS_DONE) set(CMAKE_EXE_LINKER_FLAGS_TIMING "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during timing builds." FORCE) set(CMAKE_SHARED_LINKER_FLAGS_TIMING "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during timing builds." FORCE) mark_as_advanced(CMAKE_C_FLAGS_TIMING CMAKE_CXX_FLAGS_TIMING CMAKE_EXE_LINKER_FLAGS_TIMING CMAKE_SHARED_LINKER_FLAGS_TIMING) - set(CMAKE_C_FLAGS_PROFILING "-g -O3 -Wall -DNDEBUG" CACHE STRING "Flags used by the compiler during profiling builds." FORCE) - set(CMAKE_CXX_FLAGS_PROFILING "-g -O3 -Wall -DNDEBUG" CACHE STRING "Flags used by the compiler during profiling builds." FORCE) + set(CMAKE_C_FLAGS_PROFILING "-g1 -O3 -Wall -DNDEBUG" CACHE STRING "Flags used by the compiler during profiling builds." FORCE) + set(CMAKE_CXX_FLAGS_PROFILING "-g1 -O3 -Wall -DNDEBUG" CACHE STRING "Flags used by the compiler during profiling builds." FORCE) set(CMAKE_EXE_LINKER_FLAGS_PROFILING "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during profiling builds." FORCE) set(CMAKE_SHARED_LINKER_FLAGS_PROFILING "${CMAKE__LINKER_FLAGS_RELEASE}" CACHE STRING "Linker flags during profiling builds." FORCE) mark_as_advanced(CMAKE_C_FLAGS_PROFILING CMAKE_CXX_FLAGS_PROFILING CMAKE_EXE_LINKER_FLAGS_PROFILING CMAKE_SHARED_LINKER_FLAGS_PROFILING) diff --git a/cmake/GtsamMatlabWrap.cmake b/cmake/GtsamMatlabWrap.cmake index 1fde266f4..98bd7f469 100644 --- a/cmake/GtsamMatlabWrap.cmake +++ b/cmake/GtsamMatlabWrap.cmake @@ -40,13 +40,21 @@ set(MATLAB_ROOT "${MATLAB_ROOT}" CACHE PATH "Path to MATLAB installation root (e # User-friendly wrapping function. Builds a mex module from the provided -# interfaceHeader. For example, for the interface header /path/to/gtsam.h, +# interfaceHeader. For example, for the interface header gtsam.h, # this will build the wrap module 'gtsam'. -# Params: -# interfaceHeader : Absolute or relative path to the interface definition file -# linkLibraries : All dependent CMake target names, library names, or full library paths -# extraIncludeDirs : Extra include directories, in addition to those already passed to include_directories(...) -# extraMexFlags : Any additional compiler flags +# +# Arguments: +# +# interfaceHeader: The relative path to the wrapper interface definition file. +# linkLibraries: Any *additional* libraries to link. Your project library +# (e.g. `lba`), libraries it depends on, and any necessary +# MATLAB libraries will be linked automatically. So normally, +# leave this empty. +# extraIncludeDirs: Any *additional* include paths required by dependent +# libraries that have not already been added by +# include_directories. Again, normally, leave this empty. +# extraMexFlags: Any *additional* flags to pass to the compiler when building +# the wrap code. Normally, leave this empty. function(wrap_and_install_library interfaceHeader linkLibraries extraIncludeDirs extraMexFlags) wrap_library_internal("${interfaceHeader}" "${linkLibraries}" "${extraIncludeDirs}" "${mexFlags}") install_wrapped_library_internal("${interfaceHeader}") diff --git a/cmake/README.html b/cmake/README.html new file mode 100644 index 000000000..8170cd489 --- /dev/null +++ b/cmake/README.html @@ -0,0 +1,92 @@ +

GTSAMCMakeTools

+

This is the collection of GTSAM CMake tools that may be useful in external projects. The way to use this collection is by first making a find_package call:

+
find_package(GTSAMCMakeTools)
+
+

which will add a directory containing the GTSAM CMake tools to the CMAKE_MODULE_PATH variable. After that, you may include the files you would like to use. These files and the functions they define are explained below.

+

GtsamBuildTypes

+
include(GtsamBuildTypes)
+
+

Including this file immediately sets up the following build types and a drop-down list in cmake-gui:

+ +

It also configures several minor details, as follows:

+ +

It defines the following functions:

+ +

GtsamTesting

+
include(GtsamTesting)
+
+

Defines two useful functions for creating CTest unit tests. Also immediately creates a check target that builds and runs all unit tests.

+ +

GtsamMatlabWrap

+
include(GtsamMatlabWrap)
+
+

Defines functions for generating MATLAB wrappers. Also immediately creates several CMake options for configuring the wrapper.

+ +

GtsamMakeConfigFile

+
include(GtsamMakeConfigFile)
+
+

Defines a function for generating a config file so your project may be found with the CMake find_package function. TODO: Write documentation.

\ No newline at end of file diff --git a/cmake/README.md b/cmake/README.md new file mode 100644 index 000000000..0b9f7e853 --- /dev/null +++ b/cmake/README.md @@ -0,0 +1,105 @@ +GTSAMCMakeTools +=============== + +This is the collection of GTSAM CMake tools that may be useful in external projects. The way to use this collection is by first making a find_package call: + + find_package(GTSAMCMakeTools) + +which will add a directory containing the GTSAM CMake tools to the CMAKE_MODULE_PATH variable. After that, you may include the files you would like to use. These files and the functions they define are explained below. + +GtsamBuildTypes +--------------- + + include(GtsamBuildTypes) + +Including this file immediately sets up the following build types and a drop-down list in cmake-gui: + +* `Debug` +* `Release` +* `RelWithDebInfo` +* `Profiling`: All optimizations enabled and minimal debug symbols +* `Timing`: Defines the symbol GTSAM_ENABLE_TIMING for using GTSAM timing instrumentation + +It also configures several minor details, as follows: + +* The compile flag `-ftemplate-depth=1024` is set for newer versions of Clang to handle complex templates. +* On Windows, executable and dll output paths are set to `${CMAKE_BINARY_DIR}/bin` and import library output to `${CMAKE_BINARY_DIR}/bin`. + +It defines the following functions: + +* `gtsam_assign_source_folders( [files] )` Organizes files in the IDE into folders to reflect the actual directory structure of those files. Folders will be determined relative to the current source folder when this function is called. +* `gtsam_assign_all_source_folders()` Calls `gtsam_assign_source_folders` on all cpp, c, and h files recursively in the current source folder. + +GtsamTesting +------------ + + include(GtsamTesting) + +Defines two useful functions for creating CTest unit tests. Also immediately creates a `check` target that builds and runs all unit tests. + +* `gtsamAddTestsGlob(groupName globPatterns excludedFiles linkLibraries)` Add a group of unit tests. A list of unit test .cpp files or glob patterns specifies the tests to create. Tests are assigned into a group name so they can easily by run independently with a make target. Running 'make check' builds and runs all tests. + + Usage example: + + gtsamAddTestsGlob(basic "test*.cpp" "testBroken.cpp" "gtsam;GeographicLib") + + Arguments: + + groupName: A name that will allow this group of tests to be run independently, e.g. + 'basic' causes a 'check.basic' target to be created to run this test + group. + globPatterns: The list of files or glob patterns from which to create unit tests, with + one test created for each cpp file. e.g. "test*.cpp", or + "testA*.cpp;testB*.cpp;testOneThing.cpp". + excludedFiles: A list of files or globs to exclude, e.g. "testC*.cpp;testBroken.cpp". + Pass an empty string "" if nothing needs to be excluded. + linkLibraries: The list of libraries to link to in addition to CppUnitLite. + +* `gtsamAddExamplesGlob(globPatterns excludedFiles linkLibraries)` Add scripts that will serve as examples of how to use the library. A list of files or glob patterns is specified, and one executable will be created for each matching .cpp file. These executables will not be installed. They are build with 'make all' if GTSAM_BUILD_EXAMPLES_ALWAYS is enabled. They may also be built with 'make examples'. + + Usage example: + + gtsamAddExamplesGlob("*.cpp" "BrokenExample.cpp" "gtsam;GeographicLib") + + Arguments: + + globPatterns: The list of files or glob patterns from which to create unit tests, with + one test created for each cpp file. e.g. "*.cpp", or + "A*.cpp;B*.cpp;MyExample.cpp". + excludedFiles: A list of files or globs to exclude, e.g. "C*.cpp;BrokenExample.cpp". Pass + an empty string "" if nothing needs to be excluded. + linkLibraries: The list of libraries to link to. + +GtsamMatlabWrap +--------------- + + include(GtsamMatlabWrap) + +Defines functions for generating MATLAB wrappers. Also immediately creates several CMake options for configuring the wrapper. + +* `wrap_and_install_library(interfaceHeader linkLibraries extraIncludeDirs extraMexFlags)` Generates wrap code and compiles the wrapper. + + Usage example: + + `wrap_and_install_library("lba.h" "" "" "")` + + Arguments: + + interfaceHeader: The relative or absolute path to the wrapper interface + definition file. + linkLibraries: Any *additional* libraries to link. Your project library + (e.g. `lba`), libraries it depends on, and any necessary + MATLAB libraries will be linked automatically. So normally, + leave this empty. + extraIncludeDirs: Any *additional* include paths required by dependent + libraries that have not already been added by + include_directories. Again, normally, leave this empty. + extraMexFlags: Any *additional* flags to pass to the compiler when building + the wrap code. Normally, leave this empty. + +GtsamMakeConfigFile +------------------- + + include(GtsamMakeConfigFile) + +Defines a function for generating a config file so your project may be found with the CMake `find_package` function. TODO: Write documentation. \ No newline at end of file