From 6111c099abf65e503c0aa3274aea628186709aea Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Wed, 13 Mar 2013 18:17:39 +0000 Subject: [PATCH] Improved build of shared vs static GTSAM libraries - now possible to build either one or both, executables link to the shared if it is being build, or otherwise to the static. Also removed separate shared/static CMake flags for gtsam_unstable, now uses the same GTSAM_BUILD_SHARED and GTSAM_BUILD_STATIC as gtsam. --- CMakeLists.txt | 17 ++++++++++-- gtsam/CMakeLists.txt | 6 +---- gtsam/base/CMakeLists.txt | 4 +-- gtsam/discrete/CMakeLists.txt | 2 +- gtsam/geometry/CMakeLists.txt | 4 +-- gtsam/inference/CMakeLists.txt | 4 +-- gtsam/linear/CMakeLists.txt | 4 +-- gtsam/nonlinear/CMakeLists.txt | 4 +-- gtsam/slam/CMakeLists.txt | 4 +-- gtsam_unstable/CMakeLists.txt | 33 +++++++++++------------- gtsam_unstable/base/CMakeLists.txt | 4 +-- gtsam_unstable/discrete/CMakeLists.txt | 7 +++-- gtsam_unstable/dynamics/CMakeLists.txt | 4 +-- gtsam_unstable/geometry/CMakeLists.txt | 4 +-- gtsam_unstable/linear/CMakeLists.txt | 4 +-- gtsam_unstable/navigation/CMakeLists.txt | 4 +-- gtsam_unstable/nonlinear/CMakeLists.txt | 4 +-- gtsam_unstable/slam/CMakeLists.txt | 4 +-- tests/CMakeLists.txt | 5 ++-- 19 files changed, 64 insertions(+), 58 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0346fa0f7..1f4c180c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,13 +53,13 @@ if(GTSAM_UNSTABLE_AVAILABLE) endif() if(NOT MSVC) option(GTSAM_BUILD_SHARED_LIBRARY "Enable/Disable building of a shared version of gtsam" ON) - option(GTSAM_BUILD_STATIC_LIBRARY "Enable/Disable building of a static version of gtsam" ON) + option(GTSAM_BUILD_STATIC_LIBRARY "Enable/Disable building of a static version of gtsam" OFF) else() set(GTSAM_BUILD_STATIC_LIBRARY ON) endif() option(GTSAM_USE_QUATERNIONS "Enable/Disable using an internal Quaternion representation for rotations instead of rotation matrices" OFF) if(NOT MSVC) - option(GTSAM_BUILD_CONVENIENCE_LIBRARIES "Enable/Disable use of convenience libraries for faster development rebuilds, but slower install" ON) + option(GTSAM_BUILD_CONVENIENCE_LIBRARIES "Enable/Disable use of convenience libraries for faster development rebuilds, but slower install" OFF) endif() @@ -153,6 +153,19 @@ link_directories(${Boost_LIBRARY_DIRS}) ############################################################################### # Add components +# Set default library - static or shared, before adding subdirectories +if(GTSAM_BUILD_SHARED_LIBRARY) + set(gtsam-default gtsam-shared) + if(GTSAM_BUILD_UNSTABLE) + set(gtsam_unstable-default gtsam_unstable-shared) + endif() +else() + set(gtsam-default gtsam-static) + if(GTSAM_BUILD_UNSTABLE) + set(gtsam_unstable-default gtsam_unstable-static) + endif() +endif() + # Build CppUnitLite add_subdirectory(CppUnitLite) diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 3b6db78cb..eed4c719d 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -94,8 +94,7 @@ if (GTSAM_BUILD_STATIC_LIBRARY) 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) - set(gtsam-lib gtsam-static) -endif (GTSAM_BUILD_STATIC_LIBRARY) +endif () if (GTSAM_BUILD_SHARED_LIBRARY) message(STATUS "Building GTSAM - shared") @@ -109,9 +108,6 @@ if (GTSAM_BUILD_SHARED_LIBRARY) 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) - if (NOT GTSAM_BUILD_STATIC_LIBRARY) - set(gtsam-lib "gtsam-shared") - endif() endif(GTSAM_BUILD_SHARED_LIBRARY) # Set dataset paths diff --git a/gtsam/base/CMakeLists.txt b/gtsam/base/CMakeLists.txt index af794ddd8..a1f50d61d 100644 --- a/gtsam/base/CMakeLists.txt +++ b/gtsam/base/CMakeLists.txt @@ -15,11 +15,11 @@ set(base_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(base "${base_local_libs}" "gtsam-static" "${base_excluded_files}") + gtsam_add_subdir_tests(base "${base_local_libs}" "${gtsam-default}" "${base_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(base "${base_local_libs}" "gtsam-static" "${base_excluded_files}") + gtsam_add_subdir_timing(base "${base_local_libs}" "${gtsam-default}" "${base_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam/discrete/CMakeLists.txt b/gtsam/discrete/CMakeLists.txt index 9e4647f80..ac43359d2 100644 --- a/gtsam/discrete/CMakeLists.txt +++ b/gtsam/discrete/CMakeLists.txt @@ -17,7 +17,7 @@ set (discrete_excluded_tests "") # Add all tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(discrete "${discrete_local_libs}" "gtsam-static" "${discrete_excluded_tests}") + gtsam_add_subdir_tests(discrete "${discrete_local_libs}" "${gtsam-default}" "${discrete_excluded_tests}") endif() # Build timing scripts diff --git a/gtsam/geometry/CMakeLists.txt b/gtsam/geometry/CMakeLists.txt index 6ce55b7ca..e5acb3c21 100644 --- a/gtsam/geometry/CMakeLists.txt +++ b/gtsam/geometry/CMakeLists.txt @@ -16,11 +16,11 @@ set(geometry_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(geometry "${geometry_local_libs}" "gtsam-static" "${geometry_excluded_files}") + gtsam_add_subdir_tests(geometry "${geometry_local_libs}" "${gtsam-default}" "${geometry_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(geometry "${geometry_local_libs}" "gtsam-static" "${geometry_excluded_files}") + gtsam_add_subdir_timing(geometry "${geometry_local_libs}" "${gtsam-default}" "${geometry_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam/inference/CMakeLists.txt b/gtsam/inference/CMakeLists.txt index 5e0f75b24..f88abf463 100644 --- a/gtsam/inference/CMakeLists.txt +++ b/gtsam/inference/CMakeLists.txt @@ -18,11 +18,11 @@ set(inference_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(inference "${inference_local_libs}" "gtsam-static" "${inference_excluded_files}") + gtsam_add_subdir_tests(inference "${inference_local_libs}" "${gtsam-default}" "${inference_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(inference "${inference_local_libs}" "gtsam-static" "${inference_excluded_files}") + gtsam_add_subdir_timing(inference "${inference_local_libs}" "${gtsam-default}" "${inference_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam/linear/CMakeLists.txt b/gtsam/linear/CMakeLists.txt index 81b0d4a33..802cb4d78 100644 --- a/gtsam/linear/CMakeLists.txt +++ b/gtsam/linear/CMakeLists.txt @@ -19,10 +19,10 @@ set(linear_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(linear "${linear_local_libs}" "gtsam-static" "${linear_excluded_files}") + gtsam_add_subdir_tests(linear "${linear_local_libs}" "${gtsam-default}" "${linear_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(linear "${linear_local_libs}" "gtsam-static" "${linear_excluded_files}") + gtsam_add_subdir_timing(linear "${linear_local_libs}" "${gtsam-default}" "${linear_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam/nonlinear/CMakeLists.txt b/gtsam/nonlinear/CMakeLists.txt index 690d460a3..4dcb5e8d8 100644 --- a/gtsam/nonlinear/CMakeLists.txt +++ b/gtsam/nonlinear/CMakeLists.txt @@ -20,11 +20,11 @@ set(nonlinear_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(nonlinear "${nonlinear_local_libs}" "gtsam-static" "${nonlinear_excluded_files}") + gtsam_add_subdir_tests(nonlinear "${nonlinear_local_libs}" "${gtsam-default}" "${nonlinear_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(nonlinear "${nonlinear_local_libs}" "gtsam-static" "${nonlinear_excluded_files}") + gtsam_add_subdir_timing(nonlinear "${nonlinear_local_libs}" "${gtsam-default}" "${nonlinear_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam/slam/CMakeLists.txt b/gtsam/slam/CMakeLists.txt index c25e32bd4..ba5ad5d24 100644 --- a/gtsam/slam/CMakeLists.txt +++ b/gtsam/slam/CMakeLists.txt @@ -21,10 +21,10 @@ set(slam_excluded_files # Build tests if (GTSAM_BUILD_TESTS) - gtsam_add_subdir_tests(slam "${slam_local_libs}" "gtsam-static" "${slam_excluded_files}") + gtsam_add_subdir_tests(slam "${slam_local_libs}" "${gtsam-default}" "${slam_excluded_files}") endif(GTSAM_BUILD_TESTS) # Build timing scripts if (GTSAM_BUILD_TIMING) - gtsam_add_subdir_timing(slam "${slam_local_libs}" "gtsam-static" "${slam_excluded_files}") + gtsam_add_subdir_timing(slam "${slam_local_libs}" "${gtsam-default}" "${slam_excluded_files}") endif(GTSAM_BUILD_TIMING) diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 72230de8c..7757a146c 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -44,10 +44,6 @@ set(gtsam_unstable_srcs ${navigation_srcs} ) -if(NOT MSVC) - option (GTSAM_UNSTABLE_BUILD_SHARED_LIBRARY "Enable/Disable building of a shared version of gtsam_unstable" ON) -endif() - # Versions - same as core gtsam library set(gtsam_unstable_version ${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}.${GTSAM_VERSION_PATCH}) set(gtsam_unstable_soversion ${GTSAM_VERSION_MAJOR}) @@ -55,20 +51,21 @@ message(STATUS "GTSAM_UNSTABLE Version: ${gtsam_unstable_version}") message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}") # build shared and static versions of the library -message(STATUS "Building GTSAM_UNSTABLE - static") -add_library(gtsam_unstable-static STATIC ${gtsam_unstable_srcs}) -set_target_properties(gtsam_unstable-static PROPERTIES - OUTPUT_NAME gtsam_unstable - CLEAN_DIRECT_OUTPUT 1 - VERSION ${gtsam_unstable_version} - SOVERSION ${gtsam_unstable_soversion}) -target_link_libraries(gtsam_unstable-static gtsam-static ${GTSAM_UNSTABLE_BOOST_LIBRARIES}) -set(gtsam_unstable-lib "gtsam_unstable-static") -install(TARGETS gtsam_unstable-static EXPORT GTSAM-exports ARCHIVE DESTINATION lib) -list(APPEND GTSAM_EXPORTED_TARGETS gtsam_unstable-static) -set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE) +if (GTSAM_BUILD_STATIC_LIBRARY) + message(STATUS "Building GTSAM_UNSTABLE - static") + add_library(gtsam_unstable-static STATIC ${gtsam_unstable_srcs}) + set_target_properties(gtsam_unstable-static PROPERTIES + OUTPUT_NAME gtsam_unstable + CLEAN_DIRECT_OUTPUT 1 + VERSION ${gtsam_unstable_version} + SOVERSION ${gtsam_unstable_soversion}) + target_link_libraries(gtsam_unstable-static gtsam-static ${GTSAM_UNSTABLE_BOOST_LIBRARIES}) + install(TARGETS gtsam_unstable-static EXPORT GTSAM-exports ARCHIVE DESTINATION lib) + list(APPEND GTSAM_EXPORTED_TARGETS gtsam_unstable-static) + set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE) +endif() -if (GTSAM_UNSTABLE_BUILD_SHARED_LIBRARY) +if (GTSAM_BUILD_SHARED_LIBRARY) message(STATUS "Building GTSAM_UNSTABLE - shared") add_library(gtsam_unstable-shared SHARED ${gtsam_unstable_srcs}) set_target_properties(gtsam_unstable-shared PROPERTIES @@ -80,7 +77,7 @@ if (GTSAM_UNSTABLE_BUILD_SHARED_LIBRARY) install(TARGETS gtsam_unstable-shared EXPORT GTSAM-exports LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) list(APPEND GTSAM_EXPORTED_TARGETS gtsam_unstable-shared) set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE) -endif(GTSAM_UNSTABLE_BUILD_SHARED_LIBRARY) +endif() # Wrap version for gtsam_unstable if (GTSAM_INSTALL_MATLAB_TOOLBOX) diff --git a/gtsam_unstable/base/CMakeLists.txt b/gtsam_unstable/base/CMakeLists.txt index 0545cd4c9..420402015 100644 --- a/gtsam_unstable/base/CMakeLists.txt +++ b/gtsam_unstable/base/CMakeLists.txt @@ -8,8 +8,8 @@ set(base_local_libs base_unstable) set (base_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (base_excluded_tests "") diff --git a/gtsam_unstable/discrete/CMakeLists.txt b/gtsam_unstable/discrete/CMakeLists.txt index ae84426a8..e0196dca2 100644 --- a/gtsam_unstable/discrete/CMakeLists.txt +++ b/gtsam_unstable/discrete/CMakeLists.txt @@ -12,8 +12,8 @@ set(discrete_local_libs ) set (discrete_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work #set (discrete_excluded_tests @@ -45,7 +45,6 @@ if (GTSAM_BUILD_EXAMPLES) add_custom_target(${example}.run ${EXECUTABLE_OUTPUT_PATH}${example} ${ARGN}) endif() - add_dependencies(${example} gtsam-static gtsam_unstable-static) - target_link_libraries(${example} gtsam-static gtsam_unstable-static) + target_link_libraries(${example} ${gtsam-default} ${gtsam_unstable-default}) endforeach(example) endif (GTSAM_BUILD_EXAMPLES) diff --git a/gtsam_unstable/dynamics/CMakeLists.txt b/gtsam_unstable/dynamics/CMakeLists.txt index d0d45e0e4..bf34eb476 100644 --- a/gtsam_unstable/dynamics/CMakeLists.txt +++ b/gtsam_unstable/dynamics/CMakeLists.txt @@ -15,8 +15,8 @@ set(dynamics_local_libs ) set (dynamics_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (dynamics_excluded_tests "") diff --git a/gtsam_unstable/geometry/CMakeLists.txt b/gtsam_unstable/geometry/CMakeLists.txt index d6b6a706d..21ba37d41 100644 --- a/gtsam_unstable/geometry/CMakeLists.txt +++ b/gtsam_unstable/geometry/CMakeLists.txt @@ -11,8 +11,8 @@ set(geometry_local_libs ) set (geometry_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (geometry_excluded_tests "") diff --git a/gtsam_unstable/linear/CMakeLists.txt b/gtsam_unstable/linear/CMakeLists.txt index d5429a5df..51bfa8f86 100644 --- a/gtsam_unstable/linear/CMakeLists.txt +++ b/gtsam_unstable/linear/CMakeLists.txt @@ -9,8 +9,8 @@ set(linear_local_libs base) set (linear_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (base_excluded_tests "") diff --git a/gtsam_unstable/navigation/CMakeLists.txt b/gtsam_unstable/navigation/CMakeLists.txt index fcd458c07..b33658a13 100644 --- a/gtsam_unstable/navigation/CMakeLists.txt +++ b/gtsam_unstable/navigation/CMakeLists.txt @@ -15,8 +15,8 @@ set(navigation_local_libs ) set (navigation_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (navigation_excluded_tests "") diff --git a/gtsam_unstable/nonlinear/CMakeLists.txt b/gtsam_unstable/nonlinear/CMakeLists.txt index a815e956d..767b0162b 100644 --- a/gtsam_unstable/nonlinear/CMakeLists.txt +++ b/gtsam_unstable/nonlinear/CMakeLists.txt @@ -14,8 +14,8 @@ set(nonlinear_local_libs ) set (nonlinear_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (nonlinear_excluded_tests "") diff --git a/gtsam_unstable/slam/CMakeLists.txt b/gtsam_unstable/slam/CMakeLists.txt index 33cb45df9..1a92167ac 100644 --- a/gtsam_unstable/slam/CMakeLists.txt +++ b/gtsam_unstable/slam/CMakeLists.txt @@ -15,8 +15,8 @@ set(slam_local_libs ) set (slam_full_libs - gtsam-static - gtsam_unstable-static) + ${gtsam-default} + ${gtsam_unstable-default}) # Exclude tests that don't work set (slam_excluded_tests "") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 213d2f5e9..59e801bda 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,7 @@ file(GLOB time_srcs "time*.cpp") list(REMOVE_ITEM test_lib_srcs ${test_srcs}) list(REMOVE_ITEM test_lib_srcs ${time_srcs}) add_library(test_lib STATIC ${test_lib_srcs}) +target_link_libraries(test_lib ${gtsam-default}) # Assemble local libraries set(tests_local_libs @@ -38,7 +39,7 @@ if (GTSAM_BUILD_TESTS) # Build grouped tests gtsam_add_grouped_scripts("tests" # Use subdirectory as group label "test*.cpp" check "Test" # Standard for all tests - "${tests_local_libs}" "gtsam-static;CppUnitLite;test_lib" "${tests_exclude}" # Pass in linking and exclusion lists + "${tests_local_libs}" "${gtsam-default};CppUnitLite;test_lib" "${tests_exclude}" # Pass in linking and exclusion lists ${is_test}) # Set all as tests endif (GTSAM_BUILD_TESTS) @@ -51,6 +52,6 @@ if (GTSAM_BUILD_TIMING) # Build grouped benchmarks gtsam_add_grouped_scripts("tests" # Use subdirectory as group label "time*.cpp" timing "Timing Benchmark" # Standard for all timing scripts - "${tests_local_libs}" "gtsam-static;CppUnitLite;test_lib" "${tests_exclude}" # Pass in linking and exclusion lists + "${tests_local_libs}" "${gtsam-default};CppUnitLite;test_lib" "${tests_exclude}" # Pass in linking and exclusion lists ${is_test}) endif (GTSAM_BUILD_TIMING)