From e029204c01f714d9cfbe25e78da65d66138d35a8 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 19 Feb 2014 13:10:37 -0500 Subject: [PATCH 1/5] Added cmake code to install cmake tools, and a GTSAM-CMakeToolsConfig file to automatically find them. --- CMakeLists.txt | 3 +++ cmake/CMakeLists.txt | 26 ++++++++++++++++++++++++++ cmake/GTSAM-CMakeToolsConfig.cmake | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 cmake/CMakeLists.txt create mode 100644 cmake/GTSAM-CMakeToolsConfig.cmake 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..d201fc1d7 --- /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(GTSAM-CMakeTools) +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 + GTSAM-CMakeToolsConfig.cmake + Config.cmake.in + dllexport.h.in + GtsamBuildTypes.cmake + GtsamMakeConfigFile.cmake + GtsamMatlabWrap.cmake + GtsamPrinting.cmake + GtsamPythonWrap.cmake + GtsamTesting.cmake + GtsamTestingObsolete.cmake + DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAM-CMakeTools") + + diff --git a/cmake/GTSAM-CMakeToolsConfig.cmake b/cmake/GTSAM-CMakeToolsConfig.cmake new file mode 100644 index 000000000..c79a2f5c2 --- /dev/null +++ b/cmake/GTSAM-CMakeToolsConfig.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}") From 781349ec86989eb2724b7697782ebe33f5494d7d Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 19 Feb 2014 13:12:22 -0500 Subject: [PATCH 2/5] Renamed to GTSAMCMakeTools --- cmake/CMakeLists.txt | 6 +++--- ...M-CMakeToolsConfig.cmake => GTSAMCMakeToolsConfig.cmake} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename cmake/{GTSAM-CMakeToolsConfig.cmake => GTSAMCMakeToolsConfig.cmake} (100%) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d201fc1d7..89cf53898 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -2,7 +2,7 @@ # 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(GTSAM-CMakeTools) +# find_package(GTSAMCMakeTools) if(WIN32 AND NOT CYGWIN) set(SCRIPT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/CMake") else() @@ -11,7 +11,7 @@ endif() # Install scripts install(FILES - GTSAM-CMakeToolsConfig.cmake + GTSAMCMakeToolsConfig.cmake Config.cmake.in dllexport.h.in GtsamBuildTypes.cmake @@ -21,6 +21,6 @@ install(FILES GtsamPythonWrap.cmake GtsamTesting.cmake GtsamTestingObsolete.cmake - DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAM-CMakeTools") + DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAMCMakeTools") diff --git a/cmake/GTSAM-CMakeToolsConfig.cmake b/cmake/GTSAMCMakeToolsConfig.cmake similarity index 100% rename from cmake/GTSAM-CMakeToolsConfig.cmake rename to cmake/GTSAMCMakeToolsConfig.cmake From b4d7ede12330dc86007923335a707bd62ceffb2d Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 19 Feb 2014 15:43:16 -0500 Subject: [PATCH 3/5] Better debug flag for Profiling build type --- cmake/GtsamBuildTypes.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From ee274419fb9c8ac0523b2353db619f1550a432e9 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 19 Feb 2014 15:43:25 -0500 Subject: [PATCH 4/5] Documentation improvement --- cmake/GtsamMatlabWrap.cmake | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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}") From c629339a7ca46e31903392cb1829a482cb76389f Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 19 Feb 2014 15:43:37 -0500 Subject: [PATCH 5/5] Added README file for cmake tools --- cmake/CMakeLists.txt | 2 +- cmake/README.html | 92 +++++++++++++++++++++++++++++++++++++ cmake/README.md | 105 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 cmake/README.html create mode 100644 cmake/README.md diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 89cf53898..49069c57f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -17,10 +17,10 @@ install(FILES GtsamBuildTypes.cmake GtsamMakeConfigFile.cmake GtsamMatlabWrap.cmake - GtsamPrinting.cmake GtsamPythonWrap.cmake GtsamTesting.cmake GtsamTestingObsolete.cmake + README.html DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAMCMakeTools") 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:

+
    +
  • 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 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