Merged in jlblancoc/gtsam (pull request #372)

port to target-based CMake compile options and definitions

Approved-by: Chris Beall <chrisbeall@gmail.com>
release/4.3a0
JOSE LUIS BLANCO CLARACO 2019-01-30 04:05:50 +00:00 committed by Chris Beall
commit b81f845f16
4 changed files with 28 additions and 27 deletions

View File

@ -1,6 +1,6 @@
project(GTSAM CXX C)
cmake_minimum_required(VERSION 2.8.4)
cmake_minimum_required(VERSION 3.0)
# new feature to Cmake Version > 2.8.12
# Mac ONLY. Define Relative Path on Mac OS
@ -121,12 +121,11 @@ if(MSVC)
# If we use Boost shared libs, disable auto linking.
# Some libraries, at least Boost Program Options, rely on this to export DLL symbols.
if(NOT Boost_USE_STATIC_LIBS)
add_definitions(-DBOOST_ALL_NO_LIB)
add_definitions(-DBOOST_ALL_DYN_LINK)
list(APPEND GTSAM_COMPILE_DEFINITIONS BOOST_ALL_NO_LIB BOOST_ALL_DYN_LINK)
endif()
# Virtual memory range for PCH exceeded on VS2015
if(MSVC_VERSION LESS 1910) # older than VS2017
add_definitions(-Zm295)
list(APPEND GTSAM_COMPILE_OPTIONS -Zm295)
endif()
endif()
@ -141,14 +140,19 @@ endif()
option(GTSAM_DISABLE_NEW_TIMERS "Disables using Boost.chrono for timing" OFF)
# Allow for not using the timer libraries on boost < 1.48 (GTSAM timing code falls back to old timer library)
set(GTSAM_BOOST_LIBRARIES
${Boost_SERIALIZATION_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY} ${Boost_DATE_TIME_LIBRARY} ${Boost_REGEX_LIBRARY})
Boost::serialization
Boost::system
Boost::filesystem
Boost::thread
Boost::date_time
Boost::regex
)
if (GTSAM_DISABLE_NEW_TIMERS)
message("WARNING: GTSAM timing instrumentation manually disabled")
add_definitions(-DGTSAM_DISABLE_NEW_TIMERS)
list(APPEND GTSAM_COMPILE_DEFINITIONS DGTSAM_DISABLE_NEW_TIMERS)
else()
if(Boost_TIMER_LIBRARY)
list(APPEND GTSAM_BOOST_LIBRARIES ${Boost_TIMER_LIBRARY} ${Boost_CHRONO_LIBRARY})
list(APPEND GTSAM_BOOST_LIBRARIES Boost::timer Boost::chrono)
else()
list(APPEND GTSAM_BOOST_LIBRARIES rt) # When using the header-only boost timer library, need -lrt
message("WARNING: GTSAM timing instrumentation will use the older, less accurate, Boost timer library because boost older than 1.48 was found.")
@ -158,7 +162,7 @@ endif()
if(NOT (${Boost_VERSION} LESS 105600))
message("Ignoring Boost restriction on optional lvalue assignment from rvalues")
add_definitions(-DBOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES -DBOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES)
list(APPEND GTSAM_COMPILE_DEFINITIONS BOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES)
endif()
###############################################################################
@ -279,9 +283,9 @@ endif()
if (MSVC)
if (BUILD_SHARED_LIBS)
# mute eigen static assert to avoid errors in shared lib
add_definitions(-DEIGEN_NO_STATIC_ASSERT)
list(APPEND GTSAM_COMPILE_DEFINITIONS DEIGEN_NO_STATIC_ASSERT)
endif()
add_definitions(/wd4244) # Disable loss of precision which is thrown all over our Eigen
list(APPEND GTSAM_COMPILE_OPTIONS "/wd4244") # Disable loss of precision which is thrown all over our Eigen
endif()
###############################################################################
@ -347,27 +351,27 @@ include_directories(BEFORE
CppUnitLite)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
add_definitions(/wd4251 /wd4275 /wd4251 /wd4661 /wd4344 /wd4503) # Disable non-DLL-exported base class and other warnings
add_definitions(/bigobj) # Allow large object files for template-based code
list(APPEND GTSAM_COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
list(APPEND GTSAM_COMPILE_OPTIONS /wd4251 /wd4275 /wd4251 /wd4661 /wd4344 /wd4503) # Disable non-DLL-exported base class and other warnings
list(APPEND GTSAM_COMPILE_OPTIONS /bigobj) # Allow large object files for template-based code
endif()
# GCC 4.8+ complains about local typedefs which we use for shared_ptr etc.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
add_definitions(-Wno-unused-local-typedefs)
list(APPEND GTSAM_COMPILE_OPTIONS -Wno-unused-local-typedefs)
endif()
endif()
# As of XCode 7, clang also complains about this
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
add_definitions(-Wno-unused-local-typedefs)
list(APPEND GTSAM_COMPILE_OPTIONS -Wno-unused-local-typedefs)
endif()
endif()
if(GTSAM_ENABLE_CONSISTENCY_CHECKS)
add_definitions(-DGTSAM_EXTRA_CONSISTENCY_CHECKS)
list(APPEND GTSAM_COMPILE_DEFINITIONS GTSAM_EXTRA_CONSISTENCY_CHECKS)
endif()
###############################################################################

View File

@ -7,7 +7,7 @@
###################################################################################
# To create your own project, replace "example" with the actual name of your project
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.0)
project(example CXX C)
# Include GTSAM CMake tools

View File

@ -101,9 +101,10 @@ message(STATUS "Building GTSAM - shared: ${BUILD_SHARED_LIBS}")
# BUILD_SHARED_LIBS automatically defines static/shared libs:
add_library(gtsam ${gtsam_srcs})
target_link_libraries(gtsam
PUBLIC
${GTSAM_BOOST_LIBRARIES} ${GTSAM_ADDITIONAL_LIBRARIES})
target_link_libraries(gtsam PUBLIC ${GTSAM_BOOST_LIBRARIES})
target_link_libraries(gtsam PUBLIC ${GTSAM_ADDITIONAL_LIBRARIES})
target_compile_definitions(gtsam PUBLIC ${GTSAM_COMPILE_DEFINITIONS})
target_compile_options(gtsam PUBLIC ${GTSAM_COMPILE_OPTIONS})
set_target_properties(gtsam PROPERTIES
OUTPUT_NAME gtsam
CLEAN_DIRECT_OUTPUT 1

View File

@ -14,8 +14,6 @@ if(GTSAM_SUPPORT_NESTED_DISSECTION) # Only build partition if metis is built
set (gtsam_unstable_subdirs ${gtsam_unstable_subdirs} partition)
endif(GTSAM_SUPPORT_NESTED_DISSECTION)
set(GTSAM_UNSTABLE_BOOST_LIBRARIES ${GTSAM_BOOST_LIBRARIES})
add_custom_target(check.unstable COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
# To exclude a source from the library build (in any subfolder)
@ -72,10 +70,8 @@ set_target_properties(gtsam_unstable PROPERTIES
CLEAN_DIRECT_OUTPUT 1
VERSION ${gtsam_unstable_version}
SOVERSION ${gtsam_unstable_soversion})
target_link_libraries(gtsam_unstable
PUBLIC
gtsam
${GTSAM_UNSTABLE_BOOST_LIBRARIES})
target_link_libraries(gtsam_unstable PUBLIC gtsam)
# No need to link against Boost here, it's inherited from gtsam PUBLIC interface
if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with shared library
if (NOT BUILD_SHARED_LIBS)