Merge pull request #1464 from Ibarria/law/cmakeoptions

Allow override of BUILD_SHARED_LIBS
release/4.3a0
Frank Dellaert 2023-02-16 10:59:25 -08:00 committed by GitHub
commit a96b6918db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 20 deletions

View File

@ -82,7 +82,7 @@ else()
endif ()
if (MSVC)
if (BUILD_SHARED_LIBS)
if (GTSAM_SHARED_LIB)
# mute eigen static assert to avoid errors in shared lib
list_append_cache(GTSAM_COMPILE_DEFINITIONS_PUBLIC EIGEN_NO_STATIC_ASSERT)
endif()

View File

@ -14,7 +14,8 @@ if(GTSAM_UNSTABLE_AVAILABLE)
option(GTSAM_UNSTABLE_BUILD_PYTHON "Enable/Disable Python wrapper for libgtsam_unstable" ON)
option(GTSAM_UNSTABLE_INSTALL_MATLAB_TOOLBOX "Enable/Disable MATLAB wrapper for libgtsam_unstable" OFF)
endif()
option(BUILD_SHARED_LIBS "Build shared gtsam library, instead of static" ON)
option(GTSAM_FORCE_SHARED_LIB "Force gtsam to be a shared library, overriding BUILD_SHARED_LIBS" OFF)
option(GTSAM_FORCE_STATIC_LIB "Force gtsam to be a static library, overriding BUILD_SHARED_LIBS" OFF)
option(GTSAM_USE_QUATERNIONS "Enable/Disable using an internal Quaternion representation for rotations instead of rotation matrices. If enable, Rot3::EXPMAP is enforced by default." OFF)
option(GTSAM_POSE3_EXPMAP "Enable/Disable using Pose3::EXPMAP as the default mode. If disabled, Pose3::FIRST_ORDER will be used." ON)
option(GTSAM_ROT3_EXPMAP "Ignore if GTSAM_USE_QUATERNIONS is OFF (Rot3::EXPMAP by default). Otherwise, enable Rot3::EXPMAP, or if disabled, use Rot3::CAYLEY." ON)
@ -30,6 +31,24 @@ option(GTSAM_SUPPORT_NESTED_DISSECTION "Support Metis-based nested dissecti
option(GTSAM_TANGENT_PREINTEGRATION "Use new ImuFactor with integration on tangent space" ON)
option(GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR "Use the slower but correct version of BetweenFactor" OFF)
if (GTSAM_FORCE_SHARED_LIB)
message(STATUS "GTSAM is a shared library due to GTSAM_FORCE_SHARED_LIB")
set(GTSAM_LIBRARY_TYPE SHARED CACHE STRING "" FORCE)
set(GTSAM_SHARED_LIB 1 CACHE BOOL "" FORCE)
elseif (GTSAM_FORCE_STATIC_LIB)
message(STATUS "GTSAM is a static library due to GTSAM_FORCE_STATIC_LIB")
set(GTSAM_LIBRARY_TYPE STATIC CACHE STRING "" FORCE)
set(GTSAM_SHARED_LIB 0 CACHE BOOL "" FORCE)
elseif (BUILD_SHARED_LIBS)
message(STATUS "GTSAM is a shared library due to BUILD_SHARED_LIBS is ON")
set(GTSAM_LIBRARY_TYPE SHARED CACHE STRING "" FORCE)
set(GTSAM_SHARED_LIB 1 CACHE BOOL "" FORCE)
else()
message(STATUS "GTSAM is a static library due to BUILD_SHARED_LIBS is OFF")
set(GTSAM_LIBRARY_TYPE STATIC CACHE STRING "" FORCE)
set(GTSAM_SHARED_LIB 0 CACHE BOOL "" FORCE)
endif()
if(NOT MSVC AND NOT XCODE_VERSION)
option(GTSAM_BUILD_WITH_CCACHE "Use ccache compiler cache" ON)
endif()

View File

@ -14,11 +14,11 @@ endif()
# or explicit instantiation will generate build errors.
# See: https://bitbucket.org/gtborg/gtsam/issues/417/fail-to-build-on-msvc-2017
#
if(MSVC AND BUILD_SHARED_LIBS)
if(MSVC AND GTSAM_SHARED_LIB)
list_append_cache(GTSAM_COMPILE_DEFINITIONS_PUBLIC EIGEN_NO_STATIC_ASSERT)
endif()
if (APPLE AND BUILD_SHARED_LIBS)
if (APPLE AND GTSAM_SHARED_LIB)
# Set the default install directory on macOS
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif()

View File

@ -14,7 +14,7 @@ print_enabled_config(${GTSAM_BUILD_TIMING_ALWAYS} "Build timing scripts
if (DOXYGEN_FOUND)
print_enabled_config(${GTSAM_BUILD_DOCS} "Build Docs")
endif()
print_enabled_config(${BUILD_SHARED_LIBS} "Build shared GTSAM libraries")
print_enabled_config(${GTSAM_SHARED_LIB} "Build shared GTSAM libraries")
print_enabled_config(${GTSAM_BUILD_TYPE_POSTFIXES} "Put build type in library name")
if(GTSAM_UNSTABLE_AVAILABLE)
print_enabled_config(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ")

View File

@ -31,10 +31,10 @@
// Whether GTSAM is compiled as static or DLL in windows.
// This will be used to decide whether include __declspec(dllimport) or not in headers
#cmakedefine BUILD_SHARED_LIBS
#cmakedefine GTSAM_SHARED_LIB
#ifdef _WIN32
# ifndef BUILD_SHARED_LIBS
# ifndef GTSAM_SHARED_LIB
# define @library_name@_EXPORT
# define @library_name@_EXTERN_EXPORT extern
# else
@ -56,5 +56,5 @@
#endif
#endif
#undef BUILD_SHARED_LIBS
#undef GTSAM_SHARED_LIB

View File

@ -118,10 +118,11 @@ message(STATUS "GTSAM Version: ${gtsam_version}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
# build shared and static versions of the library
message(STATUS "Building GTSAM - shared: ${BUILD_SHARED_LIBS}")
message(STATUS "Building GTSAM - as a ${GTSAM_LIBRARY_TYPE} library")
# BUILD_SHARED_LIBS automatically defines static/shared libs:
add_library(gtsam ${gtsam_srcs})
# BUILD_SHARED_LIBS automatically defines static/shared libs
# Here we ensure we control which type of library gtsam is specifically
add_library(gtsam ${GTSAM_LIBRARY_TYPE} ${gtsam_srcs})
target_link_libraries(gtsam PUBLIC ${GTSAM_BOOST_LIBRARIES})
target_link_libraries(gtsam PUBLIC ${GTSAM_ADDITIONAL_LIBRARIES})
@ -174,10 +175,10 @@ target_include_directories(gtsam SYSTEM BEFORE PUBLIC
)
if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with shared library
if (NOT BUILD_SHARED_LIBS)
if (NOT GTSAM_SHARED_LIB)
set_target_properties(gtsam PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS GTSAM_IMPORT_STATIC)
PREFIX "lib")
target_compile_definitions(gtsam PRIVATE GTSAM_IMPORT_STATIC)
else()
set_target_properties(gtsam PROPERTIES
PREFIX ""

View File

@ -87,8 +87,7 @@ set(gtsam_unstable_soversion ${GTSAM_VERSION_MAJOR})
message(STATUS "GTSAM_UNSTABLE Version: ${gtsam_unstable_version}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
# BUILD_SHARED_LIBS automatically defines static/shared libs:
add_library(gtsam_unstable ${gtsam_unstable_srcs})
add_library(gtsam_unstable ${GTSAM_LIBRARY_TYPE} ${gtsam_unstable_srcs})
# Apply build flags:
gtsam_apply_build_flags(gtsam_unstable)
@ -102,7 +101,7 @@ 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)
if (NOT GTSAM_SHARED_LIB)
set_target_properties(gtsam_unstable PROPERTIES
PREFIX "lib"
COMPILE_DEFINITIONS GTSAM_UNSTABLE_IMPORT_STATIC)

View File

@ -42,7 +42,7 @@ endif()
include(MatlabWrap)
if(NOT BUILD_SHARED_LIBS)
if(NOT GTSAM_SHARED_LIB)
message(
FATAL_ERROR
"GTSAM_INSTALL_MATLAB_TOOLBOX and BUILD_SHARED_LIBS=OFF."
@ -54,7 +54,7 @@ endif()
# ##############################################################################
# Generate, build and install toolbox
set(mexFlags "${GTSAM_BUILD_MEX_BINARY_FLAGS}")
if(NOT BUILD_SHARED_LIBS)
if(NOT GTSAM_SHARED_LIB)
list(APPEND mexFlags -DGTSAM_IMPORT_STATIC)
endif()
@ -89,7 +89,7 @@ matlab_wrap("${interface_files}" "gtsam" "${GTSAM_ADDITIONAL_LIBRARIES}"
if(GTSAM_UNSTABLE_INSTALL_MATLAB_TOOLBOX)
# Generate, build and install toolbox
set(mexFlags "${GTSAM_BUILD_MEX_BINARY_FLAGS}")
if(NOT BUILD_SHARED_LIBS)
if(NOT GTSAM_SHARED_LIB)
list(APPEND mexFlags -DGTSAM_IMPORT_STATIC)
endif()