From 948b75efe90524a7b4795c1d4d39bbb6f800ce71 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 21 Nov 2019 05:16:59 -0800 Subject: [PATCH] CMake cleanups - Bump minimum requred version to 3.12 (Ubuntu Cosmic LTS) - Rename `SAPI_USE_?` options to `SAPI_DOWNLOAD_?` - Improve detection of Python 3 - Use platform independent static library suffixes for `find_library()` PiperOrigin-RevId: 281727467 Change-Id: I45596b6ba08e4f8201d8dcde19a03baf825b83ec --- CMakeLists.txt | 2 +- cmake/SapiDeps.cmake | 36 +++++++++--------------------- cmake/SapiOptions.cmake | 18 +++++++-------- cmake/abseil/CMakeLists.txt.in | 2 +- cmake/benchmark/CMakeLists.txt.in | 2 +- cmake/gflags/CMakeLists.txt.in | 2 +- cmake/glog/CMakeLists.txt.in | 2 +- cmake/googletest/CMakeLists.txt.in | 2 +- cmake/libunwind/CMakeLists.txt.in | 2 +- cmake/protobuf/CMakeLists.txt.in | 2 +- 10 files changed, 27 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80e988b..500d973 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(SandboxedAPI C CXX ASM) diff --git a/cmake/SapiDeps.cmake b/cmake/SapiDeps.cmake index 95e95f0..8bf9e65 100644 --- a/cmake/SapiDeps.cmake +++ b/cmake/SapiDeps.cmake @@ -19,50 +19,46 @@ function(check_target target) endif() endfunction() -# Prefer to use static libraries +# Use static libraries set(_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) -if(WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) -else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) -endif() +set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) if(SAPI_ENABLE_TESTS) - if(SAPI_USE_GOOGLETEST) + if(SAPI_DOWNLOAD_GOOGLETEST) include(cmake/googletest/Download.cmake) endif() check_target(gtest) check_target(gtest_main) check_target(gmock) - if(SAPI_USE_BENCHMARK) + if(SAPI_DOWNLOAD_BENCHMARK) include(cmake/benchmark/Download.cmake) endif() check_target(benchmark) endif() -if(SAPI_USE_ABSL) +if(SAPI_DOWNLOAD_ABSL) include(cmake/abseil/Download.cmake) endif() check_target(absl::core_headers) -if(SAPI_USE_LIBUNWIND) +if(SAPI_DOWNLOAD_LIBUNWIND) include(cmake/libunwind/Download.cmake) endif() check_target(unwind_ptrace) check_target(unwind_ptrace_wrapped) -if(SAPI_USE_GFLAGS) +if(SAPI_DOWNLOAD_GFLAGS) include(cmake/gflags/Download.cmake) endif() check_target(gflags) -if(SAPI_USE_GLOG) +if(SAPI_DOWNLOAD_GLOG) include(cmake/glog/Download.cmake) endif() check_target(glog::glog) -if(SAPI_USE_PROTOBUF) +if(SAPI_DOWNLOAD_PROTOBUF) include(cmake/protobuf/Download.cmake) check_target(protobuf::libprotobuf) check_target(protobuf::protoc) @@ -75,19 +71,7 @@ find_package(Libffi REQUIRED) if(SAPI_ENABLE_EXAMPLES) find_package(ZLIB REQUIRED) endif() - -if(CMAKE_VERSION VERSION_LESS "3.12") - # Work around FindPythonInterp sometimes not preferring Python 3. - foreach(v IN ITEMS 3 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) - list(APPEND _sapi_py_names python${v}) - endforeach() - find_program(Python3_EXECUTABLE NAMES ${_sapi_py_names}) - if(NOT Python3_EXECUTABLE) - message(FATAL_ERROR "No suitable version of Python 3 found") - endif() -else() - find_package(Python3 COMPONENTS Interpreter REQUIRED) -endif() +find_package(Python3 COMPONENTS Interpreter REQUIRED) # Undo global change set(CMAKE_FIND_LIBRARY_SUFFIXES ${_sapi_saved_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/SapiOptions.cmake b/cmake/SapiOptions.cmake index cc2807f..2e2d40e 100644 --- a/cmake/SapiOptions.cmake +++ b/cmake/SapiOptions.cmake @@ -19,16 +19,16 @@ # below enables embedding projects to selectively override/replace these # dependencies. This is useful for cases where embedding projects already # depend on some of these libraries (e.g. Abseil). -option(SAPI_USE_ABSL "Download Abseil at config time" ON) -option(SAPI_USE_GOOGLETEST "Download googletest at config time" ON) -option(SAPI_USE_BENCHMARK "Download benchmark at config time" ON) -option(SAPI_USE_GFLAGS "Download gflags at config time" ON) -option(SAPI_USE_GLOG "Download glog at config time" ON) -option(SAPI_USE_PROTOBUF "Download protobuf at config time" ON) -option(SAPI_USE_LIBUNWIND "Download libunwind at config time" ON) +option(SAPI_DOWNLOAD_ABSL "Download Abseil at config time" ON) +option(SAPI_DOWNLOAD_GOOGLETEST "Download googletest at config time" ON) +option(SAPI_DOWNLOAD_BENCHMARK "Download benchmark at config time" ON) +option(SAPI_DOWNLOAD_GFLAGS "Download gflags at config time" ON) +option(SAPI_DOWNLOAD_GLOG "Download glog at config time" ON) +option(SAPI_DOWNLOAD_PROTOBUF "Download protobuf at config time" ON) +option(SAPI_DOWNLOAD_LIBUNWIND "Download libunwind at config time" ON) # TODO(cblichmann): These two are not currently implemented -option(SAPI_USE_LIBCAP "Download libcap at config time" ON) -option(SAPI_USE_LIBFFI "Download libffi at config time" ON) +option(SAPI_DOWNLOAD_LIBCAP "Download libcap at config time" ON) +option(SAPI_DOWNLOAD_LIBFFI "Download libffi at config time" ON) option(SAPI_ENABLE_EXAMPLES "Build example code" ON) option(SAPI_ENABLE_TESTS "Build unit tests" ON) diff --git a/cmake/abseil/CMakeLists.txt.in b/cmake/abseil/CMakeLists.txt.in index b9f4558..04f9285 100644 --- a/cmake/abseil/CMakeLists.txt.in +++ b/cmake/abseil/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(absl-download NONE) include(ExternalProject) diff --git a/cmake/benchmark/CMakeLists.txt.in b/cmake/benchmark/CMakeLists.txt.in index f32579b..3bd2d75 100644 --- a/cmake/benchmark/CMakeLists.txt.in +++ b/cmake/benchmark/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(benchmark-download NONE) include(ExternalProject) diff --git a/cmake/gflags/CMakeLists.txt.in b/cmake/gflags/CMakeLists.txt.in index 6b1248f..1c98d7a 100644 --- a/cmake/gflags/CMakeLists.txt.in +++ b/cmake/gflags/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(gflags-download NONE) include(ExternalProject) diff --git a/cmake/glog/CMakeLists.txt.in b/cmake/glog/CMakeLists.txt.in index 3df548f..9f2374e 100644 --- a/cmake/glog/CMakeLists.txt.in +++ b/cmake/glog/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(glog-download NONE) include(ExternalProject) diff --git a/cmake/googletest/CMakeLists.txt.in b/cmake/googletest/CMakeLists.txt.in index 5582ae7..2413020 100644 --- a/cmake/googletest/CMakeLists.txt.in +++ b/cmake/googletest/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(googletest-download NONE) include(ExternalProject) diff --git a/cmake/libunwind/CMakeLists.txt.in b/cmake/libunwind/CMakeLists.txt.in index 4ad3f27..f7ab8de 100644 --- a/cmake/libunwind/CMakeLists.txt.in +++ b/cmake/libunwind/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(libunwind-download NONE) include(ExternalProject) diff --git a/cmake/protobuf/CMakeLists.txt.in b/cmake/protobuf/CMakeLists.txt.in index 8092973..ef4becd 100644 --- a/cmake/protobuf/CMakeLists.txt.in +++ b/cmake/protobuf/CMakeLists.txt.in @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(protobuf-download NONE) include(ExternalProject)