diff --git a/CMakeLists.txt b/CMakeLists.txt index 202c19842..5b33b5d57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,13 +75,24 @@ option(GTSAM_WITH_EIGEN_MKL "Eigen will use Intel MKL if available" option(GTSAM_WITH_EIGEN_MKL_OPENMP "Eigen, when using Intel MKL, will also use OpenMP for multithreading if available" OFF) option(GTSAM_THROW_CHEIRALITY_EXCEPTION "Throw exception when a triangulated point is behind a camera" ON) option(GTSAM_ALLOW_DEPRECATED_SINCE_V4 "Allow use of methods/functions deprecated in GTSAM 4" ON) -option(GTSAM_TYPEDEF_POINTS_TO_VECTORS "Typdef Point2 and Point3 to Eigen::Vector equivalents" OFF) +option(GTSAM_TYPEDEF_POINTS_TO_VECTORS "Typedef Point2 and Point3 to Eigen::Vector equivalents" OFF) option(GTSAM_SUPPORT_NESTED_DISSECTION "Support Metis-based nested dissection" ON) option(GTSAM_TANGENT_PREINTEGRATION "Use new ImuFactor with integration on tangent space" ON) if(NOT MSVC AND NOT XCODE_VERSION) option(GTSAM_BUILD_WITH_CCACHE "Use ccache compiler cache" ON) endif() +# Set the build type to upper case for downstream use +string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) + +# Set the GTSAM_BUILD_TAG variable. +# If build type is Release, set to blank (""), else set to the build type. +if(${CMAKE_BUILD_TYPE_UPPER} STREQUAL "RELEASE") + set(GTSAM_BUILD_TAG "") # Don't create release mode tag on installed directory +else() + set(GTSAM_BUILD_TAG "${CMAKE_BUILD_TYPE}") +endif() + # Options relating to MATLAB wrapper # TODO: Check for matlab mex binary before handling building of binaries option(GTSAM_INSTALL_MATLAB_TOOLBOX "Enable/Disable installation of matlab toolbox" OFF) @@ -94,10 +105,7 @@ if((GTSAM_INSTALL_MATLAB_TOOLBOX OR GTSAM_INSTALL_CYTHON_TOOLBOX) AND NOT GTSAM_ message(FATAL_ERROR "GTSAM_INSTALL_MATLAB_TOOLBOX or GTSAM_INSTALL_CYTHON_TOOLBOX is enabled, please also enable GTSAM_BUILD_WRAP") endif() if((GTSAM_INSTALL_MATLAB_TOOLBOX OR GTSAM_INSTALL_CYTHON_TOOLBOX) AND GTSAM_BUILD_TYPE_POSTFIXES) - set(CURRENT_POSTFIX ${CMAKE_${CMAKE_BUILD_TYPE}_POSTFIX}) - if(NOT "${CURRENT_POSTFIX}" STREQUAL "") - message(FATAL_ERROR "Cannot use executable postfixes with the matlab or cython wrappers. Please disable GTSAM_BUILD_TYPE_POSTFIXES") - endif() + set(CURRENT_POSTFIX ${CMAKE_${CMAKE_BUILD_TYPE_UPPER}_POSTFIX}) endif() if(GTSAM_INSTALL_WRAP AND NOT GTSAM_BUILD_WRAP) message(FATAL_ERROR "GTSAM_INSTALL_WRAP is enabled, please also enable GTSAM_BUILD_WRAP") @@ -528,11 +536,13 @@ print_config_flag(${GTSAM_BUILD_TYPE_POSTFIXES} "Put build type in librar if(GTSAM_UNSTABLE_AVAILABLE) print_config_flag(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ") endif() -string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper) + +print_config_flag(${GTSAM_BUILD_WITH_MARCH_NATIVE} "Build for native architecture ") if(NOT MSVC AND NOT XCODE_VERSION) print_config_flag(${GTSAM_BUILD_WITH_MARCH_NATIVE} "Build for native architecture ") message(STATUS " Build type : ${CMAKE_BUILD_TYPE}") - message(STATUS " C++ compilation flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${cmake_build_type_toupper}}") + message(STATUS " C compilation flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}") + message(STATUS " C++ compilation flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}") endif() print_build_options_for_target(gtsam) diff --git a/cmake/GtsamCythonWrap.cmake b/cmake/GtsamCythonWrap.cmake index 6366c1508..c3cad9d83 100644 --- a/cmake/GtsamCythonWrap.cmake +++ b/cmake/GtsamCythonWrap.cmake @@ -86,8 +86,13 @@ function(build_cythonized_cpp target cpp_file output_lib_we output_dir) if(APPLE) set(link_flags "-undefined dynamic_lookup") endif() - set_target_properties(${target} PROPERTIES COMPILE_FLAGS "-w" LINK_FLAGS "${link_flags}" - OUTPUT_NAME ${output_lib_we} PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${output_dir}) + set_target_properties(${target} + PROPERTIES COMPILE_FLAGS "-w" + LINK_FLAGS "${link_flags}" + OUTPUT_NAME ${output_lib_we} + PREFIX "" + ${CMAKE_BUILD_TYPE_UPPER}_POSTFIX "" + LIBRARY_OUTPUT_DIRECTORY ${output_dir}) endfunction() # Cythonize a pyx from the command line as described at @@ -161,9 +166,13 @@ endfunction() function(install_cython_wrapped_library interface_header generated_files_path install_path) get_filename_component(module_name "${interface_header}" NAME_WE) - # NOTE: only installs .pxd and .pyx and binary files (not .cpp) - the trailing slash on the directory name + # NOTE: only installs .pxd and .pyx and binary files (not .cpp) - the trailing slash on the directory name # here prevents creating the top-level module name directory in the destination. - message(STATUS "Installing Cython Toolbox to ${install_path}") #${GTSAM_CYTHON_INSTALL_PATH}") + # Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH/subdirectory if there is one + get_filename_component(location "${install_path}" PATH) + get_filename_component(name "${install_path}" NAME) + message(STATUS "Installing Cython Toolbox to ${location}${GTSAM_BUILD_TAG}/${name}") #${GTSAM_CYTHON_INSTALL_PATH}" + if(GTSAM_BUILD_TYPE_POSTFIXES) foreach(build_type ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER "${build_type}" build_type_upper) @@ -172,10 +181,8 @@ function(install_cython_wrapped_library interface_header generated_files_path in else() set(build_type_tag "${build_type}") endif() - # Split up filename to strip trailing '/' in GTSAM_CYTHON_INSTALL_PATH if there is one - get_filename_component(location "${install_path}" PATH) - get_filename_component(name "${install_path}" NAME) - install(DIRECTORY "${generated_files_path}/" DESTINATION "${location}/${name}${build_type_tag}" + + install(DIRECTORY "${generated_files_path}/" DESTINATION "${location}${build_type_tag}/${name}" CONFIGURATIONS "${build_type}" PATTERN "build" EXCLUDE PATTERN "CMakeFiles" EXCLUDE diff --git a/cython/gtsam_eigency/CMakeLists.txt b/cython/gtsam_eigency/CMakeLists.txt index 4bff567eb..77bead834 100644 --- a/cython/gtsam_eigency/CMakeLists.txt +++ b/cython/gtsam_eigency/CMakeLists.txt @@ -39,11 +39,11 @@ add_dependencies(cythonize_eigency cythonize_eigency_conversions cythonize_eigen # install install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DESTINATION ${GTSAM_CYTHON_INSTALL_PATH} + DESTINATION "${GTSAM_CYTHON_INSTALL_PATH}${GTSAM_BUILD_TAG}" PATTERN "CMakeLists.txt" EXCLUDE PATTERN "__init__.py.in" EXCLUDE) install(TARGETS cythonize_eigency_core cythonize_eigency_conversions - DESTINATION "${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency") -install(FILES ${OUTPUT_DIR}/conversions_api.h DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency) + DESTINATION "${GTSAM_CYTHON_INSTALL_PATH}${GTSAM_BUILD_TAG}/gtsam_eigency") +install(FILES ${OUTPUT_DIR}/conversions_api.h DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}${GTSAM_BUILD_TAG}/gtsam_eigency) configure_file(__init__.py.in ${OUTPUT_DIR}/__init__.py) -install(FILES ${OUTPUT_DIR}/__init__.py DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}/gtsam_eigency) +install(FILES ${OUTPUT_DIR}/__init__.py DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}${GTSAM_BUILD_TAG}/gtsam_eigency) diff --git a/cython/setup.py.in b/cython/setup.py.in index ed02372d8..c35e54079 100644 --- a/cython/setup.py.in +++ b/cython/setup.py.in @@ -7,7 +7,7 @@ except ImportError: if 'SETUP_PY_NO_CHECK' not in os.environ: script_path = os.path.abspath(os.path.realpath(__file__)) - install_path = os.path.abspath(os.path.realpath(os.path.join('${GTSAM_CYTHON_INSTALL_PATH}', 'setup.py'))) + install_path = os.path.abspath(os.path.realpath(os.path.join('${GTSAM_CYTHON_INSTALL_PATH}${GTSAM_BUILD_TAG}', 'setup.py'))) if script_path != install_path: print('setup.py is being run from an unexpected location: "{}"'.format(script_path)) print('please run `make install` and run the script from there') diff --git a/gtsam.h b/gtsam.h index 97eb2d8c3..826f8472e 100644 --- a/gtsam.h +++ b/gtsam.h @@ -248,6 +248,9 @@ class FactorIndices { /** gtsam namespace functions */ +#include +bool isDebugVersion(); + #include class IndexPair { IndexPair(); diff --git a/gtsam/base/debug.cpp b/gtsam/base/debug.cpp index 1c4d08dcd..d6d2a4fe0 100644 --- a/gtsam/base/debug.cpp +++ b/gtsam/base/debug.cpp @@ -47,4 +47,15 @@ void guardedSetDebug(const std::string& s, const bool v) { gtsam::debugFlags[s] = v; } +bool isDebugVersion() { +#ifdef NDEBUG + // nondebug + return false; +#else + // debug + return true; +#endif + +} + } diff --git a/gtsam/base/debug.h b/gtsam/base/debug.h index e21efcc83..5f42580b1 100644 --- a/gtsam/base/debug.h +++ b/gtsam/base/debug.h @@ -47,6 +47,9 @@ namespace gtsam { // Non-guarded use led to crashes, and solved in commit cd35db2 bool GTSAM_EXPORT guardedIsDebug(const std::string& s); void GTSAM_EXPORT guardedSetDebug(const std::string& s, const bool v); + + // function to check if compiled version has debug information + bool GTSAM_EXPORT isDebugVersion(); } #undef ISDEBUG