Require at least CMake 3.16

Given we no longer support Ubuntu 18.04 due to packaged GCC lacking
C++17 support we can bump the minimum required CMake version to the one
provided by Ubuntu 20.04 which is CMake 3.16. Consequently, this allows
to drop some of the legacy CMake logic.

Change-Id: I1f05d4c5681d10aa7faa0800ef4a803be2f5b7dd
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a6d196d..2957e60 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
 # Ceres Solver - A fast non-linear least squares minimizer
-# Copyright 2022 Google Inc. All rights reserved.
+# Copyright 2023 Google Inc. All rights reserved.
 # http://ceres-solver.org/
 #
 # Redistribution and use in source and binary forms, with or without
@@ -29,23 +29,7 @@
 # Authors: keir@google.com (Keir Mierle)
 #          alexs.mac@gmail.com (Alex Stewart)
 
-cmake_minimum_required(VERSION 3.11)
-
-if (POLICY CMP0074) # Added in CMake 3.12
-  # FindTBB.cmake uses TBB_ROOT in a way that is historical, but also compliant
-  # with CMP0074 so suppress the legacy compatibility warning and allow its use.
-  cmake_policy(SET CMP0074 NEW)
-endif()
-
-# TODO(sameeragarwal): This should be removed when we go past CMake
-# 3.12 as required as it provides alternate ways of finding the Python
-# interpreter.
-if (POLICY CMP0148)
-  # FindSphinx.cmake uses find_package(PythonInterp 3), which has been deprecated
-  # in cmake 3.27. So use the old behaviour till we update our minimum required
-  # cmake version to 3.27
-  cmake_policy(SET CMP0148 OLD)
-endif()
+cmake_minimum_required(VERSION 3.16...3.27)
 
 # On macOS, add the Homebrew prefix (with appropriate suffixes) to the
 # respective HINTS directories (after any user-specified locations).  This
@@ -169,11 +153,6 @@
 if (ANDROID)
   option(ANDROID_STRIP_DEBUG_SYMBOLS "Strip debug symbols from Android builds (reduces file sizes)" ON)
 endif()
-if (MSVC)
-  # TODO Not needed starting CMake 3.15 which provides CMAKE_MSVC_RUNTIME_LIBRARY
-  option(MSVC_USE_STATIC_CRT
-    "MS Visual Studio: Use static C-Run Time Library in place of shared." OFF)
-endif()
 
 # IOS is defined iff using the iOS.cmake CMake toolchain to build a static
 # library for iOS.
@@ -575,29 +554,6 @@
   # the warnings.
   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049")
 
-  # Update the C/CXX flags for MSVC to use either the static or shared
-  # C-Run Time (CRT) library based on the user option: MSVC_USE_STATIC_CRT.
-  list(APPEND C_CXX_FLAGS
-    CMAKE_CXX_FLAGS
-    CMAKE_CXX_FLAGS_DEBUG
-    CMAKE_CXX_FLAGS_RELEASE
-    CMAKE_CXX_FLAGS_MINSIZEREL
-    CMAKE_CXX_FLAGS_RELWITHDEBINFO)
-
-  foreach(FLAG_VAR ${C_CXX_FLAGS})
-    if (MSVC_USE_STATIC_CRT)
-      # Use static CRT.
-      if (${FLAG_VAR} MATCHES "/MD")
-        string(REGEX REPLACE "/MD" "/MT" ${FLAG_VAR} "${${FLAG_VAR}}")
-      endif (${FLAG_VAR} MATCHES "/MD")
-    else (MSVC_USE_STATIC_CRT)
-      # Use shared, not static, CRT.
-      if (${FLAG_VAR} MATCHES "/MT")
-        string(REGEX REPLACE "/MT" "/MD" ${FLAG_VAR} "${${FLAG_VAR}}")
-      endif (${FLAG_VAR} MATCHES "/MT")
-    endif (MSVC_USE_STATIC_CRT)
-  endforeach()
-
   # Tuple sizes of 10 are used by Gtest.
   add_definitions("-D_VARIADIC_MAX=10")
 
@@ -650,14 +606,7 @@
   endif(HAVE_RETURN_TYPE_C_LINKAGE)
 endif ()
 
-if (CMAKE_VERSION VERSION_LESS 3.12)
-  # Disable the definition of min/max macros within the project
-  if (WIN32)
-    add_definitions (-DNOMINMAX)
-  endif (WIN32)
-else (CMAKE_VERSION VERSION_LESS 3.12)
-  add_compile_definitions($<$<BOOL:${WIN32}>:NOMINMAX>)
-endif (CMAKE_VERSION VERSION_LESS 3.12)
+add_compile_definitions($<$<BOOL:${WIN32}>:NOMINMAX>)
 
 # Configure the Ceres config.h compile options header using the current
 # compile options and put the configured header into the Ceres build
diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake
index fa5925d..52a456c 100644
--- a/cmake/FindSphinx.cmake
+++ b/cmake/FindSphinx.cmake
@@ -1,5 +1,5 @@
 # Ceres Solver - A fast non-linear least squares minimizer
-# Copyright 2015 Google Inc. All rights reserved.
+# Copyright 2023 Google Inc. All rights reserved.
 # http://ceres-solver.org/
 #
 # Redistribution and use in source and binary forms, with or without
@@ -37,27 +37,24 @@
 
 find_program(SPHINX_EXECUTABLE
              NAMES sphinx-build
-             PATHS
-               /usr/bin
-               /usr/local/bin
-               /opt/local/bin
+             PATHS /opt/local/bin
              DOC "Sphinx documentation generator")
 
 if (SPHINX_EXECUTABLE)
 
-  find_package(PythonInterp 3)
+  find_package(Python COMPONENTS Interpreter)
 
-  if(PYTHONINTERP_FOUND)
+  if(Python_Interpreter_FOUND)
     # Check for sphinx theme dependency for documentation
     execute_process(
-      COMMAND ${PYTHON_EXECUTABLE} -c "import sphinx_rtd_theme"
+      COMMAND ${Python_EXECUTABLE} -c "import sphinx_rtd_theme"
       RESULT_VARIABLE SPHINX_RTD_THEME
       OUTPUT_QUIET
       ERROR_QUIET
     )
   endif ()
 
-  if (${SPHINX_RTD_THEME} EQUAL 0)
+  if (SPHINX_RTD_THEME EQUAL 0)
     set(SPHINX_RTD_THEME TRUE)
   else ()
     set(SPHINX_RTD_THEME FALSE)
diff --git a/docs/source/CMakeLists.txt b/docs/source/CMakeLists.txt
index 2b6d749..144316d 100644
--- a/docs/source/CMakeLists.txt
+++ b/docs/source/CMakeLists.txt
@@ -9,12 +9,12 @@
         COMPONENT Doc
         PATTERN "${SPHINX_HTML_DIR}/*")
 
-# Find python 3
-find_package(PythonInterp 3 REQUIRED)
+# Find python
+find_package(Python REQUIRED COMPONENTS Interpreter)
 
 # Building using 'make_docs.py' python script
 add_custom_target(ceres_docs ALL
-                  ${PYTHON_EXECUTABLE}
+                  $<TARGET_FILE:Python::Interpreter>
                   "${Ceres_SOURCE_DIR}/scripts/make_docs.py"
                   "${Ceres_SOURCE_DIR}"
                   "${Ceres_BINARY_DIR}/docs"
diff --git a/docs/source/installation.rst b/docs/source/installation.rst
index 3838ccb..ed4df87 100644
--- a/docs/source/installation.rst
+++ b/docs/source/installation.rst
@@ -29,7 +29,7 @@
 optional. For details on customizing the build process, see
 :ref:`section-customizing` .
 
-- `CMake <http://www.cmake.org>`_ 3.10 or later **required**.
+- `CMake <http://www.cmake.org>`_ 3.16 or later **required**.
 
 - `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_
   3.3 or later **required**.
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index b3a7a96..4125eca 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -81,15 +81,9 @@
 # to a different value than Eigen's default.  Depending on the order of files
 # in the unity build this can lead to clashes.  Additionally, these files are
 # already generated in a way which leads to fairly large compilation units,
-# so the gains from a unity build would be marginal.  Since this property is
-# not available before cmake 3.16, unity build is only available from this
-# version on.
-if (NOT CMAKE_VERSION VERSION_LESS 3.16)
-  set_source_files_properties(${CERES_INTERNAL_SCHUR_FILES} PROPERTIES
-    SKIP_UNITY_BUILD_INCLUSION ON)
-elseif(CMAKE_UNITY_BUILD)
-  message(FATAL_ERROR "Unity build requires cmake 3.16 or newer.  Please unset CMAKE_UNITY_BUILD.")
-endif()
+# so the gains from a unity build would be marginal.
+set_source_files_properties(${CERES_INTERNAL_SCHUR_FILES} PROPERTIES
+  SKIP_UNITY_BUILD_INCLUSION ON)
 
 if (NOT MINIGLOG AND GLOG_FOUND)
   list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES})