Remove obsolete CMake helpers and checks Ceres now requires CMake 3.28, so several old workarounds are no longer needed. Remove DetectBrokenStackCheckMacOSXcodePairing.cmake (a 2019 macOS 10.15 / Xcode 11 workaround that spawns sw_vers and xcodebuild on every macOS configure), PrettyPrintCMakeList.cmake (replaced by string(JOIN)), and the Clang 2.9 check for -Wno-return-type-c-linkage. Also replace old list(FIND) boilerplate with IN_LIST in CeresCompileOptionsToComponents.cmake and CreateCeresConfig.cmake, stop symlinking FindSphinx.cmake into CeresFindModules, and drop the duplicate SuiteSparse::SPQR link in ceres_test. Change-Id: Ie13497fdfca418d9670280a005f2295b6a95827e
diff --git a/CMakeLists.txt b/CMakeLists.txt index 28d56bf..2f35da5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -104,11 +104,9 @@ include(CMakeDependentOption) include(CMakePackageConfigHelpers) include(CreateCeresConfig) -include(DetectBrokenStackCheckMacOSXcodePairing) include(EnableSanitizer) include(FeatureSummary) include(GNUInstallDirs) -include(PrettyPrintCMakeList) function(ceres_register_found_package PACKAGE_NAME) set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND "${PACKAGE_NAME}") @@ -196,13 +194,8 @@ REQUIRED RECOMMENDED OPTIONAL) check_cxx_compiler_flag(/bigobj HAVE_BIGOBJ) -# Older versions of Clang (<= 2.9) do not support the 'return-type-c-linkage' -# option, so check for its presence before adding it to the default flags set. -check_cxx_compiler_flag("-Wno-return-type-c-linkage" - HAVE_RETURN_TYPE_C_LINKAGE) check_library_exists(m pow "" HAVE_LIBM) -detect_broken_stack_check_macos_xcode_pairing() enable_sanitizer(${WITH_SANITIZERS}) if (BUILD_TESTING) @@ -596,9 +589,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -mllvm -inline-threshold=600") endif () - if (HAVE_RETURN_TYPE_C_LINKAGE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage") - endif(HAVE_RETURN_TYPE_C_LINKAGE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type-c-linkage") endif () add_compile_definitions($<$<BOOL:${WIN32}>:NOMINMAX>) @@ -669,7 +660,6 @@ set(_Ceres_FIND_MODULES "${Ceres_SOURCE_DIR}/cmake/FindAccelerateSparse.cmake" "${Ceres_SOURCE_DIR}/cmake/FindMETIS.cmake" - "${Ceres_SOURCE_DIR}/cmake/FindSphinx.cmake" "${Ceres_SOURCE_DIR}/cmake/FindSuiteSparse.cmake") set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_Ceres_FIND_MODULES})
diff --git a/cmake/CeresCompileOptionsToComponents.cmake b/cmake/CeresCompileOptionsToComponents.cmake index 26d9085..bea9fcc 100644 --- a/cmake/CeresCompileOptionsToComponents.cmake +++ b/cmake/CeresCompileOptionsToComponents.cmake
@@ -29,39 +29,6 @@ # Authors: alexs.mac@gmail.com (Alex Stewart) # -# Conditionally add a value to the output list based on whether the specified -# value is found in the input list. -function(update_output_if_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_FOUND VAR_TO_COPY_IF_NOT_FOUND) - list(FIND ${INPUT_LIST_VAR} "${ITEM_TO_FIND}" HAVE_ITEM) - # list(FIND ..) returns -1 if the element was not in the list, but CMake - # interprets if (VAR) to be true if VAR is any non-zero number, even - # negative ones, hence we have to explicitly check for >= 0. - if (HAVE_ITEM GREATER -1) - list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_FOUND}") - else() - list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_NOT_FOUND}") - endif() - set(${OUTPUT_LIST_VAR} ${${OUTPUT_LIST_VAR}} PARENT_SCOPE) -endfunction() - -# Helpers for update_output_if_found() to improve legibility when dealing with -# USE_XXX & NO_XXX option types in ceres_compile_options_to_components(). -macro(add_to_output_if_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_FOUND) - update_output_if_found(${INPUT_LIST_VAR} - ${OUTPUT_LIST_VAR} - "${ITEM_TO_FIND}" - "${VAR_TO_COPY_IF_FOUND}" - "") # Copy nothing if not found. -endmacro() - -macro(add_to_output_if_not_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_NOT_FOUND) - update_output_if_found(${INPUT_LIST_VAR} - ${OUTPUT_LIST_VAR} - "${ITEM_TO_FIND}" - "" # Copy nothing if found - "${VAR_TO_COPY_IF_NOT_FOUND}") -endmacro() - # Convert the Ceres compile options specified by: CURRENT_CERES_COMPILE_OPTIONS # into the corresponding list of Ceres components (names), which may be used in: # find_package(Ceres COMPONENTS <XXX>). @@ -70,24 +37,32 @@ # without having to specify explicitly which one, for each sparse library we # add the 'meta-module': SparseLinearAlgebraLibrary in addition to their own # module name. - add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_USE_EIGEN_SPARSE "EigenSparse;SparseLinearAlgebraLibrary") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_NO_LAPACK "LAPACK") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_NO_SUITESPARSE "SuiteSparse;SparseLinearAlgebraLibrary") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_NO_ACCELERATE_SPARSE "AccelerateSparse;SparseLinearAlgebraLibrary") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_NO_CUDA "CUDA") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_NO_CUDSS "cuDSS;SparseLinearAlgebraLibrary") - add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} - CERES_RESTRICT_SCHUR_SPECIALIZATION "SchurSpecializations") + set(COMPONENTS) + if (CERES_USE_EIGEN_SPARSE IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS EigenSparse SparseLinearAlgebraLibrary) + endif() + if (NOT CERES_NO_LAPACK IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS LAPACK) + endif() + if (NOT CERES_NO_SUITESPARSE IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS SuiteSparse SparseLinearAlgebraLibrary) + endif() + if (NOT CERES_NO_ACCELERATE_SPARSE IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS AccelerateSparse SparseLinearAlgebraLibrary) + endif() + if (NOT CERES_NO_CUDA IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS CUDA) + endif() + if (NOT CERES_NO_CUDSS IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS cuDSS SparseLinearAlgebraLibrary) + endif() + if (NOT CERES_RESTRICT_SCHUR_SPECIALIZATION IN_LIST CURRENT_CERES_COMPILE_OPTIONS) + list(APPEND COMPONENTS SchurSpecializations) + endif() # Multithreading is always available. - list(APPEND ${CERES_COMPONENTS_VAR} Multithreading) + list(APPEND COMPONENTS Multithreading) # Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends # are present. - list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR}) - set(${CERES_COMPONENTS_VAR} "${${CERES_COMPONENTS_VAR}}" PARENT_SCOPE) + list(REMOVE_DUPLICATES COMPONENTS) + set(${CERES_COMPONENTS_VAR} "${COMPONENTS}" PARENT_SCOPE) endfunction()
diff --git a/cmake/CreateCeresConfig.cmake b/cmake/CreateCeresConfig.cmake index 565e680..ad4e45a 100644 --- a/cmake/CreateCeresConfig.cmake +++ b/cmake/CreateCeresConfig.cmake
@@ -28,10 +28,10 @@ # # Author: alexs.mac@gmail.com (Alex Stewart) -# This must take place outside of CONFIGURE_CERES_CONFIG() in order that +# This must take place outside of CREATE_CERES_CONFIG() in order that # we can determine where *this* file is, and thus the relative path to -# config.h.in. Inside of CONFIGURE_CERES_CONFIG(), CMAKE_CURRENT_LIST_DIR -# refers to the caller of CONFIGURE_CERES_CONFIG(), not this file. +# config.h.in. Inside of CREATE_CERES_CONFIG(), CMAKE_CURRENT_LIST_DIR +# refers to the caller of CREATE_CERES_CONFIG(), not this file. set(CERES_CONFIG_IN_FILE "${CMAKE_CURRENT_LIST_DIR}/config.h.in") # CreateCeresConfig.cmake - Create the config.h for Ceres. @@ -70,7 +70,7 @@ # Read all possible configurable compile options from config.h.in, this avoids # us having to hard-code in this file what the valid options are. - file(READ ${CERES_CONFIG_IN_FILE} CERES_CONFIG_IN_CONTENTS) + file(READ "${CERES_CONFIG_IN_FILE}" CERES_CONFIG_IN_CONTENTS) string(REGEX MATCHALL "@[^@ $]+@" ALL_CONFIGURABLE_CERES_OPTIONS "${CERES_CONFIG_IN_CONTENTS}") # Removing @ symbols at beginning and end of each option. @@ -83,12 +83,7 @@ foreach (CERES_OPTION ${ALL_CONFIGURABLE_CERES_OPTIONS}) # Try and find the option in the list of current compile options, if it # is present, then the option is enabled, otherwise it is disabled. - list(FIND CURRENT_CERES_COMPILE_OPTIONS ${CERES_OPTION} OPTION_ENABLED) - - # list(FIND ..) returns -1 if the element was not in the list, but CMake - # interprets if (VAR) to be true if VAR is any non-zero number, even - # negative ones, hence we have to explicitly check for >= 0. - if (OPTION_ENABLED GREATER -1) + if (CERES_OPTION IN_LIST CURRENT_CERES_COMPILE_OPTIONS) set(${CERES_OPTION} "#define ${CERES_OPTION}") # Remove the item from the list of current options so that we can identify @@ -109,6 +104,6 @@ "${CURRENT_CERES_COMPILE_OPTIONS}") endif() - configure_file(${CERES_CONFIG_IN_FILE} + configure_file("${CERES_CONFIG_IN_FILE}" "${CERES_CONFIG_OUTPUT_DIRECTORY}/config.h" @ONLY) endfunction()
diff --git a/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake b/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake deleted file mode 100644 index f333ed9..0000000 --- a/cmake/DetectBrokenStackCheckMacOSXcodePairing.cmake +++ /dev/null
@@ -1,83 +0,0 @@ -# Ceres Solver - A fast non-linear least squares minimizer -# Copyright 2023 Google Inc. All rights reserved. -# http://ceres-solver.org/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# * Neither the name of Google Inc. nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# Author: alexs.mac@gmail.com (Alex Stewart) - -# As detailed in [1] the combination of macOS 10.15.x (Catalina) and -# Xcode 11.0-1 enables by default a broken version of -fstack-check which -# can break the alignment requirements for SIMD instructions resulting in -# segfaults from within Eigen. This issue was apparently fixed in Xcode 11.2 -# despite not appearing in the official release notes. -# -# Although this can be worked around by compiling with -fno-stack-check, we -# instead prevent generation as the update to Xcode 11.2 is free and failing -# to include -fno-stack-check *everywhere* could still result in random -# segfaults. -# -# [1]: https://forums.developer.apple.com/thread/121887 -function(detect_broken_stack_check_macos_xcode_pairing) - if (NOT APPLE) - return() - endif() - - execute_process(COMMAND sw_vers -productVersion - OUTPUT_VARIABLE MACOS_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - if (MACOS_VERSION VERSION_LESS 10.15) - # Only 10.15 (Catalina) is likely to be affected, irrespective of the Xcode - # version. Although it is possible to recreate the issue on 10.14 (Mojave) - # and Xcode 11.0-1 if -fstack-check is forced on, this is not the default. - return() - endif() - - execute_process(COMMAND xcodebuild -version - OUTPUT_VARIABLE XCODE_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX MATCH "Xcode [0-9\\.]+" XCODE_VERSION "${XCODE_VERSION}") - string(REGEX REPLACE "Xcode ([0-9\\.]+)" "\\1" XCODE_VERSION "${XCODE_VERSION}") - - if ((XCODE_VERSION VERSION_EQUAL 11.0) OR - (XCODE_VERSION VERSION_EQUAL 11.1)) - message(FATAL_ERROR "Detected macOS version: ${MACOS_VERSION} and " - "Xcode version: ${XCODE_VERSION} which combined exhibit an " - "-fstack-check bug which can break alignment requirements for at least " - "AVX instructions as detailed here [1]." - "\n" - "This bug affected Xcode 11.0 and 11.1 but only when used with 10.15 " - "(Catalina), and was fixed in Xcode 11.2. Without the fix in place, " - "random segfaults will occur in Eigen operations used by Ceres that use " - "AVX instructions." - "\n" - "Please update to at least Xcode 11.2." - "\n" - "[1]: https://forums.developer.apple.com/thread/121887") - endif() -endfunction()
diff --git a/cmake/EnableSanitizer.cmake b/cmake/EnableSanitizer.cmake index 081e771..8ec6f36 100644 --- a/cmake/EnableSanitizer.cmake +++ b/cmake/EnableSanitizer.cmake
@@ -56,10 +56,8 @@ list(LENGTH MERGED_SANITIZERS COMBINED_LENGTH_NO_DUPLICATES) math(EXPR VALID_LENGTH "${COMBINED_LENGTH} - 1") if (COMBINED_LENGTH_NO_DUPLICATES LESS VALID_LENGTH) - include(PrettyPrintCMakeList) - pretty_print_cmake_list(REQUESTED_SANITIZERS ${ARGN}) - pretty_print_cmake_list( - PRETTY_INCOMPATIBLE_SANITIZERS ${INCOMPATIBLE_SANITIZERS}) + string(JOIN ", " REQUESTED_SANITIZERS ${ARGN}) + string(JOIN ", " PRETTY_INCOMPATIBLE_SANITIZERS ${INCOMPATIBLE_SANITIZERS}) message(FATAL_ERROR "Found incompatible sanitizers in requested set: " "${REQUESTED_SANITIZERS}. The following sanitizers are mutually " "exclusive: ${PRETTY_INCOMPATIBLE_SANITIZERS}")
diff --git a/cmake/PrettyPrintCMakeList.cmake b/cmake/PrettyPrintCMakeList.cmake deleted file mode 100644 index 30151fe..0000000 --- a/cmake/PrettyPrintCMakeList.cmake +++ /dev/null
@@ -1,39 +0,0 @@ -# Ceres Solver - A fast non-linear least squares minimizer -# Copyright 2023 Google Inc. All rights reserved. -# http://ceres-solver.org/ -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# * Neither the name of Google Inc. nor the names of its contributors may be -# used to endorse or promote products derived from this software without -# specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -# Authors: alexs.mac@gmail.com (Alex Stewart) - -# pretty_print_cmake_list( OUTPUT_VAR [item1 [item2 ... ]] ) -# -# Sets ${OUTPUT_VAR} in the caller's scope to a human-readable string -# representation of the list passed as the remaining arguments formed -# as: "[item1, item2, ..., itemN]". -function(pretty_print_cmake_list OUTPUT_VAR) - string(REPLACE ";" ", " PRETTY_LIST_STRING "[${ARGN}]") - set(${OUTPUT_VAR} "${PRETTY_LIST_STRING}" PARENT_SCOPE) -endfunction()
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index dad7a25..83e6935 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt
@@ -411,13 +411,6 @@ target_link_libraries(${NAME}_test PRIVATE test_util ceres_static ${CERES_LIBRARY_PRIVATE_DEPENDENCIES} GTest::gmock_main) - # covariance_test uses SuiteSparseQR.hpp. However, since SuiteSparse import - # targets are private (link only) dependencies not propagated to consumers, - # we need to link against the target explicitly here. - if (TARGET SuiteSparse::SPQR) - target_link_libraries (${NAME}_test PRIVATE SuiteSparse::SPQR) - endif (TARGET SuiteSparse::SPQR) - add_test(NAME ${NAME}_test COMMAND ${NAME}_test) endfunction (CERES_TEST)